Project 2 serves to create and implement a language using a context-free grammar. The language is interpreted using two programs:
- the scanner, which reads the input programs and returns a sequence of tokens
- the parser, which reads the tokens, and runs the code line by line, generating an error list as it does so.
If at any point an error is encountered, the current program stops and does not pass along its input to the next stage of compilation. It would not make sense to try and interpret code that has not been parsed properly; similarly, it would not make sense to parse a program containing unexpected/unhandled tokens.
- Status
- To do
- Context-Free Grammar
- Syntax Overview
- Comments
- Program Layout
- Block Declarations
- Move Commands
- Sample Program
- Sample Output
The parser is currently capable of processing the WORLD and BLOCKS sections of code, declaring the world and filling it with its initial values. Much work will need to be done to verify this functionality before moving on to the MOVES section, which will likely be the most difficult to implement and test.
The language was changed from java to C++ in order to implement a Makefile, which will allow Dr. Strader to quickly and easily compile the code with all the same flags. This also makes documentation easier, as instructions for how to run are essentially
make
blocks input
The last declaration in the BLOCKS
section must be arm()
. Note that by default, arm starts at location (1,1)
. However, an initial location for arm may also be declared by supplying a coordinate instead of the empty parentheses, e.g. arm(2,3);
.
Note that the Block World interpreter will automatically output the initial and final positions of all blocks, in addition to the relevant compilation or debugging output (if desired).
## Sample Program: ``` /** Dylan Jager-Kujawa and Matt Richardson Block World Sample Input */WORLD proj2(5,6): // Declare world with dimensions 5x5 BLOCKS { var1(1,1); // var1 declaration var2(1,2); // var2 declaration var3(2,4); // var3 declaration arm(); // Default arm location = (1,1) }; MOVES [ MOVE(1,1); // Move arm to (1,1) (unnecessary) GRAB(var1); // Pickup var1 MOVE(2,2); // Move arm to (2,2) DROP; // Drop var1 MOVE(1,2); // Move arm to (1,2) GRAB(var2); // Pickup var2 MOVE(2,2); // Move arm to (2,2) STACK; // Stack var2 on var1 /* Errors: UNSTACK(var1); //ERROR: var 1 not at top of stack MOVE(6,5); //ERROR: (6,5) not located within proj2 DROP; //ERROR: not holding anything */ ];
<a name="output" />
## Sample Output (from code above excluding errors):
Initial position: # blocks / location: 1 2 3 4 5 1 1 _ _ _ _ 2 1 _ _ _ _ 3 _ _ _ _ _ 4 _ 1 _ _ _ 5 _ _ _ _ _ 6 _ _ _ _ _ Location contents: (1,1): var1 (1,2): var2 (2,4): var3
Final position: # blocks / location: 1 2 3 4 5 1 _ _ _ _ _ 2 _ 2 _ _ _ 3 _ _ _ _ _ 4 _ 1 _ _ _ 5 _ _ _ _ _ 6 _ _ _ _ _ Location contents: (2,2): STACK: [top] var2 var1 [bottom] (2,4): var3