On this page:
grammar?
grammar
2.1 Production rules
production-rule?
production-rule
8.12

2 Grammars🔗ℹ

 (require yaragg/base/grammar) package: yaragg

A grammar is a formal description of the syntax of a language. Grammars consist of a start symbol and a set of production rules which describe how to rewrite the start symbol into valid strings in the language. Grammars are used to construct parsers, which can transform input strings into a parse tree structured according to the rules laid out in the grammar.

procedure

(grammar? v)  boolean?

  v : any/c
A predicate for grammars.

procedure

(grammar #:rules rules    
  #:start-symbol start-symbol)  grammar?
  rules : (sequence/c production-rule?)
  start-symbol : nonterminal-symbol?
Constructs a grammar containing rules and using start-symbol to identify the initial rules to apply during parsing.

2.1 Production rules🔗ℹ

A production rule is a rule in a grammar that describes how a nonterminal symbol in the grammar can be rewritten into a string of other grammar symbols and input tokens. The rewrite pattern is represented by a production expression.

procedure

(production-rule? v)  boolean?

  v : any/c
A predicate for production rules.

procedure

(production-rule #:nonterminal nonterminal 
  #:substitution substitution 
  #:action action) 
  production-rule?
  nonterminal : nonterminal-symbol?
  substitution : production-expression?
  action : semantic-action?
Constructs a production rule that rewrites nonterminal into substitution. During parsing, action is applied to parse nodes created by the constructed rule.