1
votes

antlr3ide seems to generate parser and lexer files without the package info where the java files are located (such as package tour.trees;, here the relative path folder tour/trees contains the corresponding files ExprParser.java and ExprLexer.java).

The official forum seems a bit inactive and the documentation gives me not much help:(

Below is a sample grammar file Expr.g:

grammar Expr;

options {
  language = Java;
}


prog : stat+;

stat : expr NEWLINE
     | ID '=' expr NEWLINE
     | NEWLINE
     ;

expr: multiExpr (('+'|'-') multiExpr)*
    ;

multiExpr : atom('*' atom)*
    ;

atom : INT
     | ID
     | '(' expr ')'
     ;

ID : ('a'..'z'|'A'..'Z')+ ;
INT : '0'..'9'+;
NEWLINE : '\r'?'\n';
WS : (' '|'\t'|'\n'|'\r')+{skip();};
1
@BartKiers I didn't add additional options block for the grammar file?Should I have to?Hongxu Chen
@BartKiers Thanks for your advice:)I have now added a sample code.Hongxu Chen

1 Answers

1
votes

The package declaration is not something that antlrv3ide generates. This is done by ANTLR. To let ANTLR generate source files in the package tour.trees, add @header blocks containing the package declarations in your grammar file like this:

grammar Expr;

options {
  language = Java;
}

// placed _after_ the `options`-block!    
@parser::header { package tour.trees; }
@lexer::header { package tour.trees; }

prog : stat+;

...