Next: , Previous: lang lex, Up: Lexing and Parsing


41.2 Specifying a grammar

[todo: write blurb]

— Scheme Procedure: production-symbol p

Return the symbol expanded by a production p.

— Scheme Procedure: production-expansion p

Return the list of symbols in the expansion of a production p.

— Scheme Procedure: production-body p

Return the body of a productions reduction procedure from production p.

— Scheme Procedure: grammar-start-symbol g

Return the starting symbol of grammar g.

By convention, the first production determines the start symbol but in fact, any symbol could be used. A grammar can have mulitple entry points, for example.

— Scheme Procedure: grammar-non-terminals g

Return the non-terminal symbols of grammar g.

The list is computed by looking at the lhs of each production.

— Scheme Procedure: grammar-terminals g

Return the list of terminals of grammar g.

The list is computed by looking at all the symbols used in expansions, and subtracting out the non-terminals.

— Scheme Procedure: grammar-nullables g

Return those non-terminals of grammar g that can derive the empty string.

— Scheme Procedure: symbol-productions g nt

Return the productions in grammar g with lhs eq? to non-terminal nt.

— Scheme Procedure: grammar-cache g

Return the grammar-cache object property of grammar g.