Description
Compiler Lab – UCS 1602
Programming Assignment-5 – Implementation of Desk Calculator using Yacc Tool
Write Lex program to recognize relevant tokens required for the Yacc parser to implement deskcalculator. Write the Grammar for the expression involving the operators namely, + , – ,* , / , ^ , ( , ). Precedence and associativity has to be preserved. Yacc is available as a command in linux. Thegrammar should have non terminals E, Op and a terminal id.
Verify your calculator with the following inputs
i. 3+9
ii. 3+9*6
iii. (3+4)*7 iv. (3-4)+(7*6)
v. 5/7+2
vi. 4^2^1
vii. (2^3)^2
Extend your calculator to evaluate Boolean expressions.
Tips to use tools
• Write Lex specification, compile and execute to check for the tokens, namely, operators and the identifiers.
• Write yacc specification in ex.y and type the command yaccex.y.The output will be y.tab.c
• Compile using the command cc y.tab.c. The output will be a.out
• Use .exe to give input and get the output.




Reviews
There are no reviews yet.