The Wisent’s parser is what is called a bottom-up or shift-reduce parser which repeatedly:
That is pushes the value of the last lexical token read (the look-ahead token) into a value stack, and reads a new one.
That is replaces a nonterminal by its semantic value. The values of the components which form the right hand side of a rule are popped from the value stack and reduced by the semantic action of this rule. The result is pushed back on top of value stack.
The parser will stop on:
When all input has been successfully parsed. The semantic value of the start nonterminal is on top of the value stack.
When a syntax error (an unexpected token in input) has been detected. At this point the parser issues an error message and either stops or calls a recovery routine to try to resume parsing.
The above elementary actions are driven by the LALR(1)
automaton built by wisent-compile-grammar
from a context-free
grammar.
The Wisent’s parser is entered by calling the function:
Parse input using the automaton specified in automaton.
Is an LALR(1) automaton generated by
wisent-compile-grammar
(see Wisent Grammar).
Is a function with no argument called by the parser to obtain the next terminal (token) in input (see What the parser must receive).
Is an optional reporting function called when a parse error occurs.
It receives a message string to report. It defaults to the function
wisent-message
(see The error reporting function).
Specify the start symbol (nonterminal) used by the parser as its goal. It defaults to the start symbol defined in the grammar (see Wisent Grammar).
The following two normal hooks permit doing some useful processing respectively before starting parsing, and after the parser terminated.
Normal hook run just before entering the LR parser engine.
Normal hook run just after the LR parser engine terminated.