[antlr-interest] Re: Unified grammar and # directives for a C-like language
uprightness_of_character
andrei at metalanguage.com
Wed May 14 16:40:54 PDT 2003
I posted another message (I'm not sure whether it's lost or on its
way) explaining the problems with the two proposed solutions to the
'#'-directive problem. In short:
* Jim O'Connor's suggestion engenders an ambiguity that antlr resolves
in the undesired direction;
* Monty's suggestion recognizes '#'-directives that start in column 1,
but without leading spaces.
I've had a lot to learn from your answers - thanks a lot - and I
synthesized something that works. I wonder if this is elegant enough,
or if there's an easier and clearer solution.
I defined my whitespaces like this:
// Whitespace (no newlines) -- ignored
WS
{ const bool firstCol = getColumn() == 1; }
:
(
' '
| '\t'
| '\f'
)+
{
$setType(antlr::Token::SKIP);
}
( { firstCol }? '#' { $setType(HASH_DIRECTIVE_BEGIN); } )?
;
And I also defined:
HASH_DIRECTIVE_BEGIN : { getColumn()==1}? '#' ;
These two rules match the '#' directives correctly. I am a bit unhappy
that the concept is spread in two rules, so if there's a better
solution, please let me know!
Andrei
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list