Answered step by step
Verified Expert Solution
Link Copied!

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).

image

image

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... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions

Question

1. Check readers and library books. Is there ethnic diversity?

Answered: 1 week ago