Next: Wisent Semantic, Previous: Wisent Grammar, Up: top [Contents][Index]

## 3 Wisent Parsing

The Wisent’s parser is what is called a bottom-up or shift-reduce parser which repeatedly:

shift

  That is pushes the value of the last lexical token read (the look-ahead token) into a value stack, and reads a new one.

reduce

  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:

accept

  When all input has been successfully parsed. The semantic value of the start nonterminal is on top of the value stack.

error

  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:

Function: wisent-parse automaton lexer &optional error start

  Parse input using the automaton specified in automaton.

  automaton

    Is an LALR(1) automaton generated by `wisent-compile-grammar` (see Wisent Grammar).

  lexer

    Is a function with no argument called by the parser to obtain the next terminal (token) in input (see Writing a lexer).

  error

    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 Report errors).

  start

    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.

Variable: wisent-pre-parse-hook

  Normal hook run just before entering the LR parser engine.

Variable: wisent-post-parse-hook

  Normal hook run just after the LR parser engine terminated.

Next: Wisent Semantic, Previous: Wisent Grammar, Up: top [Contents][Index]