Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assume the following stream of characters (with whitespace serves as the delimiter) are read in to a C compiler: tem p = 2 * (

image text in transcribed

Assume the following stream of characters (with whitespace serves as the delimiter) are read in to a C compiler: tem 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: tem 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database Foundations Technology Fundamentals For IT Success

Authors: Bob Bryla

1st Edition

0782143725, 9780782143720

Students also viewed these Databases questions

Question

=+to live and work wherever he or she wants?

Answered: 1 week ago

Question

=+How will this affect the recruiting process?

Answered: 1 week ago