Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Question

  1. #1
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    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

    COULD ANYONE EXPLAIN ME THE PROBLEM FIRST? I HAVE NO CLUE AT ALL.

  • #2
    Regular Coder ralph l mayo's Avatar
    Join Date
    Nov 2005
    Posts
    951
    Thanks
    1
    Thanked 31 Times in 29 Posts
    Congratulations on coming up with the worst thread title I've ever seen here, and with some very stiff competition too.

    If you don't understand this question you should probably just drop the class. You are expected to produce a Java program that compiles this limited grammar to some arbitrary instruction set, and write a (presumably also Java) virtual machine that interprets and executes the instruction set.

  • #3
    Regular Coder borntoslow's Avatar
    Join Date
    Aug 2008
    Location
    192.168.0.2
    Posts
    137
    Thanks
    2
    Thanked 9 Times in 9 Posts
    hahaha ralph, best reply to a post i have ever seen.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •