> I wonder how test2.py shall work. According to the grammar and lexer
> code I expect to see the message
>
> skipping unknown letter
>
> if I press, say, `a <Enter>'.
>
> Instead, I get nothing. Even worse, if I then press `b <Enter>', I
> get the following backtrace:
>
> Traceback (most recent call last):
> File "./test2.py", line 27, in ?
> tree = p.parse()
> File "/usr/lib/python2.3/site-packages/pyggy/glr.py", line 200, in parse
> raise ParseError(self.tokval, self.errtoken)
> pyggy.errors.ParseError: ParseError <type 'str'>
>
> Somehow I have the feeling that the examples don't reflect how pyggy
> works currently. Have you changed the syntax, without updating the
> examples?
When you type "a <enter>" it is still waiting for more input
before finishing its parse. When you then follow with "b <enter>"
you complete an invalid syntax and it complains. It is important
to realize that this is not a line-by-line lexer.
It behaves properly on the following input:
echo 'id+id+id' | test2.py
You are correct in your next email that there is a bug when
it receives an unexpected character. After changing the tokdata
reference to value as you point out it behaves properly:
$ echo 'id+id+id!' | test2.py
skipping unknown letter !
parse done: [(id + (id + id)) or ((id + id) + id)]
> Reason for asking is that I'm not able to get a working engine. pyggy
> accepts both my lexing and parsing code without warning, but whatever
> I use as input, I get the same error as above. On the other hand,
> pyggy itself works fine (but is too complicated for a python novice
> like me), so I'm really clueless.
If you want a line-at-a-time parse, you can fetch a line of
input with a normal python command, and then give that input
to a lexer with the setinputstr method. See the example in
ply_calc.py for more details.
Debugging parsers isnt very easy in pyggy right now. The best way
to debug a parser is through looking at the debug output of the parser
generator and manually playing the parsers part of following where
you would be after each input token. Before doing this you should
probably test your lexer to make sure it is giving you the tokens
you expect.
If you want some help feel free to post examples of what you are
working on here.
> Werner
Tim Newsham
http://www.lava.net/~newsham/