D. Richard Hipp wrote:
John Cohen wrote:


The last suggestion worked great (thanks!). But still, I still have a small problem. It won't accept more than one 'statement'. I know why, but can't fix it. Take a look:


$ ./a.out
7 + 9 + 7 + 3 / (5 + 7);
        23.25
3 + 3 + 3;
Fatal Error: Parser is hopelessly lost...

Now, I know why, because my grammar look like this:
in ::= stmt ENDLINE.
stmt(A) ::= expression. { printf("%u\n", a); }
expression(A) ::= INTEGER(B). { A = B; }
expression(A) ::= expression(B) PPLUS expression(C). { A = B + C; }
expression(A) ::= expression(B) PSUB expression(C). { A = B - C; }
...etc...

Now its obvious why that will only accept one statement, but how to fix it? SQLite doesn't offer any help here because the parser seems to be reinitialized each statement, but that really isn't an option in my case. Is there any way? In bison, you can simply make the start token right recursive (like in my last message):

in ::= in stmt ENDLINE.


There's a bug in lemon such that it doesn't like the primary
non-terminal to be recursive.  So do this:

 main ::= in.

Then in addition to what you have it should work.


Correction: There *used* to be this bug in lemon. I think it is now fixed. The problem above is that there is no initial case for the in term. You need this:


in ::= . in ::= in stmt ENDLINE.




-- D. Richard Hipp -- [EMAIL PROTECTED] -- 704.948.4565



Reply via email to