!_NEWLINE_!Why does the following lexer rule:!_NEWLINE_!!_NEWLINE_!!_NEWLINE_!!_NEWLINE_! protected ...
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Stephen_Johnson
Posted On:   Friday, March 2, 2001 05:55 PM

Why does the following lexer rule: protected NEWLINE : ( ' ' ( options { greedy = true; } : ' ' )? // dos and mac line breaks | ' ' // xNIX line break ) { newline(); }; Cause this C++ to be generated? switch ( LA(1)) { case static_cast (' '): { match(static_cast (' ')); { if ((LA(1)==static_cast (' ')) && (true)) { match(static_cast (' ')); } else if true { } else { throw antlr::NoViableAltForCharException(LA(1), getFilename(), getLine()); } } break   More>>


Why does the following lexer rule:



			
protected NEWLINE :
( '
' ( options { greedy = true; } : '
' )? // dos and mac line breaks
| '
' // xNIX line break
)
{ newline(); };



Cause this C++ to be generated?



			
switch ( LA(1)) {
case static_cast ('
'):
{
match(static_cast ('
'));
{
if ((LA(1)==static_cast ('
')) && (true)) {
match(static_cast ('
'));
}
else if true {
}
else {
throw antlr::NoViableAltForCharException(LA(1), getFilename(), getLine());
}
}
break;
}
case static_cast ('
'):
{
match(static_cast ('
'));
break;
}
default:
{
throw antlr::NoViableAltForCharException(LA(1), getFilename(), getLine());
}
}



My problem is that the "else if true" clause causes my compiler (MSVC 6.0) to choke, and as far as I can tell there's no need for this or the following else clause. Come to think of it, I've noticed a lot of needless branches on "true" being generated in the code. Can anyone explain this to me?

   <<Less

Re: !_NEWLINE_!Why does the following lexer rule:!_NEWLINE_!!_NEWLINE_!!_NEWLINE_!!_NEWLINE_! protected ...

Posted By:   Terence_Parr  
Posted On:   Monday, April 9, 2001 08:33 PM

I'm not sure if this is specific to the C++ output, but I know that ANTLR often generates code that is inoptimal since it uses a general template to generate code and doesn't optimize it.
About | Sitemap | Contact