[antlr-interest] Bug report: Composite grammar with all tokens defined in Lexer
George S. Cowan
cowang at comcast.net
Mon Dec 22 09:52:01 PST 2008
Using ANTLR 3.1.1 on Windows XP, I was unable to split Yang Jiang's java.g
(http://openjdk.java.net/projects/compiler-grammar/antlrworks/Java.g) into
separate parser and lexer grammars for a composite grammar. The following
grammar distilled from that one works, but not if the PUBLIC rule is
uncommented. The file Debug_DebugLex.java is not generated; however, there
is no warning or error message.
The pattern seems to be that the grammar fails when all the tokens used in
the parse grammar have a lex grammar rule defined for them.
------------ begin Debug.g -----------
grammar Debug;
options {
backtrack=true;
memoize=true;
}
import DebugParse
, DebugLex
;
interfaceHeader
: modifiers 'interface' IDENTIFIER
;
------------- end Debug.g ------------
------------ begin DebugLex.g -----------
lexer grammar DebugLex;
INTERFACE
: 'interface'
;
// PUBLIC
// : 'public'
// ;
IDENTIFIER
: IdentifierStart IdentifierPart*
;
fragment
IdentifierStart
: 'a'..'z' | 'A'..'Z'
;
fragment
IdentifierPart
: 'a'..'z' | 'A'..'Z' | '0'..'9'
;
WS
: (
' '
| '\r'
| '\t'
| '\u000C'
| '\n'
)
{
skip();
}
;
------------- end DebugLex.g ------------
------------ begin DebugParse.g -----------
parser grammar DebugParse;
modifiers
:
( 'public'
)*
;
interfaceHeader
: modifiers 'interface' IDENTIFIER
;
------------- end DebugParse.g ------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20081222/2a7989a9/attachment.html
More information about the antlr-interest
mailing list