Re: using define-lex

Eric Ludlam <[email protected]> Tue, 27 Oct 2015 18:35:47 -0400
Newsgroups gmane.emacs.semantic
Message-ID <[email protected]>
On 10/27/2015 12:23 PM, Arnab Chakraborty wrote:
> Hello,
>
>     I know about grammars and bison, but am new to semantic and wisent.
> After some effort I have managed to write a simple test grammar that I
> could successfully feed into wisent-grammar-compile and the output
> passes wisent-automaton-p test.
> Now I want to apply wisent-parse to it. For this I need a LEXER which is
> supposed to be a function with 0 argument that returns the next token. I
> could successfully write one from scratch.

The easiest way to convert your grammar into something usable is with 
the "Update Lisp Package" menu item bound to C-c C-c.

>    However, I want to use something like define-lex to construct the
> lexer automatically. Here I have the following problem:
>
>    define-lex produces a lexer that has two compulsory arguments START
> and END, while the requirement of wisent-parser is a lexer with NO
> argument.

You can define lexer parts via the %token statements in the wisent 
grammar, and define your lexer at the end of the grammar.  Java.wy is a 
good example.

> Now can I convert the lexer produced by define-lex into one suitable for
> wisent-parse? I looked through the python parser file
> in the semantic/wisent folder. But it is not using wisent-parse
> anywhere, this dos not get me anywhre.
>

Usually you can define `semantic-lex-analyzer' to be the analyzer you 
want to use that takes the inputs, and then "install" the parser with 
the auto-generated  wisent-mylanguage--install-parser command, and 
wisent handles the conversion between the needed lexical commands.

> Any help, please?

The documentation in wisent.info can also help.

> Also, must wisent always be used in the semantic framework, or may I use
> it independently also?
>

If you are using it for an association with a major mode, the simplest 
example is probably in cogre/wisent-dot.wy, and cogre/wisent-dot.el.

If you want to use it outside of a mode, you can look at 
semantic/wisent/calc.wy and semantic/wisent/calc.el.   It runs by 
installing a parser into  temp buffer.  It does not produce tags or use 
the rest of the semantic framework, just the raw parser, and parser 
installation into a buffer.

Good Luck
Eric

------------------------------------------------------------------------------