Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Assume the following stream of characters (with whitespace serves as the delimiter) are read in to a C compiler: te m p = 2 *
Assume the following stream of characters (with whitespace serves as the delimiter) are read in to a C compiler: te m p = 2 * ( x - 100); (a) [2 pts] Show the stream of tokens likely produced by the lexer. (b) [2 pts] Assume the compiler uses an AST representation with standard nodes such as assign, +, -, *, /, etc. Express the input in an AST, in the linear S-expression form. (c) [2 pts] Assume the compiler uses a register-machine IR, which supports the usual basic operations, but limits one operation per instruction (e.g. x = y op z). Express the input in this IR. (d) [4 pts] Assume the compiler also uses a stack-machine IR, which supports the usual basic operations, ADD, SUB, MUL, DIV, plus the following three instructions, each with an explicit operand: PUSH n // push constant n to stack LOAD X // load var x's value to stack STORE X // store top of stack value to var x's storage (Note: for a binary op, the left operand is pushed on to the stack first.) For the given input, assume the two variables, x and temp's indices are 0 and 1, respectively. Express the input in the IR code. Assume the following stream of characters (with whitespace serves as the delimiter) are read in to a C compiler: te m p = 2 * ( x - 100); (a) [2 pts] Show the stream of tokens likely produced by the lexer. (b) [2 pts] Assume the compiler uses an AST representation with standard nodes such as assign, +, -, *, /, etc. Express the input in an AST, in the linear S-expression form. (c) [2 pts] Assume the compiler uses a register-machine IR, which supports the usual basic operations, but limits one operation per instruction (e.g. x = y op z). Express the input in this IR. (d) [4 pts] Assume the compiler also uses a stack-machine IR, which supports the usual basic operations, ADD, SUB, MUL, DIV, plus the following three instructions, each with an explicit operand: PUSH n // push constant n to stack LOAD X // load var x's value to stack STORE X // store top of stack value to var x's storage (Note: for a binary op, the left operand is pushed on to the stack first.) For the given input, assume the two variables, x and temp's indices are 0 and 1, respectively. Express the input in the IR code
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started