|
Hi Erez, There is an ambiguity between var_list and expr_list. So when ply has seen "a, b = c" it could reduce the last 'c' to either var_list or expr_list. It will pick var_list because var_list appears before expr_list in the grammar. This prevents the use of the rule "assign_list : var_list ASSIGN expr_list" in that case. It works for "a,b=1,2" because "1" can only be an expr. You should be able to fix this by allowing var_list to be a type of expr_list. Perhaps something like: expr_list: var_list | var_list COMMA expr2_list | expr2 | expr2 COMMA expr_list add expr2 to be any expr except NAME, and expr2_list starts with an expr2, then any expr after that: expr: NAME | expr2 expr2: expr PLUS expr | NUMBER expr2_list: expr2 | expr2 COMMA expr_list # expr_list, not expr2_list, to allow any expr after the first non-NAME Now ply isn't forced to decide between two interpretations of what 'c' is in "a,b=c,d". Ply doesn't have to decide until it has "c,d"; which could either be a var_list or an expr_list. It will decide this depending on the next token. If the token is, say, PLUS, then 'c,d' will end up an expr_list (expr_list: var_list COMMA expr2_list, where expr2_list: expr2, and expr2: expr PLUS expr). If it's ASSIGN, it must be a var_list. This should get you closer. -bruce Erez wrote: Hello dear plyers, Please help me solve a little ambiguity! I've been trying to write a parser for python for my personal enjoyment. I'm aware that it's hard. As you probably know, Python's assignment is rather complex. You can use multiple assignments on one line, in two forms: 1) a=b=c=d=4 2) a,b=3,4 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~--- |
- Parsing Ambiguity Erez
- Re: Parsing Ambiguity Bruce Frederiksen
- Re: Parsing Ambiguity Erez Sh.
- Re: Parsing Ambiguity Bruce Frederiksen
- Re: Parsing Ambiguity Andrew Dalke
- Re: Parsing Ambiguity Erez Sh.
- Re: Parsing Ambiguity Andrew Dalke
