[antlr-interest] syntactic predicates and exceptions

Pete Gonzalez pgonzalez at bluel.com
Wed Nov 16 10:30:26 PST 2005


Terence Parr wrote:
> Hi.  First, are you parsing C# or are you parsing simple field/value  
> pairs?

We are parsing field/value pairs, but the grammar was created by modifying 
an example grammar for C# from your web site.  This may seem like overkill 
for simple field/value pairs, but the application requires parsers for 
several different languages with syntax similar to C#, so it made sense to 
use a common framework.

 > Second, yes exceptions are slooooow!  Best to avoid syntactic
> predicates if you can.  I've seen people use them in exceptions and  get 
> exponential behavior.

The exceptions I see right now are MismatchedCharException (1870 times) and 
NoViableAltForCharException (3755 times).  I searched for "=>", and the 
only instances I see are in the NUMERIC_LITERAL lexer rule pasted below. 
Is there a better way to parse numeric literals?  We do need to distinguish 
integers, floating point, and hexadecimal.

> Thanks very much for the valuable info.  I'm going to try for no- 
> exceptions to see what happens.  Note that v3 should make syn preds  
> MUCH less needed.

How hard is it to convert 2.0 grammars for Antlr 3.0?  How usable is the 
current "early access" build?  What's the ETA for the official 3.0 release? 
  These seem like basic questions, but I didn't see them in the FAQ.  :-)

Cheers,
-Pete

__

// ***** A.1.8 LITERALS *****

NUMERIC_LITERAL
   // real
   : ('.' DECIMAL_DIGIT) =>
      '.' (DECIMAL_DIGIT)+ (EXPONENT_PART)? (REAL_TYPE_SUFFIX)?

   | ((DECIMAL_DIGIT)+ '.' DECIMAL_DIGIT) =>
      (DECIMAL_DIGIT)+ '.' (DECIMAL_DIGIT)+ (EXPONENT_PART)? 
(REAL_TYPE_SUFFIX)?

   | ((DECIMAL_DIGIT)+ (EXPONENT_PART)) =>
      (DECIMAL_DIGIT)+ (EXPONENT_PART) (REAL_TYPE_SUFFIX)?

   | ((DECIMAL_DIGIT)+ (REAL_TYPE_SUFFIX)) =>
      (DECIMAL_DIGIT)+ (REAL_TYPE_SUFFIX)

   // integer
   |  (DECIMAL_DIGIT)+ (INTEGER_TYPE_SUFFIX)?

   // just a dot
   | '.'
   ;


More information about the antlr-interest mailing list