> Another question. I looked some more at wisent-calc.el and found
> that it uses its own lexer. In my last mail I just called
> `bovinate' -- but I don't know what it does -- is the return value
> important? At the moment it just returns 1.
Wisent is a LALR parser generator (in fact a port of Bison in Elisp)
and is not yet fully integrated with Semantic.
Currently Wisent only accepts terminal symbols, that is something like
NUM, NEG, NL, EQ, PLUS, MINUS, MULT, DIV, EXP, LPAREN, RPAREN (these
nonterminal symbols are used in wisent-calc.bnf). So the LALR
parser needs a lexer that return these terminal symbols as tokens. I
will call a such lexer the LALR lexer to avoid confusion with
The LALR lexer itself uses `semantic-flex' to get an input stream as a
list of low level Emacs syntax elements. The LALR lexer then reads the semantic-flex tokens and converts them in terminal symbols understood
by the LALR parser.
In the BNF grammar the %token notation helps to define the terminal
symbols like this:
%token NUM literal ""
%token NEG dummy ""
%token NL punctuation ";"
%token EQ punctuation "=3D"
%token PLUS punctuation "+"
%token MINUS punctuation "-"
%token MULT punctuation "*"
%token DIV punctuation "/"
%token EXP punctuation "^"
%token LPAREN punctuation "("
%token RPAREN punctuation ")"
This will create the following token table:
(RPAREN . ")")
(LPAREN . "(")
(EXP . "^")
(DIV . "/")
(MULT . "*")
(MINUS . "-")
(PLUS . "+")
(EQ . "=3D")
(NL . ";"))
(NEG . ""))
(NUM . "")))
Then the calc lexer can use the following function to access the
token table like this:
(semantic-flex-token-key wisent-calc-tokens 'punctuation ")")
and return a valid token for the LALR parser that is in the above
You can read header comments in wisent.el to get more detail on the
format of lexical tokens for Wisent.
Or the lexer can directly handle the buffer content associated to the
semantic-flex tokens like in:
(string-match wisent-calc-number-regexp is)
Which checks if the input matches a number using a RE. Notice that numbers are now direcly handled by `semantic-flex'.
> (set-buffer (get-buffer-create "*TEST*"))
> (insert "child::para")
As I already said Wisent is not fully integrated with Semantic
today. So calling `semantic-bovinate-toplevel' only calls the LALR
parser if you put the following in your setup hook:
;; Override the default parser to setup the alternate LALR one.
;; Define the lexer used by the LALR parser.
;; How `semantic-flex' will setup the lexer input stream.
A good but more complex example of using the Wisent LALR parser in
the Semantic interactive environment is the wisent-java one.
Hope this helps ;)
Faites un voeu et puis Voila ! http://www.voila.fr
Avec Voila Mail, consultez vos e-mails sur votre mobile Wap.