NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

ANTLR - Problem - Mygrammar.g contains grammar Expr; names must be identical

 
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Users
View previous topic :: View next topic  
Author Message
welworx



Joined: 13 Jun 2010
Posts: 2

PostPosted: Mon Sep 20, 2010 2:09 pm    Post subject: ANTLR - Problem - Mygrammar.g contains grammar Expr; names must be identical Reply with quote

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(Cool: 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

PostPosted: Sat Jan 15, 2011 11:43 pm    Post subject: Reply with quote

u must to rename the name of grammare to
grammar MyGrammar;
in grammar file
good luk Smile Smile Arrow
Back to top
benhuan



Joined: 27 Dec 2012
Posts: 1

PostPosted: Thu Dec 27, 2012 3:01 am    Post subject: Reply with quote

dzsystem wrote:
u must to rename the name of grammare to
grammar MyGrammar;
in grammar file
good luk Smile Smile Arrow

Thank you so much
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Users All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo