Question 1: Write a Yacc program that takes boolean expressions as input and produces the truth value of the expressions. The following grammar for boolean expressions:
bexpr → bexpr or bterm | bterm
bterm → bterm and bfactor | bfactor
bfactor→ not bfactor|( bexpr ) | true | false
Parse tree for the sentence:
Grammar generates all boolean expressions,
bexpr => bterm => bfactor => not bfactor => not (bexpr) => not (bexpr or bterm)
=> not (bterm or bterm) => not (bfactor or bfactor) => not (true or false)
By traversing the tree, the tree generated will lead to bfactor which will generates all boolean expression.
bexpr=> bterm=> bfactor=> true
bexpr=> bterm=> bfactor=>false
bexpr=> bterm=> bfactor=> not bfactor=> not true
bexpr=> bterm=> bfactor=> not bfactor=> not false
bexpr=> bexpr or bterm=> bterm or bterm=> bfactor or bfactor=> true or false
bexpr=> bexpr and bterm=> bterm and bterm=> bfactor and bfactor=> true and false
bexpr => bterm => bfactor => not bfactor => not (bexpr) => not (bexpr or bterm)
=> not (bterm or bterm) => not (bfactor or bfactor) => not (true or false)
Yacc program that takes boolean expressions as input and produces the truth value of the expressions:
test.l %{ #include "y.tab.h" %} AND [Aa][Nn][Dd] OR [Oo][Rr] NOT [Nn][Oo][Tt] op '&' | '|' | "!" %% [a-zA-Z] {return ALPHA;} [\t]+ ; [\n] {return '\n';} {AND} { return (AND); } {OR} { return (OR); } {NOT} { return (NOT); } [Tt][Rr][Uu][Ee] { yylval = 1; return (boolean); } [Ff][Aa][Ll][Ss][Ee] { yylval = 0; return (boolean); } . {();} %%
test.y %{ #include<stdio.h> #include<stdlib.h> int yylex(); %} %token ALPHA AND OR NOT TRUE FALSE boolean %left "&" "|" %right '!' %% program: bexpr '\n' {if ($1 >= 1) { printf("TRUE\n"); exit(0); } else{ printf("FALSE\n"); exit(0); } | ; bexpr: bexpr "|""|" bterm { $$ = $1 || $3; } | bterm { $$ = $1; } ; bterm: bterm "&""&" bfactor { $$ = $1 && $3; } | bfactor { $$ = $1; } ; bfactor: '!' bfactor { $$ = ! $2; } | '(' bexpr ')' { $$ = $2; } | TRUE { $$ = $1; } | FALSE {$$ = $1; } | boolean { $$ = $1; } ; %% int main() { printf("Enter your truth statement\n"); yyparse(); return 0; }
Question 1: Write a Yacc program that takes boolean expressions as input and produces the truth...
R327 Complete the following truth table by finding the truth values of the Boolean expressions for all combinations of the Boolean inputs p, q, and . · false false false false false true false true false 5 more combinations
A truth table can be implemented with different boolean expressions and different circuits True False Question 5 (2 points) The boolean expression "not x or y" is equivalent to the boolean expression "x or not Y" True False Question 6 (2 points) The boolean expression (x or y) and x is equivalent to the boolean expression (x and y) ory True False
C++ Write a program that takes an infix expression as an input and produces a postfix expression. Use stack to convert an infix expression into postfix expression. Include a function that evaluates a postfix expression.
QUESTION 2 Boolean or "truth-valued" expressions are how we express conditions that control choices and repetition in computer languages. Consider the following Python Boolean expression, where variables alpha, beta, and gamma are of type Boolean: alpha and (beta or gamma) In any algebraic notation there are usually several different ways of writing the same expression. For instance, in integer arithmetic the value of expression '4 x (5 + 2)' is numerically equivalent to that of expression '(4 x 5) +...
Problem 1: Complete this truth Table. Write a program that you can enter from the keyboard,a 1 or 0 into three Boolean variables, A,B,C. Write an if statement that tests the condition ( (A or B ) and C ). Run the program 8 separate times, testing each of the following 8 combinations. Write the results below in the following truth table: Problem 1-Complete this truth Table. Write a program that you can enter from the keyboard, a 1 or...
Use Boolean Algebra to simplify the following Boolean expressions to three (3) literals. Please write down the intermediate steps. 1). F11(x,y,z) = x'yz+xyz +x'y'Z+xy'Z+ xy'z 2). F12(x,y,z) = (y'+xyz')' Question 2 [2 points) Obtain the function expression of F2 from the logic diagram. Question 3 [3 points) Obtain the truth table of the following function and rewrite the function in Canonical POS (Product of Maxterms) format: F3(a,b,c) = (a'+c)(a+b+c') +a'bc' Question 4 (2 points) Convert the following function to Canonical...
Write a C++ program that reads string expressions from an input file "prefix.txt" containing prefix expressions (one expression per input line). For each prefix expression read from the input file, the program should: (1) convert the expression to a fully parenthesized infix expression and (2) find the value of the expression. Use a stack to solve the problem. Assume the expressions contain only integer numbers and the *,/, +, - operators. Generate the results in an output file "results.txt" in...
Given a boolean variable a, are the following expressions equivalent? !( !a ) a 1) No answer text provided. 2) true 3) false 4) No answer text provided.
a) Generate the truth table for the following Boolean expressions and display it in the MATLAB command window (Use logical functions: and, not, or) X (A. B) (C. D) Y-ACD b) Solve the following questions and hence to verify your calculated result. (You may use bi2de, de2bi, hex2dec and dec2hex) i Convert the binary number 10011011into decimal ii) Convert the decimal number 137 into binary Convert the hexadecimal number A4C3 into decimal iv) Convert the decimal number 52710 into hexadecimal.
1. Write a program that takes a number as input and check whether the number is positive, negative or zero. 2. Write a C++ program that prompts the user to enter a number and checks whether the entered number is even or odd. 3. Using switch-case statement write a C++ program that prompts the user to enter 1, 2 or 3 and display "Red" if selection is 1, "Yellow" if selection is 2, or "Green" if selection is 3. 4. Write...