How can a lexer decide a token to be "get", "IdentifierName" or "Identifier" ?

程劭非 csf178 at gmail.com
Mon Feb 4 06:45:12 PST 2013


Though it's a little too long since this discussion, I've tried Allen's
idea in my parser and still find conflicting.

Consider the following rules:

PropertyAssignment :
    IdentifierName PropertyName ( ) { FunctionBody }

PropertyAssignment :
    PropertyName : AssignmentExpression

PropertyName :
    IdentifierName

when a parser get “IdentifierName” it need to decide reduce
the IdentifierName into "get" or “PropertyName”. For LR parsers there is no
way to do these things.

I would suggest another way:

IdentifierName ::
    FutureReservedWord
    Keywords
    Identifier
    SpecialWord

SpecialWord ::
    get
    set

2012/5/3 Allen Wirfs-Brock <allen at wirfs-brock.com>

> If I was going to move something to the syntactic grammar it would
> probably be the current definition of Identifier
>
> Identifier :
>     IdentifierName but not ReservedWord
>
> You might  then lex all IdentifierNames (including ReservedWord) as
> IdentifierName tokens and treat all occurrences of keyword terminals in the
> syntactic grammar as short-hands for saying: IdentifierName matching this
> specific keyword.  For example:
>
> PropertyAssignment :
>    get PropertyName ( ) { FunctionBody }
>
> could be interpreted as:
>
> PropertyAssignment :
>    IdentifierName PropertyName ( ) { FunctionBody }
>
> with the static semantic restriction that the text of IdentifierName must
> be "get"
>
>
> Allen
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130204/5e0a7124/attachment.html>


More information about the es-discuss mailing list