[antlr-interest] tricky (to this newby) translation problem
Kenny Tilton
ktilton at nyc.rr.com
Fri Dec 30 13:07:33 PST 2005
[resending to list....]
Terence Parr wrote:
>
> On Dec 30, 2005, at 8:31 AM, Kenny Tilton wrote:
>
>> enumerator
>> : i:ID { print( i ); }
>> ( b:ASSIGN { print( b ); }
>> expr
>> )?
>> ;
>>
>> But my problem is that, if the match with an ASSIGN happens, I need
>> to get a left-parens /in front/ of the emitted ID. Otherwise I have
>> to always wrap enumerators in parens:
>
>
> Hi. First let me suggest using StringTemplate in combination with
> ANTLR:
>
> http://www.codegeneration.net/tiki-read_article.php?articleId=77
Actually I did look at that first because it sounded perfect, but that
article was greek to me so I looked for something I could grok without
learning about parsing. I know that sounds strange and that by the time
I am done I will have learned quite a bit, but I have a hard time
understanding doc. otoh, GnuCEmitter.g was on the face of it something I
could work from with a little guesswork.
The funny thing is that I just want to translate one old C app to Common
Lisp (CL) so I can resume development with my new preferred language. An
hour of hand translation was enough to send me looking for a translator.
Antlr looks brilliant, but I am also having to get up to speed on Java
and now parsing.
So believe it or not I am getting actual results without really having
learned anything yet! Full marks to the great examples, especially Cgram.
>
> As to your problem. Try this
>
> enumerator
> : i:ID
> ( b:ASSIGN { print( i ); print( b ); }
> expr
> | { print( i ); } // empty grammatical production
> )
> ;
>
Diabolical. I like it. :)
Thx, kenny
More information about the antlr-interest
mailing list