PDA

View Full Version : ANTLR - Problema durante compilazione


vfldj
30-07-2013, 22:27
Ciao a tutti, devo usare antlr per l'università ma non so se l'ho installato bene.
Premetto che sto usando Windows 7 64 bit.
Ho scaricato da http://www.antlr3.org/download/antlr-3.5-complete.jar la versione 3.5 di antlr e da http://www.antlr3.org/download/antlrworks-1.4.2.jar antlrwork 1.4.2.
Poi ho messo questi due file in una cartella C:\Javalib ed ho impostato il classpath aggiungendo C:\Javalib\antlr-3.5-complete.jar; alla variabile d'ambiente Path (è la stessa a cui ho aggiunto anche il percorso delle jkd di java).
Poi, per esempio, ho provato a seguire i passi descritti qui http://www.antlr.org/wiki/display/ANTLR3/Expression+evaluator.
Quindi ho copiato il testo della grammatica in un file Expr.g e l'ho salvato sempre nella cartella C:\Javalib.
Poi dal prompt dei comandi ho eseguito (trovandomi in C:\Javalib) java -cp antlr-3.5-complete.jar org.antlr.Tool Expr.g ed effettivamente mi ha prodotto i 3 file ExprLexer.java, ExprParser.java e Expr.tokens.
Fin qui quindi tutto bene...
Ora iniziano i problemi.
Ho poi copiato in un file java il programmino Test.java e ho provato a compilarlo eseguendo dal prompt dei comandi (dopo essermi posizionato nella cartella C:\Javalib) javac Test.java ExprLexer.java ExprParser.java ma mi da errore, anzi.. mi da 100 errori.
Ho provato allora scrivendo sul prompt javac -cp .:.\antlr-3.5-complete.jar Test.java ExprLexer.java ExprParser.java e javac -cp .;C:\antlr-3.5-complete.jar Test.java ExprLexer.java ExprParser.java ma niente, sempre gli stessi 100 errori.

Ho installato bene tutto? Le variabili d'ambiente sono corrette? Come faccio a compilare?

Grazie :)

mone.java
31-07-2013, 09:12
Quali Errori ti da ?

vfldj
31-07-2013, 15:37
Grazie per la risposta. Ecco gli errori:

location: class ExprParser
ExprParser.java:434: error: cannot find symbol
public static final BitSet FOLLOW_INT_in_atom230 = new BitSet(new long[]
{0x0000000000000002L});
^
symbol: class BitSet
location: class ExprParser
ExprParser.java:435: error: cannot find symbol
public static final BitSet FOLLOW_ID_in_atom242 = new BitSet(new long[]{
0x0000000000000002L});
^
symbol: class BitSet
location: class ExprParser
ExprParser.java:436: error: cannot find symbol
public static final BitSet FOLLOW_8_in_atom262 = new BitSet(new long[]{0
x0000000000000130L});
^
symbol: class BitSet
location: class ExprParser
ExprParser.java:437: error: cannot find symbol
public static final BitSet FOLLOW_expr_in_atom264 = new BitSet(new long[
]{0x0000000000000200L});
^
symbol: class BitSet
location: class ExprParser
ExprParser.java:438: error: cannot find symbol
public static final BitSet FOLLOW_9_in_atom266 = new BitSet(new long[]{0
x0000000000000002L});
^
symbol: class BitSet
location: class ExprParser
Test.java:5: error: cannot find symbol
ANTLRInputStream input = new ANTLRInputStream(System.in);
^
symbol: class ANTLRInputStream
location: class Test
Test.java:5: error: cannot find symbol
ANTLRInputStream input = new ANTLRInputStream(System.in);
^
symbol: class ANTLRInputStream
location: class Test
Test.java:7: error: cannot find symbol
CommonTokenStream tokens = new CommonTokenStream(lexer);
^
symbol: class CommonTokenStream
location: class Test
Test.java:7: error: cannot find symbol
CommonTokenStream tokens = new CommonTokenStream(lexer);
^
symbol: class CommonTokenStream
location: class Test
ExprLexer.java:25: error: cannot find symbol
return new Lexer[] {};
^
symbol: class Lexer
location: class ExprLexer
ExprLexer.java:30: error: cannot find symbol
this(input, new RecognizerSharedState());
^
symbol: class RecognizerSharedState
location: class ExprLexer
ExprLexer.java:35: error: method does not override or implement a method from a
supertype
@Override public String getGrammarFileName() { return "Expr.g"; }
^
ExprLexer.java:41: error: cannot find symbol
int _channel = DEFAULT_TOKEN_CHANNEL;
^
symbol: variable DEFAULT_TOKEN_CHANNEL
location: class ExprLexer
ExprLexer.java:45: error: cannot find symbol
match('(');
^
symbol: method match(char)
location: class ExprLexer
ExprLexer.java:48: error: cannot find symbol
state.type = _type;
^
symbol: variable state
location: class ExprLexer
ExprLexer.java:49: error: cannot find symbol
state.channel = _channel;
^
symbol: variable state
location: class ExprLexer
ExprLexer.java:61: error: cannot find symbol
int _channel = DEFAULT_TOKEN_CHANNEL;
^
symbol: variable DEFAULT_TOKEN_CHANNEL
location: class ExprLexer
ExprLexer.java:65: error: cannot find symbol
match(')');
^
symbol: method match(char)
location: class ExprLexer
ExprLexer.java:68: error: cannot find symbol
state.type = _type;
^
symbol: variable state
location: class ExprLexer
ExprLexer.java:69: error: cannot find symbol
state.channel = _channel;
^
symbol: variable state
location: class ExprLexer
ExprLexer.java:81: error: cannot find symbol
int _channel = DEFAULT_TOKEN_CHANNEL;
^
symbol: variable DEFAULT_TOKEN_CHANNEL
location: class ExprLexer
ExprLexer.java:85: error: cannot find symbol
match('*');
^
symbol: method match(char)
location: class ExprLexer
ExprLexer.java:88: error: cannot find symbol
state.type = _type;
^
symbol: variable state
location: class ExprLexer
ExprLexer.java:89: error: cannot find symbol
state.channel = _channel;
^
symbol: variable state
location: class ExprLexer
ExprLexer.java:101: error: cannot find symbol
int _channel = DEFAULT_TOKEN_CHANNEL;
^
symbol: variable DEFAULT_TOKEN_CHANNEL
location: class ExprLexer
ExprLexer.java:105: error: cannot find symbol
match('+');
^
symbol: method match(char)
location: class ExprLexer
ExprLexer.java:108: error: cannot find symbol
state.type = _type;
^
symbol: variable state
location: class ExprLexer
ExprLexer.java:109: error: cannot find symbol
state.channel = _channel;
^
symbol: variable state
location: class ExprLexer
ExprLexer.java:121: error: cannot find symbol
int _channel = DEFAULT_TOKEN_CHANNEL;
^
symbol: variable DEFAULT_TOKEN_CHANNEL
location: class ExprLexer
ExprLexer.java:125: error: cannot find symbol
match('-');
^
symbol: method match(char)
location: class ExprLexer
ExprLexer.java:128: error: cannot find symbol
state.type = _type;
^
symbol: variable state
location: class ExprLexer
ExprLexer.java:129: error: cannot find symbol
state.channel = _channel;
^
symbol: variable state
location: class ExprLexer
ExprLexer.java:141: error: cannot find symbol
int _channel = DEFAULT_TOKEN_CHANNEL;
^
symbol: variable DEFAULT_TOKEN_CHANNEL
location: class ExprLexer
ExprLexer.java:145: error: cannot find symbol
match('=');
^
symbol: method match(char)
location: class ExprLexer
ExprLexer.java:148: error: cannot find symbol
state.type = _type;
^
symbol: variable state
location: class ExprLexer
ExprLexer.java:149: error: cannot find symbol
state.channel = _channel;
^
symbol: variable state
location: class ExprLexer
ExprLexer.java:161: error: cannot find symbol
int _channel = DEFAULT_TOKEN_CHANNEL;
^
symbol: variable DEFAULT_TOKEN_CHANNEL
location: class ExprLexer
ExprLexer.java:170: error: cannot find symbol
int LA1_0 = input.LA(1);
^
symbol: variable input
location: class ExprLexer
ExprLexer.java:179: error: cannot find symbol
if ( (input.LA(1) >= 'A' && input.LA(1)
<= 'Z')||(input.LA(1) >= 'a' && input.LA(1) <= 'z') ) {
^
symbol: variable input
location: class ExprLexer
ExprLexer.java:179: error: cannot find symbol
if ( (input.LA(1) >= 'A' && input.LA(1)
<= 'Z')||(input.LA(1) >= 'a' && input.LA(1) <= 'z') ) {
^
symbol: variable input
location: class ExprLexer
ExprLexer.java:179: error: cannot find symbol
if ( (input.LA(1) >= 'A' && input.LA(1)
<= 'Z')||(input.LA(1) >= 'a' && input.LA(1) <= 'z') ) {

^
symbol: variable input
location: class ExprLexer
ExprLexer.java:179: error: cannot find symbol
if ( (input.LA(1) >= 'A' && input.LA(1)
<= 'Z')||(input.LA(1) >= 'a' && input.LA(1) <= 'z') ) {

^
symbol: variable input
location: class ExprLexer
ExprLexer.java:180: error: cannot find symbol
input.consume();
^
symbol: variable input
location: class ExprLexer
ExprLexer.java:183: error: cannot find symbol
MismatchedSetException mse = new
MismatchedSetException(null,input);
^
symbol: class MismatchedSetException
location: class ExprLexer
ExprLexer.java:183: error: cannot find symbol
MismatchedSetException mse = new
MismatchedSetException(null,input);

^
symbol: class MismatchedSetException
location: class ExprLexer
ExprLexer.java:183: error: cannot find symbol
MismatchedSetException mse = new
MismatchedSetException(null,input);

^
symbol: variable input
location: class ExprLexer
ExprLexer.java:192: error: cannot find symbol
EarlyExitException eee = new EarlyExitEx
ception(1, input);
^
symbol: class EarlyExitException
location: class ExprLexer
ExprLexer.java:192: error: cannot find symbol
EarlyExitException eee = new EarlyExitEx
ception(1, input);
^
symbol: class EarlyExitException
location: class ExprLexer
ExprLexer.java:192: error: cannot find symbol
EarlyExitException eee = new EarlyExitEx
ception(1, input);

^
symbol: variable input
location: class ExprLexer
ExprLexer.java:200: error: cannot find symbol
state.type = _type;
^
symbol: variable state
location: class ExprLexer
ExprLexer.java:201: error: cannot find symbol
state.channel = _channel;
^
symbol: variable state
location: class ExprLexer
ExprLexer.java:213: error: cannot find symbol
int _channel = DEFAULT_TOKEN_CHANNEL;
^
symbol: variable DEFAULT_TOKEN_CHANNEL
location: class ExprLexer
ExprLexer.java:222: error: cannot find symbol
int LA2_0 = input.LA(1);
^
symbol: variable input
location: class ExprLexer
ExprLexer.java:231: error: cannot find symbol
if ( (input.LA(1) >= '0' && input.LA(1)
<= '9') ) {
^
symbol: variable input
location: class ExprLexer
ExprLexer.java:231: error: cannot find symbol
if ( (input.LA(1) >= '0' && input.LA(1)
<= '9') ) {
^
symbol: variable input
location: class ExprLexer
100 errors

C:\Javalib>

mone.java
31-07-2013, 16:04
È evidente che ti manca qualcosa :D premetto che non ho mai usato antlr, dunque il primo passo che hai fatto, ovvero mettere la libreria nella variabile d'ambiante Path, non ha molto senso, anzi direi che è inutile. In generale in Java quando devi includere delle librerie in un programma fallo dal comando che esegue il programma stesso usando, come hai fatto tu:


javac -cp ecc..


Detto questo noto che innanzitutto la seconda libreria che hai linkato non è mai stata usata (antlrwork 1.4.2.) e penso che nemmeno sia utile, poi per compilare dai questo comando:


javac -cp .:antlr-3.5-complete.jar Test.java ExprLexer.java ExprParser.java


e per eseguire:


java -cp .:antlr-3.5-complete.jar Test


inserisci la tua espressione e per dare <EOF> premi Ctrl+D

vfldj
31-07-2013, 16:20
È evidente che ti manca qualcosa :D premetto che non ho mai usato antlr, dunque il primo passo che hai fatto, ovvero mettere la libreria nella variabile d'ambiante Path, non ha molto senso, anzi direi che è inutile. In generale in Java quando devi includere delle librerie in un programma fallo dal comando che esegue il programma stesso usando, come hai fatto tu:


javac -cp ecc..


Detto questo noto che innanzitutto la seconda libreria che hai linkato non è mai stata usata (antlrwork 1.4.2.) e penso che nemmeno sia utile, poi per compilare dai questo comando:


javac -cp .:antlr-3.5-complete.jar Test.java ExprLexer.java ExprParser.java


e per eseguire:


java -cp .:antlr-3.5-complete.jar Test


inserisci la tua espressione e per dare <EOF> premi Ctrl+D

Ho tolto dalla variabile d'ambiente il path C:\Javalib, ho provato a compilare col comando che hai scritto tu ma mi da sempre i 100 errori. Ho capito male io?
Mi sento un pò rinco..

mone.java
31-07-2013, 17:33
L'unica differenza è che io ho linux e te windows quindi magari cambia qualcosa nella sintassi del parametro -cp.... Investiga, su quello..

mone.java
31-07-2013, 18:00
L'unica differenza è che io ho linux e te windows quindi magari cambia qualcosa nella sintassi del parametro -cp.... Investiga, su quello..

vfldj
31-07-2013, 18:00
L'unica differenza è che io ho linux e te windows quindi magari cambia qualcosa nella sintassi del parametro -cp.... Investiga, su quello..

va bene, grazie!

vfldj
01-08-2013, 19:39
Non sono ancora riuscito a risolvere...

mone.java
02-08-2013, 08:11
Non so proprio come aiutarti, windows non lo uso da tempi assai remoti (meno male :D ).. quindi dovresti chiedere a qualcuno che usa windows come si imposta il classpath di java (anche se a rigor di logica dovrebbe essere uguale a linux).... Se non riesci cmq posso provare con una macchina virtuale windows....

vfldj
04-08-2013, 15:58
Non so proprio come aiutarti, windows non lo uso da tempi assai remoti (meno male :D ).. quindi dovresti chiedere a qualcuno che usa windows come si imposta il classpath di java (anche se a rigor di logica dovrebbe essere uguale a linux).... Se non riesci cmq posso provare con una macchina virtuale windows....

Se per te non è un grosso problema provare con una macchina virtuale, mi faresti un enorme favore :)

mone.java
06-08-2013, 17:14
SI trattava di mettere il ; alla fine dell'argomento -cp:


java -cp antlr-3.5-complete.jar; Test


Provato su windows XP 32-bit java 1.7.0_15...

:)

vfldj
06-08-2013, 20:20
SI trattava di mettere il ; alla fine dell'argomento -cp:


java -cp antlr-3.5-complete.jar; Test


Provato su windows XP 32-bit java 1.7.0_15...

:)

Grazie infinite, gentilissimo! :)