def test_issue_16(): parser = ParserPEG(grammar, "calc", skipws=False) input_expr = """public function __construct( )""" parse_tree = parser.parse(input_expr) # Do semantic analysis. Do not use default actions. asg = parser.getASG(sem_actions=sem_actions, defaults=False) assert asg
def main(debug=False): # First we will make a parser - an instance of the calc parser model. # Parser model is given in the form of PEG notation therefore we # are using ParserPEG class. Root rule name (parsing expression) is "calc". parser = ParserPEG(calc_grammar, "calc", debug=debug) # An expression we want to evaluate input_expr = "-(4-1)*5+(2+4.67)+5.89/(.2+7)" # Then parse tree is created out of the input_expr expression. parse_tree = parser.parse(input_expr) result = parser.getASG(sem_actions) # getASG will start semantic analysis. # In this case semantic analysis will evaluate expression and # returned value will be evaluated result of the input_expr expression. # Semantic actions are supplied to the getASG function. print("{} = {}".format(input_expr, result))
def main(debug=False): # First we will make a parser - an instance of the calc parser model. # Parser model is given in the form of PEG notation therefore we # are using ParserPEG class. Root rule name (parsing expression) is "calc". parser = ParserPEG(calc_grammar, "calc", True) # An expression we want to evaluate input_expr = "-(4-1)*5+(2+4.67)+5.89/(.2+7)" # Then parse tree is created out of the input_expr expression. parse_tree = parser.parse(input_expr) result = parser.getASG(sem_actions) if debug: # getASG will start semantic analysis. # In this case semantic analysis will evaluate expression and # returned value will be evaluated result of the input_expr expression. # Semantic actions are supplied to the getASG function. print("{} = {}".format(input_expr, result))