4.1.4 Start nonterminals

When you write a grammar for Semantic, it is important to carefully indicate the start nonterminals. Each one defines an entry point in the grammar, and after parsing its semantic value is returned to the back-end iterative engine. Consequently:

The semantic value of a start nonterminal must be a produced by a TAG like grammar macro.

Start nonterminals are declared by %start statements. When nothing is specified the first nonterminal that appears in the grammar is the start nonterminal.

Generally, the following nonterminals must be declared as start symbols:

The EXPANDFULL macro has a side effect it is important to know, related to the incremental re-parse mechanism of Semantic: the nonterminal symbol parameter passed to EXPANDFULL also becomes the reparse-symbol property of the tag returned by the EXPANDFULL expression.

When buffer’s data mapped by a tag is modified, Semantic schedules an incremental re-parse of that data, using the tag’s reparse-symbol property as start nonterminal.

The rules associated to such start symbols must be carefully reviewed to ensure that the incremental parser will work!

Things are a little bit different when the grammar is written in Bison style.

The reparse-symbol property is set to the nonterminal symbol the rule that explicitly uses EXPANDTAG belongs to.

For example:

rule:
    rhs
    (let* ((rhs $1)
           name type comps prec action elt)
      …
      (EXPANDTAG
       (TAG name 'rule :type type :value comps :prec prec :expr action)
       ))
  ;

Set the reparse-symbol property of the expanded tag to ‘rule’. An important consequence is that:

Every nonterminal having any rule that calls EXPANDTAG in a semantic action, should be declared as a start symbol!