[antlr-interest] Re: on parsers look and feel
micheal_jor
open.zone at virgin.net
Fri Nov 28 13:40:27 PST 2003
--- In antlr-interest at yahoogroups.com, Cristian Amitroaie
<cristian at a...> wrote:
> Hello guys,
>
> Case:
> o sometimes I kind of foreget what name I gave to the "=" token
from the
> Lexer (EQ/EQUAL/EQUALS/ASSIGN) when I want to add a new rule to a
parser.
> o sometimes I get bored to write LCURLEY instead of "{" or '{'
> o sometimes it's hard for me to follow rules full of SEMI,
LCURL(E)?Y,
> LBRACK, LPARENS and so on
>
> For example, I would like to see my parser rules look like:
>
> assign:
> ID "="^ ID ";"!
> ;
<SNIP>
> Are there any disadvantages/risks related to this approach?
<SNIP>
> Or it's just a matter of taste?
Christian,
It might be a taste thing but, there is a difference between a
character (or indeed sequence of characters i.e. string) literal and a
token. The same character/string literal can result in a different
token depending on where/when it appears in the lexers input stream.
Using character/string literals directly in parser/treeparser grammars
can result in a loss of clarity since it is possible that the same
literal repeated in a grammar actually means different things. Quite
apart from the technical issue of how well ANTLR supports the use of
character/string literals is the issue of how well our grammars convey
their intent. They should be designed to be easy to comprehend and
maintain after all.
Ric's idea of adopting a standard "template" and growing from there is
right on the ball IMO.
Cheers,
Micheal
ANTLR/C#
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list