dcsimg
dumb question
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Saturday, March 12, 2005 12:03 PM

Hi everyone! I'm trying to use Antlr for the first time. I've generated parsers and lexers (java) but now I'm unable to use them. I've written a very simple grammar for test purpose but I do not have any results, since I've got errors when I use it. So here is the code of my grammar: class ProcessusParser extends Parser; options { buildAST = true; k = 3; } spec : (ID ";")+ EOF! ; class ProcessusLexer extends Lexer; options { k = 3; } ID options {testLiterals=true;} :    More>>


Hi everyone!
I'm trying to use Antlr for the first time. I've generated parsers and lexers (java) but now I'm unable to use them.
I've written a very simple grammar for test purpose but I do not have any results, since I've got errors when I use it. So here is the code of my grammar:







class ProcessusParser extends Parser;

options {

buildAST = true;

k = 3;

}



spec

: (ID ";")+ EOF!

;



class ProcessusLexer extends Lexer;




options {

k = 3;

}



ID

options {testLiterals=true;}

: ('a'..'z'|'A'..'Z')
('a'..'z'|'A'..'Z'|'_'|'0'..'9')*

;




And now the code of my main class :




class Processus {




public static void main(String[] args)

throws IOException {



FileInputStream processusFichier = new FileInputStream(args[0]);

ProcessusLexer lexerent = new ProcessusLexer(processusFichier);

ProcessusParser parserent = new ProcessusParser(lexerent);




try {

parserent.spec();

}

catch(RecognitionException e) {

System.err.println("exception: "+e);

}

catch (TokenStreamException e) {

System.err.println("exception: "+e);

}

}

}




When I launch the main with the following input :


var1;

var2;

var3;

var4;

var5;




I've got the following message: "exception: line 1:5: unexpected char: ';'"


If I put spaces, like for exemple : "var1 ;", the unexpected char becomes " " (space char).


I really do not understand, I believe it is very simple but I don't see the problem. Thanks for your help

   <<Less

Re: dumb question

Posted By:   Kai_Koehne  
Posted On:   Monday, March 14, 2005 07:16 AM

This should work:


class ProcessusParser extends Parser;
options {
buildAST = true;
k = 3;
}

spec
: (ID SEMI (NL)?)+ EOF!
;

class ProcessusLexer extends Lexer;

options {
k = 3;
}

SEMI : ';';
NL : ('
')? '
';
ID
options {testLiterals=true;}
: ('a'..'z'|'A'..'Z')
('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
;

About | Sitemap | Contact