A bottom-up template grammar can contain the special nonterminal symbol error in production right-hand sides.
That nonterminal symbol represents a parse error.
The nonterminal symbol makes it possible to change the flow of grammar execution on encountering a parse error.
The selection of an error nonterminal symbol to handle a parse error must be deterministic.
Note: bottom-up template grammars containing the
errornonterminal symbol are for direct processing by therege-bottom-uptool after optional adding to them a source PCFG production markup by therege-markup-cfgtool with passing the option --error-nont. Therege-vittool ignores theerrornonterminal symbol.
Example 1
S: A | B | C | error . ; A: "a" ; B: "b" "c" | "b" "d" ; C: "c" "c" "c" ;This grammar consumes any terminal symbol if a training terminal symbol sequence does not start with the terminal symbol
"a","b", and"c"or if a training terminal symbol sequence starts with the terminal symbol"b"not followed by the terminal symbol"c"or"d".
Example 2
S: "a" ( "b" | error . . )? "c" ;This grammar is equivalent to the grammar
S: "a" ( "b" | [^ "b" "c" ] . )? "c" ;
Example 3
S: A* ( error [^ "d" ]* )? "d" ; A: "a" "b" | "a" "c" ;Normally, this grammar consumes any number of elements ‘( "a" "b" | "a" "c" )’ finalized by
"d". If an element does not start with"a"or starts with"a"not followed by"b"or"c"or if a sequence of ‘( "a" "b" | "a" "c" )’ does not end with"d", the grammar consumes terminal symbols until encountering"d".