-- This procedure is used to test the recursive descent -- parse of Assignment 3, CS 152, Fall 2000. with TEXT_IO; use TEXT_IO; with a3; use a3; --------------------------------------------------------------------- -- This program implements and tests a recursive descent parser for a -- language defined by a grammar given below. The parse tree -- constructor takes as its argument the name of a text file. It -- attempts to parse the text as a program in the language generated -- by the grammar. If the parse is successful, an appropriate parse -- tree is constructed. Otherwise a dummy parse tree is built and -- an appropriate error message is printed. -- The function "traverse" simply prints the tree if it is not a dummy. -- Otherwise it prints an error message. -- The function "yield" prints the sequence of the tokens in the leaves -- of a parse tree (from left to right). This should be the list of -- tokens in the string that was parsed. -- The "main" function simply tests the functions by calling it with -- a number of different text files. Each file is expected to be in -- the current directory. ---------------------------------------------------------------------- -- The grammar for the language is given below. Here nonterminals are -- capitalized. The grammar has been expanded so that in each rule, -- only tokens appear on the RHS of the arrow. -- The start symbol is "Conditional". -- Conditional -> ShortIf RestIf -- ShortIf -> if Test then Block -- RestIf -> else Block endif -- RestIf -> endif -- Test -> < Var Op Var> -- Var -> x -- Var -> y -- Var -> z -- Op -> = -- Op -> /= -- Block -> begin RestBlock -- RestBlock -> end -- RestBlock -> Statement Statements -- Statements -> end -- Statements -> Statement Statements -- Statement -> Var := Var procedure a3test is t:parse_tree_ptr; begin t:=parse("data1.txt"); traverse(t); new_line; display_yield(t); new_line; t:=parse("data2.txt"); traverse(t); new_line; display_yield(t); new_line; t:=parse("data3.txt"); traverse(t); new_line; display_yield(t); new_line; t:=parse("data4.txt"); traverse(t); new_line; display_yield(t); new_line; t:=parse("data5.txt"); traverse(t); new_line; display_yield(t); new_line; t:=parse("data6.txt"); traverse(t); new_line; display_yield(t); new_line; t:=parse("data7.txt"); traverse(t); new_line; display_yield(t); new_line; t:=parse("data8.txt"); traverse(t); new_line; display_yield(t); new_line; t:=parse("data9.txt"); traverse(t); new_line; display_yield(t); new_line; t:=parse("data10.txt"); traverse(t); new_line; display_yield(t); new_line; t:=parse("data11.txt"); traverse(t); new_line; display_yield(t); new_line; t:=parse("data12.txt"); traverse(t); new_line; display_yield(t); new_line; t:=parse("data13.txt"); traverse(t); new_line; display_yield(t); new_line; t:=parse("data14.txt"); traverse(t); new_line; display_yield(t); new_line; t:=parse("data15.txt"); traverse(t); new_line; display_yield(t); new_line; t:=parse("data16.txt"); traverse(t); new_line; display_yield(t); new_line; t:=parse("data17.txt"); traverse(t); new_line; display_yield(t); new_line; t:=parse("data18.txt"); traverse(t); new_line; display_yield(t); new_line; end a3test;