Question: 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

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

1 Expert Approved Answer
Step: 1 Unlock

let rec leftAssociate ast match ast with Int ast Pl... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!