Pedro Lopes wrote:
> As a result, the statement
>
> anArray(aVar + 5) = anotherVar
>
> can be interpreted in 2 different ways:
> - assign to array "anArray", index "aVar + 5", the value of the
> expression "anotherVar"
> - call the function "anArray" with a single argument which is the
> expression "(aVar + 5) = anotherVar" (funky isn't it?)
>
> The above situation causes a shift/reduce conflict in my grammar. The
> vbscript interpreter chooses the first option, so that's what I need
> to do too.
I know nothing of vbscript, but some languages can disambiguate this 
case by having the scanner(lexer) look up the identifier in the symbol 
table.  If the identifier has been declared as an array, the scanner 
returns the token ARRAYVAR, but if it's defined as a function, then the 
token FUNVAR is returned.  This assumes that variables are declared 
ahead of time and given a type.
>  Here are the relevant (I think) parser states:
>
> state 80
>
>     (48) lvalue -> qualified_name ( indexlist . )
>     (37) indexlist -> indexlist . , expression
>
>     )               shift and go to state 112
>     ,               shift and go to state 113
>
> state 81
>
>     (70) expression -> ( expression . )
>     (38) indexlist -> expression .
>   
I don't think that you can use precedence to solve this.  What you can 
do is to make the indexlist and parenthesized expression the same where 
there is no comma:

lvalue : qualified_name indexer
indexer : ( expression )
              | ( expression , indexlist )
indexlist : expression
               | indexlist , expression

then the parser can shift the ) after a single expression and look at 
the next token before deciding what to do.  At this point, you will 
probably end up with a reduce/reduce conflict which you can control by 
the order of the productions in your grammar.

-bruce

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"ply-hack" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/ply-hack?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to