[antlr-interest] Compiling the Generated Code
Marc-André Laverdière
ma_laver at ciise.concordia.ca
Tue Apr 24 15:08:05 PDT 2007
Hello,
It looks like I replied to Johannes only! My apologies! I used his
suggestion, which takes care of the greedy problem, but the code won't
compile unless I comment out the code about error handling here. This is
obviously not a showstopper, but should be fixed.
I used Antlrworks b11, generating code in Java. My IDE is Eclipse
running Sun Java 1.6.0.1.
I didn't see this in the bug tracking... I would file the bug myself,
but I can't get an account ;)
From the grammar:
sh_behavior
: 'BeginBehavior' sh_code_blob 'EndBehavior';
sh_primitive_parameter
: '<' sh_code_blob '>';
sh_code_blob
: ( options {greedy=false;} : . )*; // can we disable the
white space analysis for this?
Here is the function in the parser where Java complains...
// $ANTLR start sh_code_blob
// C:\\Documents and Settings\\marc-andre\\Desktop\\SHL.g:72:1:
sh_code_blob : ( options {greedy=false; } : . )* ;
public final void sh_code_blob() throws RecognitionException {
try {
// C:\\Documents and
Settings\\marc-andre\\Desktop\\SHL.g:73:4: ( ( options {greedy=false; }
: . )* )
// C:\\Documents and
Settings\\marc-andre\\Desktop\\SHL.g:73:4: ( options {greedy=false; } : . )*
{
// C:\\Documents and
Settings\\marc-andre\\Desktop\\SHL.g:73:4: ( options {greedy=false; } : . )*
loop18:
do {
int alt18=2;
switch ( input.LA(1) ) {
case 19:
{
switch ( input.LA(2) ) {
case 17:
{
alt18=2;
}
break;
case 33:
case 34:
case 35:
{
alt18=2;
}
break;
case ID:
case FILE:
case INT:
case WS:
case 8:
case 9:
case 10:
case 11:
case 12:
case 13:
case 14:
case 15:
case 16:
case 18:
case 19:
case 20:
case 21:
case 22:
case 23:
case 24:
case 25:
case 26:
case 27:
case 28:
case 29:
case 30:
case 31:
case 32:
case 36:
case 37:
case 38:
case 39:
case 40:
case 41:
{
alt18=1;
}
break;
}
}
break;
case 32:
{
switch ( input.LA(2) ) {
case 28:
{
alt18=2;
}
break;
case 26:
{
alt18=2;
}
break;
case 27:
{
alt18=2;
}
break;
case 38:
case 39:
{
alt18=2;
}
break;
case 18:
{
alt18=2;
}
break;
case 29:
{
alt18=2;
}
break;
case 32:
{
alt18=2;
}
break;
case ID:
case FILE:
case INT:
case WS:
case 8:
case 9:
case 10:
case 11:
case 12:
case 13:
case 14:
case 15:
case 16:
case 17:
case 19:
case 20:
case 21:
case 22:
case 23:
case 24:
case 25:
case 30:
case 31:
case 33:
case 34:
case 35:
case 36:
case 37:
case 40:
case 41:
{
alt18=1;
}
break;
}
}
break;
case ID:
case FILE:
case INT:
case WS:
case 8:
case 9:
case 10:
case 11:
case 12:
case 13:
case 14:
case 15:
case 16:
case 17:
case 18:
case 20:
case 21:
case 22:
case 23:
case 24:
case 25:
case 26:
case 27:
case 28:
case 29:
case 30:
case 31:
case 33:
case 34:
case 35:
case 36:
case 37:
case 38:
case 39:
case 40:
case 41:
{
alt18=1;
}
break;
}
switch (alt18) {
case 1 :
// C:\\Documents and
Settings\\marc-andre\\Desktop\\SHL.g:73:32: .
{
matchAny(input);
}
break;
default :
break loop18;
}
} while (true);
}
}
catch (RecognitionException re) {
reportError(re);
recover(input,re);
}
finally {
}
return ;
}
// $ANTLR end sh_code_blob
Johannes Luber wrote:
> Marc-André Laverdière wrote:
>> Hello,
>>
>> I generated the code from my grammar using ANTLRWorks 1.0b11 and I've
>> imported the code in my Eclipse project. There are compiler errors that
>> I don't understand.
>>
>> They happen in the parser: one of my rules has {greedy=false;}, and this
>> is put in the Java code, but the compiler complains that greedy doesn't
>> exist. When I comment it out, it complains about a RecognitionException
>> that can't be thrown, so I'd have to remove the try, catch and finally
>> structure. Is it supposed to be like that?
>>
>> Further, looking at that code, I don't see how it is supposed to act in
>> a non-greedy manner! It is a (.)* rule, non-greedy, that should stop
>> when a given token is read.
>>
>> It works fine in AntlrWorks, btw (tested in 1.0b10). So, its a bit of a
>> surprise here.
>
> Can you post the relevant parts of the grammar? Makes it easier to see
> if you have a syntax error, which is now discovered, or if ANTLRworks
> got a new bug. Your rule should look like this: "( options
> {greedy=false;} : . )*".
>
>> Thanks a ton in advance. This is my first excursion in the field of
>> programming language design, and I hope it won't be a too painful one!
>
> Did you read this tutorial (and the others)
> <http://www.antlr.org/wiki/display/ANTLR3/Quick+Starter+on+Parser+Grammars+-+No+Past+Experience+Required>
> already?
>
> Best regards,
> Johannes Luber
--
Marc-André LAVERDIÈRE, B. Eng., M. A. Sc. (in progress)
Computer Security Laboratory - Laboratoire de sécurité informatique
CIISE, Université Concordia University, Montréal, Québec, Canada
www.ciise.concordia.ca
/"\
\ / ASCII Ribbon Campaign
X against HTML e-mail
/ \
"Perseverance must finish its work so that you may be mature and
complete, not lacking anything." -James 1:4
More information about the antlr-interest
mailing list