On Fri, 14 Apr 2006, idade
...@gmail.com wrote:
> It looks like the unary minus setup for pgy_calc.pyg doesn't work at
> the moment. However, the one for ply does properly parse "5 - -5". Is
> there a simple fix for this (since I want to use this kind of grammar
> in my code)". Thanks,
Yikes! Thanks for pointing this out. The precedences are backwards.
Make UNARYMINUS higher precedence than the rest:
cvs diff: Diffing .
Index: pyg_calc.pyg
===================================================================
RCS file: /u1/home/newsham/cvs/pyggy/examples/pyg_calc.pyg,v
retrieving revision 1.1
diff -u -r1.1 pyg_calc.pyg
--- pyg_calc.pyg 2 Jul 2004 05:47:44 -0000 1.1
+++ pyg_calc.pyg 15 Apr 2006 18:44:54 -0000
@@ -2,9 +2,9 @@
code :
names = {}
+%right UNARYMINUS;
%left TIMES DIVIDE;
%left PLUS;
-%right UNARYMINUS;
statement -> NAME EQUALS expression :
names[kids[0]] = kids[2]
And now it works:
calc > 2 + 3 * -5 - -100
87
> -e
Tim Newsham
http://www.lava.net/~newsham/