[antlr-interest] Need Help - Not able to use Java1.5grammaravailable on site with ANTLRv3

Diehl, Matthew J matthew.j.diehl at intel.com
Fri Jun 22 11:02:12 PDT 2007


I used the grammar file you were talking about, and besides the
"Decision can match input such as "'0'..'9'{'E', 'e'}{'+',
'-'}'0'..'9'{'D', 'F', 'd', 'f'}" using multiple alternatives: 3, 4",
I'm not getting the same errors.  I'm using ANTLRWorks 1.0.2, and Java
1.6.

A way around the above error is to delete (on the 4th alternative in the
rule FloatingPointLiteral) the "Exponent?".  It is a little redundant I
think, and is handled by the 3rd alternative.  So it should read:

 

FloatingPointLiteral

    :   ('0'..'9')+ '.' ('0'..'9')* Exponent? FloatTypeSuffix?

    |   '.' ('0'..'9')+ Exponent? FloatTypeSuffix?

    |   ('0'..'9')+ Exponent FloatTypeSuffix?

    |   ('0'..'9')+ FloatTypeSuffix

    ;

 

After this change, I rechecked the grammar, and it gave me no errors.  I
don't know what's different from yours and mine, but yours is showing
that the above error was on line 197, when it was on line 177 on my
system. Are you sure you copied the file correctly?  Make sure when you
save it that you save the link to Java.g, and not the text. For
instance, if you click on the link and brink up Java.g in the browser,
and then you click on file:saveAs, it will add extra formatting junk
into the file.  Whereas if you right-click on the LINK to Java.g and
select SaveLinkAs, it will save the file and not add extra junk to it.

 

Matt

________________________________

From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Amol Neurgaonkar
Sent: Friday, June 22, 2007 10:25 AM
To: antlr-interest at antlr.org
Subject: Re: [antlr-interest] Need Help - Not able to use
Java1.5grammaravailable on site with ANTLRv3

 

 

Another point I would like to bring out is that when I open the grammar
file in ANTLRWorks , it throws errors on a few words in the file code as
follows - 

 

1.

enumConstant : annotations? Identifier (arguments)? (classBody)?  

On this line, it throws error on word 'annotations' saying : undefined
reference "annotations"

 

2.

integerLiteral : 
HexLiteral | OctalLiteral | DecimalLiteral ; booleanLiteral : 'true' |
'false' ;

On this line, it throws error on word 'HexLiteral' saying : undefined
reference "HexLiteral "

3.Similar error is thrown for word 'forControl'

These are all related to the new features of Java 1.5 I suppose.

 

Thanks,

Amol.

 

On 6/22/07, Amol Neurgaonkar <amol.neurgaonkar at gmail.com> wrote: 

Hi,

 

I tried to save the grammar file on disk and then run the ANTLRWorks on
the file,

 

Following is the error msg I get when running the 'Check Grammar'
feature now -

 

[10:05:34] Checking Grammar...
[10:05:34] error(100): Java.txt:50:12: syntax error: antlr:
Java.txt:50:12: unexpected token: ?
[10:05:34] error(100): Java.txt:50:32: syntax error: antlr:
Java.txt:50:32: unexpected token: ? 
[10:05:34] error(100): Java.txt:50:51: syntax error: antlr:
Java.txt:50:51: unexpected token: *
[10:05:34] error(100): Java.txt:50:68: syntax error: antlr:
Java.txt:50:68: unexpected token: *
[10:05:34] error(100): Java.txt:114:18: syntax error: antlr:
Java.txt:114:18: unexpected token: ?
[10:05:34] error(100): Java.txt:129:8: syntax error: antlr:
Java.txt:129:8: unexpected token: block
[10:05:34] error(100): Java.txt:129:34: syntax error: antlr:
Java.txt:129:34: unexpected token: *
[10:05:34] error(100): Java.txt:147:1: syntax error: antlr:
Java.txt:147:1: unexpected token: forInit
[10:05:34] error(100): Java.txt:166:6: syntax error: antlr:
Java.txt:166:6: unexpected token: a 
[10:05:34] error(100): Java.txt:166:12: syntax error: antlr:
Java.txt:166:12: unexpected token: pred
[10:05:34] error(100): Java.txt:166:20: syntax error: antlr:
Java.txt:166:20: unexpected token: check
[10:05:34] error(100): Java.txt:166:33: syntax error: antlr:
Java.txt:166:33: unexpected token: on
[10:05:34] error(100): Java.txt:166:42: syntax error: antlr:
Java.txt:166:42: unexpected token: >
[10:05:34] error(100): Java.txt:194:18: syntax error: antlr:
Java.txt:194:18: unexpected token: ?
[10:05:34] error(106): Java.txt:103:60: reference to undefined rule:
annotation
[10:05:34] error(106): Java.txt:132:13: reference to undefined rule:
block
[10:05:34] error(106): Java.txt:137:30: reference to undefined rule:
block
[10:05:34] error(106): Java.txt:135:35: reference to undefined rule:
block
[10:05:34] error(106): Java.txt:109:43: reference to undefined rule:
block
[10:05:34] error(106): Java.txt:61:38: reference to undefined rule:
annotations
[10:05:34] error(106): Java.txt:97:1: reference to undefined rule:
annotation
[10:05:34] error(106): Java.txt:67:40: reference to undefined rule:
block
[10:05:34] error(106): Java.txt:135:61: reference to undefined rule:
block
[10:05:34] error(106): Java.txt:140:64: reference to undefined rule:
block
[10:05:34] error(106): Java.txt:136:11: reference to undefined rule:
block
[10:05:34] error(106): Java.txt:117:1: reference to undefined rule:
annotation
[10:05:34] warning(105): Java.txt:112:1: no lexer rule corresponding to
token: HexLiteral
[10:05:34] warning(200): Java.txt:197:24: Decision can match input such
as "'0'..'9'{'E', 'e'}{'+', '-'}'0'..'9'{'D', 'F', 'd', 'f'}" using
multiple alternatives: 3, 4 
As a result, alternative(s) 4 were disabled for that input
[10:05:34] error(10):  internal error:
org.antlr.tool.Message.toString(Unknown Source): Assertion failed!
Message ID 100 created but is not present in errorMsgIDs or
warningMsgIDs. 

Here is the line no 49 : (Note, the line is commented after }. I am not
sure if the word 'compilationUnit' should also be part of the comment or
not)

= true; } // starting point for parsing a java file compilationUnit : 

which is followed by line no 50 as below where the first error is
thrown:

annotations? packageDeclaration? importDeclaration* typeDeclaration* ; 

 

The Grammar is still the same  (
http://www.antlr.org/grammar/1152141644268/Java.g
<http://www.antlr.org/grammar/1152141644268/Java.g> ) , just that now
instead of showing the full grammar in one line(when I used to copy
directly from browser), now it shows in 221 lines. However, it gives the
above error now. 

 

Thanks,

Amol.



 

On 6/22/07, Amol Neurgaonkar <amol.neurgaonkar at gmail.com > wrote: 

Your understanding is correct. When I paste the Java1.5 grammar from
site ( http://www.antlr.org/grammar/1152141644268/Java.g
<http://www.antlr.org/grammar/1152141644268/Java.g> ) , the whole
grammar is copied 

as a single line in the ANTLRWorks dialogue box.

When I run the 'Check Grammar' , it succeeds, however when I run
'Generate Code' it throws following error.

 

[19:04:25] Java.g:1:16360: unexpected char: ' '
 at org.antlr.tool.ANTLRLexer.nextToken(Unknown Source)
 at antlr.TokenStreamRewriteEngine.nextToken
(TokenStreamRewriteEngine.java :161)
 at antlr.TokenBuffer.fill(TokenBuffer.java:69)
 at antlr.TokenBuffer.LA(TokenBuffer.java:80)
 at antlr.LLkParser.LA(LLkParser.java:52)
 at org.antlr.tool.ANTLRParser.actions (Unknown Source)
 at org.antlr.tool.ANTLRParser.grammar (Unknown Source)
 at org.antlr.tool.Grammar.setGrammarContent(Unknown Source)
 at org.antlr.tool.Grammar.setGrammarContent(Unknown Source)
 at org.antlr.works.grammar.EngineGrammar.createNewGrammar (Unknown
Source) 
 at org.antlr.works.grammar.EngineGrammar.createCombinedGrammar(Unknown
Source)
 at org.antlr.works.grammar.EngineGrammar.createGrammars(Unknown Source)
 at org.antlr.works.grammar.EngineGrammar.analyze (Unknown Source) 
 at org.antlr.works.grammar.CheckGrammar.run(Unknown Source)
 at java.lang.Thread.run(Unknown Source)

 

[19:04:25] error(100): C:\antlr3.0\Java.g:2:1: syntax error: antlr:
C:\antlr3.0\Java.g:2:1: unexpected token: null
[19:04:25] error(150):  grammar file C:\antlr3.0\Java.g has no rules 

I have tried using other grammars for Java 1.5 listed in the Grammars
section, but they do not seem to succeed even for 'Check Grammar'
feature. 

 

Thanks,

Amol.





 

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


More information about the antlr-interest mailing list