aboutsummaryrefslogtreecommitdiff
path: root/imago/sgfParser/sgfyacc.py
diff options
context:
space:
mode:
Diffstat (limited to 'imago/sgfParser/sgfyacc.py')
-rwxr-xr-ximago/sgfParser/sgfyacc.py40
1 files changed, 25 insertions, 15 deletions
diff --git a/imago/sgfParser/sgfyacc.py b/imago/sgfParser/sgfyacc.py
index bd00df6..d18f2a8 100755
--- a/imago/sgfParser/sgfyacc.py
+++ b/imago/sgfParser/sgfyacc.py
@@ -1,4 +1,4 @@
-#!/bin/python
+#!/usr/bin/python
# --------------------------------------
# sgyacc.py
@@ -7,8 +7,8 @@
import ply.yacc as yacc
-from sgflex import tokens
-from astNode import ASTNode, Property
+from imago.sgfParser.sgflex import tokens
+from imago.sgfParser.astNode import ASTNode, Property
def p_tree(p):
'''tree : LPAREN node RPAREN
@@ -31,7 +31,10 @@ def p_node(p):
def p_node_prop(p):
'node : node property'
- p[1].props[p[2].name] = p[2].value
+ if p[1].hasProperty(p[2].name):
+ print("Syntax error: node already contains a property named - %s" % p[2].name)
+ raise SyntaxError
+ p[1].props.append(p[2])
p[0] = p[1]
def p_property(p):
@@ -43,19 +46,26 @@ def p_property_value(p):
p[1].addValue(p[2])
p[0] = p[1]
-def p_error(_):
+def p_error(p):
"""Error rule for syntax errors"""
- print("Syntax error in input!")
+ print("Syntax error in input - %s" % p)
# Build the parser
parser = yacc.yacc()
+#parser = yacc.yacc(start='property')
-while True:
- try:
- s = input('calc > ')
- except EOFError:
- break
- if not s:
- continue
- result = parser.parse(s)
- print(result.toString())
+def main():
+
+ s = ""
+ while True:
+ try:
+ s = input('calc > ')
+ except EOFError:
+ break
+ if not s:
+ continue
+ result = parser.parse(s, debug=True)
+ print(result.toString())
+
+if __name__ == '__main__':
+ main()