Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

problem 1: Given the production:

S-> aSAb | Ab
A-> bbb
implement a complete pseudo code for a recursive descent parser. Assume scanner ( ) returns the next token.

problem 2: Give all needed first and follow sets needed to check if the grammar is LL(1). Is it?:

S -> aA | BB
A -> aaA | empty
B -> bB | Cd
C -> cA | dC

problem 3: A function returns a number, takes no arguments, and its body is a block. Functions are defined exactly like variables in the grammar except that function name is follow by a block. Show the grammar. Is the resulting grammar LL(1)?

problem 4: A function definition must be before the program token, and functions cannot be nested (exactly like in C). Every function has a return type (no void) and one argument. Function call is like in C, with an expression for the argument and the function call itself is an expression. Show the grammar. exs:

int fun1(long x)
begin
/* same as in any block*/
end;
long fun2(int x)
begin
/** ... */
end;
program xxx(void)
begin
int x;
x=fun1(5+2)*10;
end;

problem 5: Design unambiguous grammar to parse expressions involving +, -, *, / and unary -. Unary minus is strongest, followed by * and /(same precedence, right associative), then +, left associative, then finally -, left associative. Do not use any other operators, and use only number tokens.

problem 6: Assume function f ( ) has local variables a, b, and function g is nested inside of f ( ) and has local variable a. There is also a global variable c.

a) show the complete memory space for the program when it begins execution
b) show the stack after f ( ) is called, which subsequently calls g ( ), which calls itself once.
c) assume we have three statements in g ( )

stat1: c=10;
stat2: a=20;
stat3: b=30;
how would they be translated by the compiler: describe in words.

problem 7: Show the grammar for:

a) Allow global variables placed just before the first begin – these variables are optional and are listed separated by commas. For ex:

program
int x,y,z;
begin {etc.}

b) Also allow functions. Each function takes any number of arguments and always returns an integer. Parameter list is C-like, and the return statement (followed by an expression) is mandatory. Functions can be called in place of any expression. Functions are defined with a block, which is the same as the begin-end block in our grammar. Functions are defined separately, as in C but before the main program. Assume we have a multi-pass compiler so that prototypes is not an issue. The following is an ex program

int sum(int a, b) {paramater list is same as for globals}
begin
int c;
return a+b;
end;
program
int x,y;
begin
readI(x);
readI(y);
z:=10+sum(x,y+1);
prepareI(z);
end.

problem 8: Given the program (like Pascal, with nested functions)

int x, y; {global}
function A
begin
int z; {z is in A}
function B {B is defined inside A}
begin
int x; {x is in B}
function C {C is inside B}
begin
int x; {x is in C}
z:=10:
x:=100;
y:=1000;
C(); {recursive call on C}
end; {end of C}
C();
end; {end of B}
B(); { A calls B}
end; {end of A}

a) show ARs (activation Records) for A, B, C (show only local data, static and dynamic link}
b) What is in the persistent data space?
c) assume call to A() is done somewhere. Then, show that contents of the stack during the 3rd recursive call to C(). Make sure to fill out all info on the stack.
d) How would the left-hand-side variables in C()be translated by the compiler (describe in words, separately for each variable).

problem 9: Given the grammar, with lower case terminals and upper case nonterminals, and S the initial nonterminal

S -> aS | aA | bA
A -> Aa | ABb | cA
B -> bB | bdB | c

a) remove left recursion as needed, showing the modified grammar

b) left-factorize as needed what you get in a), showing the new grammar

c) Is the resulting grammar LL(1)? Argue piece by piece why it is or why it is not, showing all (and only the necessary) First and Follow sets.

problem 10: Assume the following static program structure, show the static chains and display when exactly five ARs are on the stack, assuming procedure A is called first.

proc A
begin /* proc A */
proc B
begin /* proc B */
proc C
begin /* proc C */
call A
end /* proc C */
call C
end /* proc B */
proc D
begin /* proc D */
call B
end /* proc D */
call D
end /* proc A */

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M93892

Have any Question?


Related Questions in Computer Engineering

An exam has 5 multiple choice questions with 2 possible

An exam has 5 multiple choice questions with 2 possible answers each, and 5 true and false questions. Assume each question on the test counts 10 points, and that each question has a unique answer. If a student guesses ea ...

Discuss why a financial services organization would benefit

Discuss why a financial services organization would benefit from using one framework over another (COSO, COBIT,) -- choose a framework or frameworks that in your opinion would be most ideally suited for such an organizat ...

What is unified threat management utm and the services it

What is Unified Threat Management (UTM) and the services it combines into one device. Does UTM holds true to the principle of defense-in-depth

What are the assumptions of linear regression analysis and

What are the assumptions of linear regression analysis and ,How do we interpret the regression coefficients ,can u give a real life example of how linear regression is used in statistical research

Question task a based on the case above as well as your own

Question: Task A: Based on the Case Above as well as your Own Research on IT Service Delivery, answer the following questions: 1) What were the key reasons for the IT implementation failure? 2) In your view, who is respo ...

Annual demand and supply for the mylan company is given

Annual demand and supply for the Mylan company is given by: QD = 5,000 + 0.5 I + 0.2 A - 100P, and QS = -5000 + 100P where Q is the quantity per year, P is price, I is income per household, and A is advertising expenditu ...

An article in the wall street journal noted that an

An article in The Wall Street Journal noted that an" increase in the price of crude oil quickly reduces demand for oil". Do you agree with this statement? Briefly explain.

A major airline company is concerned that its proportion of

A major airline company is concerned that it's proportion of late arrivals has substantially increased in the past month. Historical data shows that on the average 18% of the company airplanes have arrived late. And a ra ...

Technology certainly does play a large role in our lives

Technology certainly does play a large role in our lives and this has happened in a very short period of time. It has impacted the way we activities professionally, personally, and academically. For example, online educa ...

Respond to the statement below in at least 100 words

Respond to the statement below in at least 100 words. Original answers only. If developers are making decisions on the requirements, then how do they know that the software will work properly for the end user? Developers ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As