--[[ Imperative Core Language Prefix Parser Test Script H. Conrad Cunningham, Professor Computer and Information Science University of Mississippi Developed for CSci 450/503, Organization of Programming Languaages, Fall 2016 1234567890123456789012345678901234567890123456789012345678901234567890 2016-09-22: Imperative Core Language parser test script developed from partial test script for Expression Language 1 prefix parser --]] -- Set module "parameters" UTILITIES = "utilities" PARSER = "parser_prefix_core" -- ImpCore ABS_SYNTAX = "abs_syn_core" -- ImpCore VALUES = "values_01" -- Import Utilities module local util = require(UTILITIES) local show_data, treeConcat = util.show_data, util.treeConcat -- printTree not currently used -- Import Parser module local par = require(PARSER) local parse = par.parse -- PARTIAL TESTING print( "\nLIMITIED TESTING OF PREFIX PARSER FOR EXPRESSION LANGUAGE 1.\n") local varx = "x" print("input: " .. varx) print("output: " .. treeConcat(parse(varx))) local varxyz = " xyz_1 " print("input: " .. varxyz) print("output: " .. treeConcat(parse(varxyz))) local int370 = "370" print("input: " .. int370) print("output: " .. treeConcat(parse(int370))) local int37 = " 37 " print("input: " .. int37) print("output: ".. treeConcat(parse(int37))) local neg99 = " -99 " print("input: " .. neg99) print("output: ".. treeConcat(parse(neg99))) local negx = "-x" print("input: " .. negx) print("output: " .. treeConcat(parse(negx))) local negy = " - y " print("input: " .. negy) print("output: " .. treeConcat(parse(negy))) local negate99 = "(neg 99)" print("input: " .. negate99) print("output: " .. treeConcat(parse(negate99))) local term2 = "(+ a 24)" print("input: " .. term2) print("output: " .. treeConcat(parse(term2))) local term3 = "(- (+ a 24) x_yz)" print("input: " .. term3) print("output: " .. treeConcat(parse(term3))) local factor2 = "(* a 24) " print("input: " .. factor2) print("output: " .. treeConcat(parse(factor2))) local factor3 = "(/ (* a 24) xyz)" print("input: " .. factor3) print("output: " .. treeConcat(parse(factor3))) local mix1 = "(+ 2 (* 3 (* 4 6)))" print("input: " .. mix1) print("output: " .. treeConcat(parse(mix1))) local mix2 = " (+ (* xx 2) (* 3 (- y z)))" print("input: " .. mix2) print("output: " .. treeConcat(parse(mix2))) local eq1 = "(== abc 34)" print("input: " .. eq1) print("output: " .. treeConcat(parse(eq1))) local eq2 = "(== (+ x (* 3 y)) (- 34 1))" print("input: " .. eq2) print("output: " .. treeConcat(parse(eq2))) local if1 = "(if (< a 3) (+ x 1) (- 3 2))" print("input: " .. if1) print("output: " .. treeConcat(parse(if1))) local if2 = "(if (<= a 3) (+ x 1) (if (>= x 7) 3 x))" print("input: " .. if2) print("output: " .. treeConcat(parse(if2))) local negex1 = "(neg (+ x 3))" print("input: " .. negex1) print("output: " .. treeConcat(parse(negex1))) local as1 = "(:= x (+ 1 3))" print("input: " .. as1) print("output: " .. treeConcat(parse(as1))) local wh1 = "(while (< x 2) (:= x (+ x 1)))" print("input: " .. wh1) print("output: " .. treeConcat(parse(wh1))) local wr1 = "(write (+ x 1))" print("input: " .. wr1) print("output: " .. treeConcat(parse(wr1))) local bl0 = "( block )" print("input: " .. bl0) print("output: " .. treeConcat(parse(bl0))) local bl1 = "( block 1 )" print("input: " .. bl1) print("output: " .. treeConcat(parse(bl1))) local bl2 = "( block 1 2)" print("input: " .. bl2) print("output: " .. treeConcat(parse(bl2))) local bl3 = "(block 1 2 3)" print("input: " .. bl3) print("output: " .. treeConcat(parse(bl3)))