Re: using define-lex
Eric Ludlam <[email protected]> Wed, 28 Oct 2015 07:27:10 -0400
| Newsgroups | gmane.emacs.semantic |
|---|---|
| Message-ID | <[email protected]> |
On 10/27/2015 09:54 PM, Arnab Chakraborty wrote: > Hi Eric, > > Thanks a lot for your help. But still some points are not clear to me. > Let me tell you the simple grammar I am working with. > > ;;First the grammar as a elisp structure. The language just consists of > lists of ;;the token "number". > (setq g '( (number) > () > (line > ((number) (format "%s" $1)) > ((line number) (format "%s %s" $1 $2)) > ) > ) > ) > > ;;;Convert to an automaton > (setq a (wisent-grammar-compile g)) > > ;;;Create a lexer > (define-lex mylex "" semantic-number-analyzer) > > ;;;Try to put them together (it is here that I get error, saying that > ;;;mylex does not fit the bill. > (wisent-parse a mylex) > > > I have not tried using a .wy file yet, because I have not yet figured > out how to convert a .wy file to an elisp structure. So java.wy etc > are not helping me yet. I see. I'm less familiar with this level of use of wisent, and now I know what you meant by using a grammar without the semantic infrastructure. I'm pretty sure what you want is possible, but all the documentation, and what I know about it is rigged up to bind a parser into a buffer with a series of buffer local variables. Then the helper functions that parse sections of a buffer will all have the correct context needed to start parsing. If your goal is to eventually parse buffer contents, then you should definitely start with the .wy files. The basic process for converting a .wy file into a -wy.el file is bound to a key in wisent-mode, so when you are editing the grammar, you press C-c C-c, and it gets converted to lisp, and also creates all the other needed variables. For example, you will need both the grammar, the keyword table, to tokens table, plus the individual token analyzers needed for the lexer, all of which can be derived directly from your .wy file. It will also create a function to install your grammar into a buffer. If you still want to construct your grammar by hand, calc-wy.el is the simplest example in the collection that shows what variables you need, and how to bind it together to a buffer, and wisent-calc shows how to make sure the buffer is fully setup by calling misc init functions. I don't really know the internals of the wisent function stack to avoid using an intermediate buffer. Eric ------------------------------------------------------------------------------