[antlr-interest] left recursion removal

Jim Idle jimi at temporal-wave.com
Wed Jul 6 16:40:06 PDT 2011


yes - I pretty sure that you need to pass in the EOL token to the parser
for powerbuilder script to parse (it is pretty crummy but there is a lot
of it out there). Here is a snippet from my VB.Net grammar which allows
the various combinations. When you build the AST, it does not need to
distinguish between single and multi lines.

Also, do not worry about these things until you have the full expression
tree working as that will sometimes make you say "Ahhhhhgggh, now I have
to rework all my statements. Do:

1) Build the lexer, thinking ahead a bit about the parser;
2) Build the expression tree and generate the AST for it;
3) Build the language top down (though bottom up works too);

Or you could pay me to do it as I have no work on right now ;-) boo hoo.

Jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Sébastien Kirche
> Sent: Wednesday, July 06, 2011 4:28 PM
> To: John B. Brodie
> Cc: antlr-interest
> Subject: Re: [antlr-interest] left recursion removal
>
> Le 7 juillet 2011 00:14, John B. Brodie <jbb at acm.org> a écrit :
> > Greetings!
> >
> > [...]
> >
> > unable to reproduce.
> >
> > given your admittedly partial grammar, i tried to construct a
> complete
> > example by adding the missing elements and creating an AST (so i
> could
> > know the resultant parse).
> >
> > my test rig is attached.
> >
> > it runs without error when Tool'd, compiled, and executed from the
> > command-line (FWIW i use Ubunto 11.04 Linux running Sun Java 6 and
> the
> > Antlr version from the antlr-3.4-complete.jar file).
> >
> > Please try to post the *smallest* yet *complete* example of your
> > problem.
>
> Sorry for not having posted a more complete code before, I though that
> should have been enough...
>
> I have worked further on my grammar, with trying to define more
> precisely what an expression should be, with operator precedence. This
> made me rewrite the singleStatement by moving the funCall  rule to the
> primary rule. But my problem about the if-then-else construct is not
> gone.
>
> I have stripped down my grammar, keeping only the expression and
> subsequent rules, removed all that define loops, switches, etc.
> Given that simplified grammar, the following script should pass the
> parsing, but it can't yet :
>
> ---------------------------------------
> string s1, s2
>
> if s1='42' then s2='421'
>
> if s2='421' then
> 	string s3
> 	s3='123'
> else
> 	string s4
> 	s4='666'
> end if
>
> ---------------------------------------
>
> Also, to Jim Idle : the language I would be able to parse is
> Powerbuilder. You can see it as a sort of basic, while it accepts
> syntax like i++ or s += 'foo' He has also the ability to accept inline
> sql statements... I tried to play on the EndOfLine delimiter to handle
> the two if-then-else syntaxes but without success.
>
> --
> Sébastien Kirche


More information about the antlr-interest mailing list