Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

Program Assignment -

For this assignment we are expanding on assignment 3.  Now that we have parsed input, we will execute the code.

As a reminder, the language has the following rules:

1. An empty string is a semantic error.

2. The language contains only two types: a string and an integer.

3. The language contains only two statements: a print statement, and a set statement.

4. PRINT means evaluate the expression and printing the result on standard out.

5. SET means evaluate the expression and save the value in the variable named ID

6. It is an error to use a variable that has not been set.

7. The addition and multiplication operators associate left-to-right.

8. Addition is defined only between two integers or two strings. String addition is concatenation.

9. Multiplication is defined between two integers or between an integer and a string. Multiplying a string by an integer X repeats the string X times.

10. The language includes a subscripting operator which may have one or two expressions inside the square bracket, separated by a semicolon. Both expressions must evaluate to integers, which are used as indexes into the string (starting, of course, from zero). A single expression results in a string containing the single character at that position. Two expressions results in a substring beginning at the first position and ending at the character before the second position. If either of the expressions would access a character that is not in the string, this will be deemed a runtime error.

11. All other combination of types and operations are undefined.

For this assignment, after parsing you must perform all semantic checks and execute the program. Please note that some of the checks can be performed statically (an empty string constant is an error, and using a variable before setting it is an error), but some can only be performed at run time.

Failing a static check should print an error message and stop execution. Failing a dynamic check should print the string RUNTIME ERROR followed by a description of the error (for example; RUNTIME ERROR types being added are not permitted).

Observe that doing this assignment involves evaluating the parse tree, which is a recursive operation. Defining a virtual eval() function, with different implementations in different classes, is a useful approach. It's also likely that you will need to define some idea of a Type and a Value for this assignment. The eval() function will likely want to return a Value, and will need to test a Type.  

Your program should read the file whose name is passed as a command line argument, or the standard input if no command line argument is provided. You may divide this assignment into as many files as you like. You MUST use p2lex.h from the last assignment, with no changes. You MUST have your lexical analyzer in a separate file.

Attachment:- Assignment.zip

Computer Engineering, Engineering

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

Have any Question?


Related Questions in Computer Engineering

Why hasnt health care in australia been entirely privatised

Why hasn't health care in Australia been entirely privatised, according to Boxall and Gillespie? Should health care (in Australia) be wholly privatised? Do you think it will be in the future?

A bit-comparator is a combinational circuit with 2 inputs a

A Bit-Comparator is a combinational circuit with 2 inputs, A and B, and 3 outputs. L, E and G. Output L is 1 if A Output E is 1 if A = B, otherwise E is 0. Output G is 1 if A > B, otherwise G is 0. Show how the 2x4 decod ...

Question have you received emails like thesewhat actions if

Question : Have you received emails like these? What actions, if any, have you taken to limit the permissions of the sender? Why or why not? In your chapter reading, you learned about the CAN-SPAM law From your perspecti ...

Question research the security and reliability of apache

Question : Research the security and reliability of Apache Web Server and Microsoft IIS and determine which you consider the best and why you consider it the best. The response must be typed, single spaced, must be in ti ...

Question 1 as part of the disaster recovery planning at a

Question: 1. As part of the disaster recovery planning at a medium-sized business you have been asked to develop a project plan to test the backups of production systems. 2. Develop an outline of the project plan for the ...

Restaurant management database project the restaurant

Restaurant Management Database Project : The restaurant maintains the catalog for the list of food and beverage items that it provides. Apart from providing food facility at their own premises, the restaurant takes order ...

How can word processing software give a person the ability

How can Word Processing software give a person the ability to better position themself or a business, in today's society? Why?

Frontier services has a 2000 pure discount bond that comes

Frontier Services has a $2,000 pure discount bond that comes due in one year. The risk-free rate of return is 4 percent. The firm's assets are expected to be worth either $2,800 or $1,600 in one year. Currently, these as ...

Excel discussionconsider this using the mouse to point and

Excel discussion Consider this.... Using the mouse to point and click is one way to work on a computer. Often, the same work can be accomplished using just the keyboard, using shortcut keyboard combinations. For example, ...

Question you have been recently promoted to lead a new

Question: You have been recently promoted to lead a new division of Company XYZ. This company is known for its team-oriented atmosphere, and your boss has raved about some of your natural leadership qualities. Your first ...

  • 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