Print parsed string tree

master
Yury Kurlykov 2020-04-15 16:32:57 +10:00
parent 812f5107c3
commit 8b88405fc5
Signed by: t1meshift
GPG Key ID: B133F3167ABF94D8
1 changed files with 8 additions and 2 deletions

View File

@ -44,13 +44,19 @@ def main():
print() print()
input_stream = InputStream('"use strict";var a;\na=2+a;') input_stream = InputStream("var a;\n{a=2+a;}")
lexer = JSL(input_stream) lexer = JSL(input_stream)
stream = CommonTokenStream(lexer) stream = CommonTokenStream(lexer)
stream.fill()
for token in stream.tokens:
print("Token: {}".format(str(token)))
parser = JSP(stream) parser = JSP(stream)
print("Created parsers") print("Created parsers")
tree = parser.program() tree = parser.program()
ParseTreeWalker.DEFAULT.walk(WriteTreeListener(), tree) print(tree.toStringTree(parser.ruleNames))
# ParseTreeWalker.DEFAULT.walk(WriteTreeListener(), tree)
if __name__ == "__main__": if __name__ == "__main__":