Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a function leftA that takes an AST and returns another ASTthat is in left-associative form (likely using recursion). type ast = | Int of
Write a function leftA that takes an AST and returns another ASTthat is in left-associative form (likely using recursion).
type ast = | Int of int | Plus of {op1 ast; op2 ast} where the Parens constructor represents parentheses around an expression. (Parentheses are usually omitted during the act of parsing, but since we are going to change the groupings of operations as part of reassociating, it makes sense to include here.) 1 | Minus of {op1: ast; op2: ast} | Parens of ast In reassoc-src/bin/main.ml you must write a function leftAssociate astast that takes as input an AST and returns a version in which the Plus and Minus operations have been left-associated. For example, on an input tree of the form + + Your code should return the AST corresponding to 1 2 /\ 2 3 3
Step by Step Solution
There are 3 Steps involved in it
Step: 1
let rec leftAssociate ast match ast with Int ast Pl...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started