Make piyacc.py standalone
authorNick Downing <nick@ndcode.org>
Mon, 21 Jan 2019 07:28:51 +0000 (18:28 +1100)
committerNick Downing <nick@ndcode.org>
Mon, 21 Jan 2019 07:28:51 +0000 (18:28 +1100)
piyacc.py

index 5bd85aa..fbf84d7 100755 (executable)
--- a/piyacc.py
+++ b/piyacc.py
@@ -65,7 +65,15 @@ if len(args) < 1:
 in_file = args[0]
 
 with open(in_file) as fin:
-  _ast = element.deserialize(fin, ast.factory)
+  if in_file[-4:] == '.xml':
+    _ast = element.deserialize(fin, ast.factory)
+  else:
+    import lex_yy
+    import state
+    import y_tab
+    state.infilename = in_file
+    lex_yy.yyin = fin
+    _ast = y_tab.yyparse(ast.AST)
 #element.serialize(_ast, 'a.xml', 'utf-8')
 #_ast = element.deserialize('a.xml', ast.factory, 'utf-8')
 _ast.post_process()