need help!! - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

need help!!

positivecrappositivecrap Posts: 1Member
this is a question with which i really need help with. so plz help!! i'm just a beginner!!!!


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 ProgramInstruction, 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
Sign In or Register to comment.