summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDavid Beazley <dave@dabeaz.com>2008-11-04 15:45:34 +0000
committerDavid Beazley <dave@dabeaz.com>2008-11-04 15:45:34 +0000
commitc66982f8e7dc7de7bbb73c1e40699fd22aef5eac (patch)
tree40648cfefdb76a4ba9914378c6ff5c177cc3ecf5 /test
parent3d91085e98cd5d2ddd3822793ab33bbad8287f5c (diff)
downloadply-c66982f8e7dc7de7bbb73c1e40699fd22aef5eac.tar.gz
Fixed a bug with negative stack indices
Diffstat (limited to 'test')
-rw-r--r--test/testyacc.py9
-rw-r--r--test/yacc_nested.py33
2 files changed, 42 insertions, 0 deletions
diff --git a/test/testyacc.py b/test/testyacc.py
index 4793986..08fb007 100644
--- a/test/testyacc.py
+++ b/test/testyacc.py
@@ -160,6 +160,15 @@ class YaccErrorWarningTests(unittest.TestCase):
"yacc_missing1.py:24: Symbol 'location' used, but not defined as a token or a rule.\n"
))
+ def test_yacc_nested(self):
+ run_import("yacc_nested")
+ result = sys.stdout.getvalue()
+ self.assert_(check_expected(result,
+ "A\n"
+ "A\n"
+ "A\n",
+ ))
+
def test_yacc_nodoc(self):
run_import("yacc_nodoc")
result = sys.stderr.getvalue()
diff --git a/test/yacc_nested.py b/test/yacc_nested.py
new file mode 100644
index 0000000..4c85013
--- /dev/null
+++ b/test/yacc_nested.py
@@ -0,0 +1,33 @@
+import sys
+
+if ".." not in sys.path: sys.path.insert(0,"..")
+
+from ply import lex, yacc
+
+t_A = 'A'
+t_B = 'B'
+t_C = 'C'
+
+tokens = ('A', 'B', 'C')
+
+the_lexer = lex.lex()
+
+def t_error(t):
+ pass
+
+def p_error(p):
+ pass
+
+def p_start(t):
+ '''start : A nest C'''
+ pass
+
+def p_nest(t):
+ '''nest : B'''
+ print t[-1]
+
+the_parser = yacc.yacc(debug = False, write_tables = False)
+
+the_parser.parse('ABC', the_lexer)
+the_parser.parse('ABC', the_lexer, tracking=True)
+the_parser.parse('ABC', the_lexer, tracking=True, debug=1)