[antlr-interest] Location dependent token?
Mats Ekberg
mats.ekberg at arcticgroup.se
Mon Dec 29 10:18:39 PST 2008
Ok, maybe I was a bit unsharp.
Monetary units are expressed as three-letter words; EUR GBP and so on.
Measurement unitts are also expressed with three letters; TNE KGM and so
on.
The only way to know which is which is where the three letters are
located. In one location its a monetary and another its a measurement.
ok?
regards
mats
mån 2008-12-29 klockan 08:10 -0600 skrev Gary R. Van Sickle:
> > From: Mats Ekberg
> >
> > Lets say a three letter word in uppercase can mean one of two
> > tings like:
> >
> > 10 EUR
> > where EUR means a monetary unit
> >
> > 10 EUR / TNE
> > where EUR still means a monetary unit but the three letters
> > TNE now means a measurement uniot.
> >
> > How can that be expressed in a grammar??
> >
> > /mats
>
> Your question must be missing some information, because what you're asking
> is the most basic of lexing/parsing issues:
>
>
> Lexer does something like this:
>
> NUMBER : [0..9]+ ;
>
> EUR : 'EUR' ;
>
> TNE : 'TNE' ;
>
>
> Parser does something like this:
>
> num_with_monetary_unit_and_optional_per_unit
> : NUMBER monetary_unit ('/' measurement_unit)?
> ;
>
> monetary_unit
> : EUR
> | <<whatever other monies you support>>
> ;
>
> measurement_unit
> : TNE
> | <<whatever other measurement units you support>>
> ;
>
>
> But was that really your question?
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20081229/49994fd9/attachment.html
More information about the antlr-interest
mailing list