[antlr-interest] Infinite lookahead/syntactic predicates

Chris Black chris at lotuscat.com
Thu Jun 23 15:32:55 PDT 2005


Anders Jacobsson wrote:

>Hi!
>
>I'm really sorry if I'm asking about something obvious or something
>that is clearly stated in the documentation but I would really
>appreciate in one or two hints that can guide me in my first attempts
>of using ANTLR.
>
>Anyway, I need to process things like the following:
>
>'12345'D
>'13AEF'H
>'1A4'T
>'1010101'B
>'17853'
>
>The first one should be matched to be a decimal constant, the second
>one a hexadecimal constant, the third one a TBCD constant, the fourth
>one a binary constant and the last to be a constant of unknown type.
>
>It would have been nice to have the type indicator in front of the
>constant but I guess I'm not that lucky... :) I have been trying to
>use looping and syntactic predicates but so far no luck.
>
>Has anyone any tips?
>
>Cheers,
>Anders
>  
>
Just off the top of my head, make a rule that matches any/all of them 
(like Ter's suggestion) and separates the single-quoted chars from the 
trailing type. Then within the action part of the rule do a bunch of 
if/else's on the trailing type (or lack thereof) to determine how to 
process the quoted chars. Then either set an appropriate variable, 
return something appropriate, or create an AST node by hand using some 
imaginary tokens using types you define yourself.

Hope this helps,
Chris


More information about the antlr-interest mailing list