Question
For each of the following, give a fixity (precedence and associativity) for the infix operators in the string so that the string would parse as
For each of the following, give a fixity (precedence and associativity) for the infix operators in the string so that the string would parse as intended, or give a reason why it's impossible. Assume anything that isn't a letter or a parenthesis is a binary operator.
For example, if we wanted the string "A * B * C + D + E" to parse as "((A * (B * C)) + D) + E", we could give the operators the following fixities: + is left-associative with precedence 1 * is right-associative with precedence 2
However, the string "A + B + C + D" can't possibly parse as "(A + B) + (C + D)", because the + operator must be left-associative, right-associative, or non-associative, and none of those associativity choices choice will produce that parenthesization.
Keep in mind that we're only dealing with syntax here - the meanings of the operators are completely irrelevant!
In most cases there will be multiple valid answers, but you only have to give one.
a) "A * B + C * D" parses as "(A * B) + (C * D)" b) "A & B ^ C | D | E" parses as "(A & (B ^ C)) | (D | E)" c) "A % B @ C = D % E @ F" parses as "((A % B) @ C) = (D % (E @ F))" d) "A + B * C = A * B + A * C" parses as "((A + B) * C) = ((A * (B + A)) * C)"
Please be as clear as possible.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
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