[antlr-interest] Using multiple grammars with a single parser

Jim Idle jimi at temporal-wave.com
Wed Oct 21 01:14:25 PDT 2009


This has been covered in previous discussions (use the search), but basically you create tokens that look for dates using code that is sensitive to the locale, which leaves you with a single lexer with a code based match rather than pattern based match. 

 

DATE : '#' // Assuming that you delimit the dates somehow

              {

                  setText(myDateFunctionThatReturnsString());

              }

             '#'

          ;

 

There are other approaches than returning the string but you should get the picture?

 

Jim

 

From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Parambir Singh
Sent: Tuesday, October 20, 2009 7:06 PM
To: antlr-interest at antlr.org
Subject: [antlr-interest] Using multiple grammars with a single parser

 

Hi

 

I am working on a project where I want to parse input in different locales (e.g. english, french & german dates). I don't want to create multiple parsers, since the semantics of the grammar don't change between locales. So probably I'll need multiple lexers and a single parser. Moreover, I want to specify a locale to the parser and the input should be matched against only that particular locale (e.g. german dates should be invalid in english locale). 

 

What would be the best approach to construct such a parser using ANTLR. I don't have much experience with ANTLR but I read about grammar inheritance and think it could be useful here.

 

Thanks

Param




-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20091021/f2d7d8df/attachment.html 


More information about the antlr-interest mailing list