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: temp = 2 ( x -

image text in transcribed
Assume the following stream of characters (with whitespace serves as the delimiter) are read in to a C compiler: temp = 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 // 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, 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: temp = 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 // 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, 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

Computer Aided Database Design

Authors: Antonio Albano, Valeria De Antonellis, A. Di Leva

1st Edition

0444877355, 978-0444877352

More Books

Students also viewed these Databases questions