Welcome to Dream.In.Code
Become a Java Expert!

Join 150,163 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,372 people online right now. Registration is fast and FREE... Join Now!




QUESTION

 
Reply to this topicStart new topic

QUESTION

aforadi
3 Aug, 2008 - 07:10 AM
Post #1

New D.I.C Head
*

Joined: 3 Aug, 2008
Posts: 1

Data Structures Assignment 1
Due: Aug 10, 5pm
(Submit at moodle.)

Write an interpreter for the following language. Define and use a Procedure class that stores information about one procedure, i.e., the list of its instructions. The instructions are stored parsed: i.e., as < OPERATION-CODE, OPERANDS > tuple. You may choose any representation for op codes (but make sure that you use no literal constant in any of your methods). You need classes Program Instruction, OpCode and Operand. Classed Program and Procedure should each have the execute method that sequentially executes its Instructions. You will also need a VirtualMachine class (that will have your main program) as well as a Parser class. Make sure you handle exceptions (wrong input programs). The execute method for the PRINT instruction may directly call the JAVA print function.
Syntax
COMMENT string
DEFINEPROC procedurename parametername
SET variablename anothervariablename/value
ENDPROC
CALLIF variablename/value procedurename variablename/value
PRINT variablename

Details
All procedures take one input parameter and return no values
The input parameter can only be an integer (of arbitrary size)
All calls are by value
Recursion is allowed
No global variables
Only integer constants -- but of arbitrary width
Each program must have an entry procedure named "start".
CALLIF calls the function if the first operand is non-zero; the last operand provides the parameter value.
Example Code

COMMENT This is a comment
DEFINEPROC recur level
PRINT level
CALLIF level recur level-1
ENDPROC

DEFINEPROC start
SET call 1
CALLIF call recur 3
ENDPROC


Expected Output

3
2
1
0




i don't want the answer ....i just need help understanding the qn....i hv no clue as to what it means and what it wants me to do..
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: QUESTION
3 Aug, 2008 - 09:01 AM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,660



Thanked: 313 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
Wow, quite the assignment 1. I have seen this style of program before. What they want you to do is create a series of classes/procedures which when fed instructions in a specific format it calls the appropriate procedure to execute the statement.

So for instance, you read in an instruction like PRINT "hello world" it will read in that line, parse it by knowing the first part is a command and the second part is a parameter. It will then say "Hey, this is a print statement, pass the string 'hello world' to the print procedure" where the print procedure will then print the "hello world" to the screen. But keep in mind that they want the parameters only to be integers (which I am not sure why that is but anyways). It will then move on to the next statement and see that it is a SET command and hand off the variable name along with the value to the SET procedure and that procedure will set the variable with the specified value.

It basically chews through each line and delegates the responsibility to various procedures based on the command and the values of the line.

However if you have questions the best place to ask is the instructor. Don't rely on just my interpretation of this. I would be asking questions too just to get the hang of how the instructor wants the program laid out.

smile.gif

This post has been edited by Martyr2: 3 Aug, 2008 - 09:02 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 02:48AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month