[antlr-interest] Improvements to left recursive grammars

Seref Arikan serefarikan at kurumsalteknoloji.com
Fri Jan 6 13:01:50 PST 2012


Thanks,
A couple of months sounds quite good. I'll be looking forward to new tricks
;)

Regards
Seref


On Fri, Jan 6, 2012 at 8:22 PM, Terence Parr <parrt at cs.usfca.edu> wrote:

> Wait til you see the next trick with these suckers.  next week I hope.
>
> v4 won't be stable for a couple of months.
>
> Ter
>
> On Jan 6, 2012, at 11:10 AM, Seref Arikan wrote:
>
> Ok, this is seriously impressive. The critical question for someone who is
> working on implementing not one, but a few grammars at the moment is:
> should I start using honey badger (great name btw) or stick to v3?
> I'm in no position to judge the maturity of a piece of technology such as
> Antlr, so input from the veterans would be appreciated.
>
> Regards
> Seref
>
>
> On Fri, Jan 6, 2012 at 2:47 AM, Terence Parr <parrt at cs.usfca.edu> wrote:
>
>> Howdy. Ok,These left recursive grammar rules are craaaazy. Now they
>> behave just as you would expect regular rules. For example, you could have
>> return values and actions (on the right edge). The cool thing is you can
>> label the left recursive rule references (a=e) even though those disappear
>> in the implementation. :)
>>
>>    s : e {System.out.println($e.v);} ;
>>    e returns [int v]
>>      : a=e '*' b=e {$v = $a.v * $b.v;}
>>      | a=e '+' b=e {$v = $a.v + $b.v;}
>>      | INT         {$v = $INT.int;}
>>      | '(' x=e ')' {$v = $x.v;}
>>      ;
>>
>> For example, I passed an input 1+2*3 and got the following parse tree
>>
>> (s (e (e 1) + (e (e 2) * (e 3))))
>>
>> just like you would get if this were a bottom-up tool. Moreover, it fires
>> exit rule events as you would expect. you will see something like this, if
>> you pass in a listener that prints out the ctx. see the example page.
>>
>> exit 1: (e 1)
>> exit 1: (e 2)
>> exit 1: (e 3)
>> exit 1: (e (e 2) * (e 3))
>> exit 1: (e (e 1) + (e (e 2) * (e 3)))
>> 7
>> exit 0: (s (e (e 1) + (e (e 2) * (e 3))))
>>
>> just pushed to the website dist directory. also updated this page:
>>
>> http://www.antlr.org/wiki/display/ANTLR4/Examples
>>
>> see
>>
>> http://antlr.org/depot/antlr4/main/CHANGES.txt
>>
>> Ter
>>
>>
>> List: http://www.antlr.org/mailman/listinfo/antlr-interest
>> Unsubscribe:
>> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>>
>
>
>


More information about the antlr-interest mailing list