from __future__ import print_function
import sys, shlex, operator
tk_EOI, tk_Mul, tk_Div, tk_Mod, tk_Add, tk_Sub, tk_Negate, tk_Not, tk_Lss, tk_Leq, tk_Gtr, \
tk_Geq, tk_Eql, tk_Neq, tk_Assign, tk_And, tk_Or, tk_If, tk_Else, tk_While, tk_Print, \
tk_Putc, tk_Lparen, tk_Rparen, tk_Lbrace, tk_Rbrace, tk_Semi, tk_Comma, tk_Ident, \
tk_Integer, tk_String = range(31)
nd_Ident, nd_String, nd_Integer, nd_Sequence, nd_If, nd_Prtc, nd_Prts, nd_Prti, nd_While, \
nd_Assign, nd_Negate, nd_Not, nd_Mul, nd_Div, nd_Mod, nd_Add, nd_Sub, nd_Lss, nd_Leq, \
nd_Gtr, nd_Geq, nd_Eql, nd_Neq, nd_And, nd_Or = range(25)
# must have same order as above
Tokens = [
["EOI" , False, False, False, -1, -1 ],
["*" , False, True, False, 13, nd_Mul ],
["/" , False, True, False, 13, nd_Div ],
["%" , False, True, False, 13, nd_Mod ],
["+" , False, True, False, 12, nd_Add ],
["-" , False, True, False, 12, nd_Sub ],
["-" , False, False, True, 14, nd_Negate ],
["!" , False, False, True, 14, nd_Not ],
["<" , False, True, False, 10, nd_Lss ],
["<=" , False, True, False, 10, nd_Leq ],
[">" , False, True, False, 10, nd_Gtr ],
[">=" , False, True, False, 10, nd_Geq ],
["==" , False, True, False, 9, nd_Eql ],
["!=" , False, True, False, 9, nd_Neq ],
["=" , False, False, False, -1, nd_Assign ],
["&&" , False,
语法分析器(syntax analyzer)【Python实现】
于 2020-03-10 10:44:12 首次发布