[antlr-interest] Problem with ambiguous grammar

Thomas Woelfle thomas.woelfle at interactive-objects.com
Mon Aug 17 01:47:34 PDT 2009


Hi,

I have a problem with following grammar:

imperative_statement
  : imperative_compute_statement
  ;
 
imperative_statement_list
  : imperative_statement+
  ;

imperative_compute_statement
  : COMPUTE^ Identifier+ EQUAL Identifier END_COMPUTE?
  ;
 
conditional_compute_statement
  : COMPUTE^ Identifier+ EQUAL Identifier
      (ON? SIZE ERROR imperative_statement_list)?
      END_COMPUTE?
  ;

COMPUTE: 'COMPUTE';
NOT : 'NOT';
ON : 'ON';
SIZE : 'SIZE';
EQUAL : 'EQUAL';
ERROR : 'ERROR';
END_COMPUTE : 'END-COMPUTE';

Identifier :
  Letter (Letter | Digit)*;
 
fragment
Letter :
  'a'..'z' |
  'A'..'Z';
 
fragment
Digit :
  '0'..'9';

ANTLR tells me that the rule 'imperative_compute_statement' has more 
than one alternative to match the optional 'END_COMPUTE'. Can anybody 
give me a hint on how to rewrite this grammar so that the warning no 
longer appears?

Any help appreciated.

Regards,
Thomas

-- 
Interactive Objects Software GmbH
Basler Strasse 61
79100 Freiburg, Germany

Phone:  +49 761 400 73 0
mailto:thomas.woelfle at interactive-objects.com


------------------------------------------------------------------------

Interactive Objects' Legacy Modernization Solutions 

Get Your Applications SOA-Ready!

See http://www.interactive-objects.com/ for more information.

------------------------------------------------------------------------


Interactive Objects Software GmbH | Freiburg | Geschäftsführer: Alberto Perandones, Andrea Hemprich
| AG Frbg. HRB 5810 | USt-ID: DE 197983057



More information about the antlr-interest mailing list