Solved–Assignment 02– Solution

$30.00 $19.00

Write a function convert_grammar gram1 that returns a Homework 2-style grammar, which is converted from the Homework 1-style grammar gram1. Write a function parse_tree_leaves tree that traverses the parse tree tree left to right and yields a list of the leaves encountered. Write a function make_matcher gram that returns a matcher for the grammar gram.…

You’ll get a: . zip file solution

 

 

Description

5/5 – (2 votes)

Write a function convert_grammar gram1 that returns a Homework 2-style grammar, which is converted from the Homework 1-style grammar gram1.

Write a function parse_tree_leaves tree that traverses the parse tree tree left to right and yields a list of the leaves encountered.

Write a function make_matcher gram that returns a matcher for the grammar gram. When applied to an acceptor accept and a fragment frag, the matcher must try the grammar rules in order and return the result of calling accept on the suffix corresponding to the first acceptable matching prefix of frag; this is not necessarily the shortest or the longest acceptable match. A match is considered to be acceptable if accept succeeds when given the suffix fragment that immediately follows the matching prefix. When this happens, the matcher returns whatever the acceptor returned. If no acceptable match is found, the matcher returns None.