Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

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.

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

Slides on the topic

image text in transcribed

Precedence and associativity For two arbitrary infix operators,and Ifa has higher precedence than , then "ab c" parses as "(ab) c" Ifa is left-associative, then "abc" parses as "(ab)c" -If s is right-associative, then "abc" parses as "a(bc)" -Ifa is non-associative, then "abc" is a syntax error Fixity = precedence + associativity

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Informix Database Administrators Survival Guide

Authors: Joe Lumbley

1st Edition

0131243144, 978-0131243149

More Books

Students also viewed these Databases questions