Fix several bugs to get Python scanner/parser basically working, processes ../tests...
authorNick Downing <nick@ndcode.org>
Tue, 15 Jan 2019 00:29:36 +0000 (11:29 +1100)
committerNick Downing <nick@ndcode.org>
Tue, 15 Jan 2019 00:29:36 +0000 (11:29 +1100)
bootstrap/markup.py
bootstrap/parse.y
bootstrap/scan.l
bootstrap/skel_y_tab.py
bootstrap/state.py

index d55c28b..9c5a8fe 100755 (executable)
@@ -4,7 +4,9 @@ import lex_yy
 import y_tab
 import sys
 
+lex_yy.piece_append('<root><AST ref=\"0\"><AST_Section1>')
 y_tab.yyparse()
 while lex_yy.flexscan():
   pass
+lex_yy.piece_append('</AST></root>\n')
 sys.stdout.write(''.join(lex_yy.piece))
index de0be93..6807a2a 100644 (file)
@@ -325,7 +325,7 @@ scon
       #$$ = scon_stk_ptr
       if yychar == YYEMPTY:
         yychar = lex_yy.flexscan()
-        print('xxx yychar', yychar, 'yylval', yylval, 'yylloc', yylloc, 'lex_yy.yytext', yytext)
+        #print('xxx yychar', yychar, 'yylval', yylval, 'yylloc', yylloc, 'lex_yy.yytext', yytext)
       temp = lex_yy.piece[piece2 + 1]
       lex_yy.piece[piece2 + 1] = lex_yy.piece[piece2]
       lex_yy.piece[piece2] = lex_yy.piece[piece2 - 1]
index 483c815..f937e92 100644 (file)
@@ -960,7 +960,7 @@ M4QEND      "]""]"
      */
   "{"{NAME}"}"[[:space:]]? {
     end_ch = yytext[-1]
-    end_is_ws = end_ch != ord('}')
+    end_is_ws = end_ch != '}'
     state.nmstr = yytext[1:-1 - int(end_is_ws)]
     nmdef = state.ndlookup(state.nmstr)
     if nmdef is None:
index 746c00f..b55e87d 100644 (file)
@@ -43,7 +43,7 @@ yylloc = None
 # GENERATE SECTION2
 
 def yyparse():
-  global yystack, yychar, yyval, yyloc, yylval, yylloc
+  global yystack, yychar, yyval, yyloc, yylval, yylloc, piece2, piece3
 
   # GENERATE INITIALACTION
 
@@ -59,7 +59,7 @@ def yyparse():
         yylval = None
         yylloc = None
         yychar = lex_yy.flexscan()
-        print('yychar', yychar, 'yylval', yylval, 'yylloc', yylloc, 'lex_yy.yytext', lex_yy.yytext)
+        #print('yychar', yychar, 'yylval', yylval, 'yylloc', yylloc, 'lex_yy.yytext', lex_yy.yytext)
       action = yy_lr1dfa_states[state][1][
         bisect.bisect_right(yy_lr1dfa_states[state][0], yychar)
       ]
@@ -81,7 +81,7 @@ def yyparse():
     piece2 = n + 1
     piece3 = n + len_symbols * 2
     if len_symbols == 0:
-      lex_yy.piece[base:base] = ['', '']
+      lex_yy.piece[n:n] = ['', '']
       piece3 = n + 2
       lex_yy.piece0 += 2
     ref_data()
index 88f26ec..eb987a2 100644 (file)
@@ -1,3 +1,5 @@
+import sys
+
 # miscellaneous state accessed by scan.l and parse.y
 in_rule = False
 infilename = '<stdin>'
@@ -18,7 +20,7 @@ def ndlookup(key):
 
 def synerr(str):
   sys.stderr.write(
-    '{0:s}:{1:d}: {1:s}\n'.format(infilename, linenum, str)
+    '{0:s}:{1:d}: {2:s}\n'.format(infilename, linenum, str)
   )
 
 esc = {
@@ -31,7 +33,6 @@ esc = {
   'v': ord('\v')
 }
 def myesc(str):
-  print('myesc @@@{0:s}@@@'.format(str))
   assert str[0] == '\\'
   result = esc.get(str[1])
   if result is None: