I have 4 grammar file: lexer L.g, parser P.g and two grammars G1 and G2 (see
below). After running antlr to generate Java files compilation fails:
[mkdir] Created dir: target\classes
[javac] Compiling 10 source files to target\classes
[javac] target\src\example\G1Lexer.java:18: cannot find symbol
[javac] symbol : class G1_L
[javac] location: class G1Lexer
[javac] public G1_L gL;
[javac] ^
[javac] target\src\example\G1Lexer.java:9: duplicate class: G1Lexer
[javac] public class G1Lexer extends Lexer {
[javac] ^
[javac] target\src\example\G1_L.java:22: cannot access example.G1Lexer
[javac] bad class file: target\src\example\G1Lexer.java
[javac] file does not contain class example.G1Lexer
[javac] Please remove or make sure it appears in the correct
subdirectory of the classpath.
[javac] public G1Lexer gG1;
[javac] ^
[javac] 3 errors
The workaround would be to move @lexer::header file to both G1.g and G2.g.
It works but the solution has 2 drawbacks:
1. Code duplication.
2. L.java can not be compiled as standalone file anymore because it lacks
package declaration.
==========================L.g================================
lexer grammar L;
@lexer::header {
package example;
}
IDENT : 'A-Z' +
;
==========================P.g==========================
parser grammar P ;
tokens {
BEGIN = 'begin';
END = 'end';
}
method: BEGIN IDENT END;
============================ G1.g ======================
grammar G1 ;
import L,P;
tokens {
PROGRAM = 'program';
}
@header {
package example;
}
program: PROGRAM method;
===========================G2.g=====================
grammar G2 ;
import L,P;
tokens {
FUNCTION = 'function';
}
@header {
package example;
}
function: FUNCTION method;
==================================================
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address
--
You received this message because you are subscribed to the Google Groups
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/il-antlr-interest?hl=en.