Week – 5 Exercises Solution

$35.00 $29.00

1. Consider the below expression n = n>6+3 || !2+3 || n = !c.n*!3 || 1+3==4 A correct declaration of precedence directives (%left, %nonassoc, %right) in this assignment will help produce these groupings. Notice, for instance, that the DOT operator has the highest precedence, while the (right-associative) ASSIGN operator has the lowest precedence. The (left-associative)…

5/5 – (2 votes)

You’ll get a: zip file solution

 

Description

5/5 – (2 votes)

1. Consider the below expression

n = n>6+3 || !2+3 || n = !c.n*!3 || 1+3==4

A correct declaration of precedence directives (%left, %nonassoc, %right) in this assignment will help produce these groupings. Notice, for instance, that the DOT operator has the highest precedence, while the (right-associative) ASSIGN operator has the lowest precedence. The (left-associative) PLUS and MINUS operators should have equal precedences. The (non-associative) EQUALITY and GREATER operators should also have equal precedences, though their precedences differ from those of PLUS and MINUS. Although the NOT operator is unary (i.e., only has one operand), you can declare it to be right associative for the sake of ordering its precedence.

  1. Write a CFG for the above expression.

  1. Implement Lex and Yacc program to recognize the above expression using the CFG written in (a). You should transform your grammar, as necessary, to eliminate conflicts. The output should represent whether the expression is valid or invalid for the given CFG.

2. Imagine the syntax of a programming language construct such as while-loop

while (condition)

begin

statement;

end

where while, begin, end are keywords; condition can be a single comparison expression (such as x == 20, etc.); and statement is the assignment to a location the result of a single arithmetic operation (e.g., a = 10 * b).

  1. Write a CFG for the above construct.

  1. Implement Lex and Yacc program to recognize the above expression using the CFG written in (a). You should transform your grammar, as necessary, to eliminate conflicts. The output should represent whether the testcase is valid or invalid for the given CFG.

Upload the following files in moodle.

  1. CFG and Code for both problems.

  1. 1 Testcase with error and 1 Testcase without error for 2nd problem.

  1. Output

Note: Outputs in the form of screenshots alone will be considered for evaluation.

Week – 5 Exercises Solution
$35.00 $29.00