@@ -59,7 +59,6 @@ def main(): | |||||
print(calc(s)) | print(calc(s)) | ||||
def test(): | def test(): | ||||
# print calc("a=(1+2)") | |||||
print(calc("a = 1+2")) | print(calc("a = 1+2")) | ||||
print(calc("1+a*-3")) | print(calc("1+a*-3")) | ||||
@@ -3,7 +3,7 @@ | |||||
# | # | ||||
# The tokens NAME and VALUE match the same input. A regular lexer would arbitrarily | # The tokens NAME and VALUE match the same input. A regular lexer would arbitrarily | ||||
# choose one over the other, which would lead to a (confusing) parse error. | # choose one over the other, which would lead to a (confusing) parse error. | ||||
# However, due to the unambiguous structure of the grammar, the LALR(1) algorithm knows | |||||
# However, due to the unambiguous structure of the grammar, the LALR(1) algorithm knows | |||||
# which one of them to expect at each point during the parse. | # which one of them to expect at each point during the parse. | ||||
# The lexer then only matches the tokens that the parser expects. | # The lexer then only matches the tokens that the parser expects. | ||||
# The result is a correct parse, something that is impossible with a regular lexer. | # The result is a correct parse, something that is impossible with a regular lexer. | ||||
@@ -2,6 +2,7 @@ | |||||
# This example shows how to write a basic JSON parser | # This example shows how to write a basic JSON parser | ||||
# | # | ||||
# The code is short and clear, but has good performance. | # The code is short and clear, but has good performance. | ||||
# For an explanation, check out the JSON parser tutorial at /docs/json_tutorial.md | |||||
# | # | ||||
import sys | import sys | ||||
@@ -1,3 +1,10 @@ | |||||
# | |||||
# This example demonstrates an experimental feature: Text reconstruction | |||||
# The Reconstructor takes a parse tree (already filtered from punctuation, of course), | |||||
# and reconstructs it into correct text, that can be parsed correctly. | |||||
# It can be useful for creating "hooks" to alter data before handing it to other parsers. You can also use it to generate samples from scratch. | |||||
# | |||||
import json | import json | ||||
from .json_parser import json_grammar | from .json_parser import json_grammar | ||||