NetBeans Forums
| View previous topic :: View next topic |
| Author |
Message |
welworx
Joined: 13 Jun 2010 Posts: 2
|
Posted: Mon Sep 20, 2010 2:09 pm Post subject: ANTLR - Problem - Mygrammar.g contains grammar Expr; names must be identical |
|
|
Hi guys!
I'm trying to develop a modul for latex support with syntax highlighting.
I worked through this tutorial http://wiki.netbeans.org/AntlrInNetBeansJavaApplication
but i always get this message:
error( : file C:\NetBeansProjects\antlr\src\antlr\Mygrammar.g contains grammar Expr; names must be identical
Java Result: 1
This is my Mygrammar.g file:
| Code: |
grammar Expr;
@header {
package antlr;
import java.util.HashMap;
}
@lexer::header{
package antlr;
}
@members {
/** Map variable name to Integer object holding value */
HashMap memory = new HashMap();
}
prog: stat+ ;
stat: expr NEWLINE {System.out.println($expr.value);}
| ID '=' expr NEWLINE
{memory.put($ID.text, new Integer($expr.value));}
| NEWLINE
;
expr returns [int value]
: e=multExpr {$value = $e.value;}
( '+' e=multExpr {$value += $e.value;}
| '-' e=multExpr {$value -= $e.value;}
)*
;
multExpr returns [int value]
: e=atom {$value = $e.value;} ('*' e=atom {$value *= $e.value;})*
;
atom returns [int value]
: INT {$value = Integer.parseInt($INT.text);}
| ID
{
Integer v = (Integer)memory.get($ID.text);
if ( v!=null ) $value = v.intValue();
else System.err.println("undefined variable "+$ID.text);
}
| '(' expr ')' {$value = $expr.value;}
;
ID : ('a'..'z'|'A'..'Z')+ ;
INT : '0'..'9'+ ;
NEWLINE:'\r'? '\n' ;
WS : (' '|'\t')+ {skip();} ;
|
I have also got the problem, that there is neither a
MyGrammarLexer.java nor a MyGrammarParser.java file generated.
Any idea?
Thanks
- welworx
PS: Netbeans 6.9, windows 7 |
|
| Back to top |
|
 |
dzsystem
Joined: 15 Jan 2011 Posts: 2
|
Posted: Sat Jan 15, 2011 11:43 pm Post subject: |
|
|
u must to rename the name of grammare to
grammar MyGrammar;
in grammar file
good luk  |
|
| Back to top |
|
 |
benhuan
Joined: 27 Dec 2012 Posts: 1
|
Posted: Thu Dec 27, 2012 3:01 am Post subject: |
|
|
| dzsystem wrote: | u must to rename the name of grammare to
grammar MyGrammar;
in grammar file
good luk  |
Thank you so much |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|