/** * * Author: Joanne Louise Carter * Date: 08/06/05 * Module: G6DOOS Object Oriented Systems * Title: Coursework 2 * SCSiT Username: jxc04m * */ _________________________________________ | | | J I M M | | J I M M M M + + | | J I M M M +++++ +++++ | | J J I M M + + | | JJ I M M | |_________________________________________| What is JIM++? -------------- JIM++ is a code interpreter. It will take a .jpp file and output its result. Running the Program ------------------- You will need a .jpp file, there are several example files provided in the /test_files/ folder. To run the program you will need to type jim++ followed by the files you want to interpret; e.g: jim++ test_files/test.jpp You can interpret as many files as you like at one time, e.g: jim++ test_files/test.jpp test_files/test6.jpp How to Code in JIM++ -------------------- Please note that all commands are case sensitive. Please make sure your syntax is correct else you will get errors. Comments: --------- Any line that starts with a # will be ignored by the interpreter NB: The interpreter also ignores any blank lines in your code, so please be aware that this will affect the line numbers for error messages. Example: # This is a comment Printing: --------- FIRE and FIRELN will allow you to print text or variables. They are identical commands, apart from the fact that FIRELN will start a new line. NB: Any text must be surrounded by "quotemarks" Example: FIRE "Hello World" FIRELN x Ending a program: ----------------- The command NUKE signals the end of your program, and will cause the interpreter to ignore any lines of code that occur after the command. Pausing the program: -------------------- The STUN command pauses the program for a number of milliseconds. This can be specified by a number, or by a number variable. NB: 1 second = 1000 milliseconds Example: STUN 5000 STUN y Variables: ---------- There are three types of variables: SIMPLE, DECIMAL and TEXT. SIMPLE variables are whole numbers, DECIMALs are decimal numbers and TEXT is a string of text. When you declare a variable you merely give it a name, and set its value to 0. You can then assign it a value with the command FORCE, which is explained later on. NB: Variable names must begin with A-Z or a-z and are case sensitive. Example: SIMPLE x DECIMAL y TEXT c Assigning a value to a variable: -------------------------------- FORCE can be used to assign a value to a variable. Please make sure you assign the correct type, else you will receive an error message. NB: Make sure that text is surrounded by "quotemarks". Example: FORCE myNumber=5 FORCE myText="Hello World" Calculations: ------------- Calculations can be performed using ENGAGE. The permitted operators are * (multiply), / (divide), + (add) and - (subtract). NB: Calculations can only be performed upon variables of the same type. Calculations cannot be performed with TEXT variables. Example: ENGAGE number=number*3 ENGAGE number=number1+number2 ENGAGE number=number/2 Jumping: -------- You can jump from one point in the program to another point through the use of LABEL and TELEPORT. LABEL is used to define the point you wish to jump to, and TELEPORT tells the program to jump to that point. Note that the LABEL must be after the TELEPORT command else you will get stuck in a loop. NB: LABEL names are case sensitive. Example: TELEPORT Point1 LABEL Point1 Conditionals: ------------- CHECK and CHECKFAIL allow you to process a command only if a certain condition is satisfied. The operators you can use to compare variables and values are == (equals), != (doesn't equal), < (less than), > (greater than). The first argument of the condition MUST be a variable, and please note you can only compare variables of the same type. If the condition is not true then the CHECKFAIL statement is performed. Only one statement can follow CHECK or CHECKFAIL. Example: CHECK (number>5) FIRELN "number is more than 5" CHECKFAIL FIRELN "number is less than 6" Looping: -------- Looping has only been partially implemented; it is currently only a very simple loop. It will allow you to print out a statement a number of times; however, you cannot perform calculations within a loop at this time. If you do not put an ENDLOOP statement in, then the program will not loop. You can use a number or a SIMPLE variable for the number of times it will loop. NB: Loop names are case sensitive. Example: LOOP Loop1 (5 TIMES) // statements ENDLOOP Loop1 LOOP Loop1 (number TIMES) // statements ENDLOOP Loop1 The Program: ------------ This program has been tested on UNIX via Exceed. It could possibly be recompiled to work with Windows, but this has not been tested. In addition, only UNIX text files work with the program. If it needs to be recompiled, use the following command whilst in the jim++ root directory: g++ -o jim++ main.cpp jimpp/*.cpp Overview of Code Design ----------------------- Features: --------- - Case insensitive commands (case sensitive LABEL, LOOP and variable names) - Trims excess spaces - Will convert between double and int in FORCE for SIMPLE and DECIMAL variables - LOOP is only partially implemented, enough to show how it would work. To get ENGAGE to work inside a LOOP would involve a complete code rehaul - Sensible error messages - Functions to perform the most used operations - Completely ignores blanks lines and comments - Errors with mistyped variables, or if tries to FIRE an undeclared variable - Can interpret various files at a time - Added keyword LOOP Justification of code layout: ----------------------------- The file is taken in by main and fed into interpreter. This is a derived class of abstract_interpreter. This class takes the file, gets its contents and parses them by creating various statement class. It will then run through the statements and execute them, The statements are all derived from a base statement class. They are all in one file because it makes coding easier, and then one doesn't have to create and #include a new file for each new statement (the same with variables). Variables are all dealt with in one statement class, as are FIRE and FIRELN - they are merely passed different parameters depending on the code. There is only one exception class. This is because main only prints out "Interpreter Exception" and would not distinguish between base and derived classes. As I only use exceptions for code errors, one class suffices. It is passed a sensible error message, which includes the problem line number. Noting here that line numbers are affected by the fact that the interpreter ignores blank lines and lines with # at the start. The functions are kept all in one file, they are used to get integers, doubles and strings from the line passed to it. This includes searching the map for the variable and extracting it's value. The function trim was written by myself in emulation of the one in the boost library, as there is not a trim function in the STL at the moment. The use of trim() meant that if there were any extra spaces then they would be ignored. As exceptions and variables didn't need much in the way of functions, they are merely header files with inline constructors. This also reduced the amount of code used. Test files have been provided, for your use. The original main.cpp and abstract_interpreter.hpp have been downloaded from the website, and jim++ recompiled to include them. The Files --------- jimpp/exceptions.hpp jimpp/functions.cpp jimpp/functions.hpp jimpp/interpreter.cpp jimpp/interpreter.hpp jimpp/statement.cpp jimpp/statement.hpp jimpp/variable.hpp test_files/test2.jpp test_files/test3.jpp test_files/test4.jpp test_files/test5.jpp test_files/test6.jpp test_files/test.jpp abstract_interpreter.hpp jim++ main.cpp readme.txt (this file)