Please I need help with this assignment In this assignment, you will use top-dow
ID: 3862811 • Letter: P
Question
Please I need help with this assignment In this assignment, you will use top-down parsing rather than bottom-up parsing (as implemented using YACC).Consider Boolean expressions, with the following operations: and, or, and not (standard associativity and precedence), brackets are allowed. If below you are asked to "write ...", then you have to include the required description as a part of your documentation. If you are asked to "implement...", then you have to write a program.
Part 1. Write an S-attributed syntax directed translation for Boolean expressions with the following tokens:
true, false, and brackets, which can be used to evaluate these expressions. Note: carefully study examples from the textbook of S-attributed syntax directed translations for arithmetic expressions, to learn how to design them to express correct precedence and associativity rules.
Then, write an L-attributed translation resulting from removing left recursion. Note: carefully study examples from the textbook showing how left-recursive S-attributed translations can be converted to L-attributed translations.
Finally, implement a lexical analyzer (use Lex or write it by hand) and a recursive-descent translator based on the above translation.
Examples:
true and not false
not false or (false and not false and true or false)
are both correct, and evaluate to true, but
1 and true
is invalid.
Please I need help with this assignment In this assignment, you will use top-down parsing rather than bottom-up parsing (as implemented using YACC).
Consider Boolean expressions, with the following operations: and, or, and not (standard associativity and precedence), brackets are allowed. If below you are asked to "write ...", then you have to include the required description as a part of your documentation. If you are asked to "implement...", then you have to write a program.
Part 1. Write an S-attributed syntax directed translation for Boolean expressions with the following tokens:
true, false, and brackets, which can be used to evaluate these expressions. Note: carefully study examples from the textbook of S-attributed syntax directed translations for arithmetic expressions, to learn how to design them to express correct precedence and associativity rules.
Then, write an L-attributed translation resulting from removing left recursion. Note: carefully study examples from the textbook showing how left-recursive S-attributed translations can be converted to L-attributed translations.
Finally, implement a lexical analyzer (use Lex or write it by hand) and a recursive-descent translator based on the above translation.
Examples:
true and not false
not false or (false and not false and true or false)
are both correct, and evaluate to true, but
1 and true
is invalid.
Please I need help with this assignment
Explanation / Answer
Part1
S -> T n
T -> T F T
T -> E
F -> and
F -> or
E -> (T)
E -> L
L -> not true
L -> not false
L -> true
L -> false