[antlr-interest] [Antlr3 grammar] how to specify alpha token, numeric token and mix of both

David-Sarah Hopwood david-sarah at jacaranda.org
Thu Oct 22 22:08:20 PDT 2009


Hieu Phung wrote:
> Hi David,
> 
> Thank you for your suggestion. However, a MIX can start with number, '_' and
> '.'  :((
> 
> Actually I am trying to write a CIMP message format in Antlr. Reference:
> http://www.parse2.com/example-cargoimp-FFA4.shtml
> 
> Alpha   = %x41-5A;
> Numeric = %x30-39;
> Decimal = %x30-39 / ".";
> Mixed   = Alpha / Numeric;
> Text    = %x41-5A / %x30-39 / "." / "-" / " ";   <--- this is my MIX token
> 
> This format can be written in ABNF easily... but in Antlr, once I introduce
> the MIX token, everything which is mixed of numeric and alpha is returned as
> a MIX. Currently I have to use Java code in action to split the MIX string.

For that format, I can't immediately see any simpler way of doing it.
Sometimes formats are just ugly and irregular, and those tend to require
a lot of action code.

-- 
David-Sarah Hopwood  ⚥  http://davidsarah.livejournal.com



More information about the antlr-interest mailing list