[antlr-interest] How can I ignore reserved words incertaincases ?
Jamie Briant
jbriant at highmoonstudios.com
Thu Nov 30 10:18:45 PST 2006
The csharp_v1 parser from 2.7.7 does the following for the "contextual keywords":
nonKeywordLiterals
: "add"
| "remove"
| "get"
| "set"
| "assembly"
| "field"
| "method"
| "module"
| "param"
| "property"
| "type"
;
identifier
: IDENTIFIER
| n:nonKeywordLiterals { #n.setType(IDENTIFIER); }
;
getAccessorDeclaration! [AST attribs]
: g:"get" abody:accessorBody
{ ## = #( #g, #attribs, #abody ); }
;
Jamie
-----Original Message-----
From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Terence Parr
Sent: Thursday, November 30, 2006 10:12 AM
To: ANTLR Interest
Subject: Re: [antlr-interest] How can I ignore reserved words incertaincases ?
On Nov 30, 2006, at 9:44 AM, VAUCHER Laurent wrote:
> Isn't there a performance penalty in this case?
Most definitely.
> I mean, almost all tokens look like IDs, so the parser is forced to
> use the predicates to choose the right rule. There is no
> possibility to precompute jump-tables (or whatever you call them).
The other alternative is to do
identifier : KEY1 | KEY2 | ... | ID ;
which is a set comparison and should be faster.
Ter
>
>
> Laurent.
>
>
> -----Message d'origine-----
> De : antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] De la part de Terence Parr
> Envoyé : 30 November 2006 18:17
> À : ANTLR Interest
> Objet : Re: [antlr-interest] How can I ignore reserved words in
> certaincases ?
>
> Hi. An example from the book on predicated LL(*) parsing:
>
> http://www.antlr.org/wiki/pages/viewpage.action?pageId=1741
>
> Ter
>
>
More information about the antlr-interest
mailing list