liveBook · Manning

Parser generator

As explained in Building User-Friendly DSLs

A tool or framework that generates a parser from a grammar specification.

A parser generator is a tool or framework that turns a grammar specification into a parser for textual DSL content. Parsing recognizes text that conforms to the grammar and produces a parse tree, which may already be an AST or may require transformation. section 15.1

A parsing-based DSL workflow connects these stages:

  • Write a grammar describing permitted textual combinations. section 15.1
  • Generate a parser that recognizes conforming text. section 15.1
  • Transform the parse tree into an AST when their structures differ. section 15.1
  • Pass the AST to language services for completion, constraint checking, syntax highlighting, type information, or tooltips. section 15.1

Rental record DSL

A textual Rental record declares attributes such as rental period, rental price, discount, and an initially derived value. An EBNF grammar specifies strings, types, numbers, attribute references, attributes, and the complete record type.

How Building User-Friendly DSLs covers it

How deep it goes
Defines grammar, parser generation, parse trees, AST transformation, and downstream services, but omits generator-specific implementation details.
Examples
Uses a Rental record DSL and its EBNF grammar as concrete artifacts.
What it assumes
Assumes familiarity with textual content and introduces grammar as a formal specification of permitted character combinations.
What you can do after
Evaluate how grammar-driven parsing produces ASTs for DSL tooling and where parse-tree transformation may be required.
How it connects
Connects grammar, parsing, EBNF, parse trees, abstract syntax trees, textual DSLs, and language services.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building User-Friendly DSLs. The section links point to the parts of the book it draws on.