pgy_calc.py can't parse "5 - -5"

1 view
Skip to first unread message

idad...@gmail.com

unread,
Apr 14, 2006, 10:49:48 PM4/14/06
to pyggy
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,

-e

Tim Newsham

unread,
Apr 15, 2006, 2:47:55 PM4/15/06
to idad...@gmail.com, pyggy

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/

Reply all
Reply to author
Forward
0 new messages