==================================== CPW Pt. 9: Calculator with Variables [TOC] ==================================== ---- VIDEO ------------------------------ https://www.youtube.com/embed/X-Q12rYrg_w ----------------------------------------- Quiz 23: Calculator with Variables ================================== Reorganize the source files as shown in the video (create a separate header an source file for the parser). Extend the calculator so that it supports calculations with variables. The grammar for the calculator should be ---- LATEX --------------------------------------------------------------------- \begin{array}{rcl} \text{input-sequence} & = & \{\; \text{expr-statement}\; \}\; \texttt{EOI} \\ \text{expr-statement} & = & \text{assignment-expr}\; \texttt{;}\; \\ \text{assignment-expr} & = & \text{expr}\; [\; \texttt{=}\; \text{assignment-expr}\; ]\; \\ \text{expr} & = & \text{term}\; \{\; (\; \texttt{"+"}\; |\; \texttt{"-"}\; )\; \text{term} \} \\ \text{term} & = & \text{power-expr}\; \{\; (\; \texttt{"*"}\; |\; \texttt{"/"}\; )\; \text{power-expr} \} \\ \text{power-expr} & = & \text{unary-expr}\; [\; \texttt{"^"}\; \text{power-expr} ]\; \\ \text{unary-expr} & = & \text{factor}\; |\; (\; \texttt{"+"}\; |\; \texttt{"-"}\;)\; \text{unary-expr} \\ \text{factor} & = & \text{identifier}\; \\ & | & \text{dec-literal}\; \\ & | & \text{hex-literal}\; \\ & | & \text{oct-literal}\; \\ & | & \texttt{"("}\; \text{assignment-expr}\; \texttt{")"}\; \\ \end{array} -------------------------------------------------------------------------------- Note that for the assignment expressions actually an optional group is sufficient! As L-values only identifiers are allows. Undeclared identifiers are always accepted and have value 0. Submit your program with ---- CODE (type=txt) ----------------------------------------------------------------------------------------------------------------------- submit hpc quiz23 xtest_calc.c parser.h parser.c expr.h expr.c str.h str.c sym.h sym.c ustr.h ustr.c lexer.h lexer.c tokenkind.h tokenkind.c --------------------------------------------------------------------------------------------------------------------------------------------