Trial 5
Due on November 3rd&nbs-05:00;11:59&nbs-05:00;PM (Not accepted late).

None yet!


For this trial, you should create an interpreter called dragoninterp that interactively evaluates a Drewno Mars program. In effect, you should be able to supply valid source code as input to dragoninterp and the output of that source code should be shown on the console.

You may use the code (including the starter code) of dmc to build the interpreter. dragoninterp should accept input from stdin. When a declaration is encountered, dragoninterp should keep enough state that the declaration can later be used.

Interactive Scope

dragoninterp should maintain an interactive scope, in which a statement is immediately evaluated. Unless the user is entering a portion of a declaration (i.e. the user is in the midst of creating a function declaration), the result of the statment should take effect immediately. Thus, if the user enters, on stdin, write 1 + 5, dragoninterp should output 6 to the console.

Example session

The behavior of dragoninterp should follow the example. Text in italics describes what the program is doing. Text in bold is output from dragoninterp. Non-bold, non-italic text is user input
		> Welcome to dragoninterp! Enter Drewno Mars code to be interpreted...
		int a;
		(declaration a is added to the global scope)
		int b;
		(declaration b is added to the global scope)
		a = 2;
		(a's value is internally set to 2)
		b = 3;
		(b's value is internally set to 3)
		report a + b;
		> 5

Function declarations should suspend evaluation until the declaration is complete. During suspended evaluation, the interpreter should output a . at the beginning of a line. For example:

		> Welcome to dragoninterp! Enter Drewno Mars code to be interpreted...
		. loc:int;
		. loc = 7;
		. write loc;
		. }
		(Function v is added to the global scope)
		loc = 2;
		(error/dragoninterp terminates because loc is not in the global scope)


Submit a complete source code tarball, including a makefile. It should be possible to run

make all ; dragoninterp

to begin an interactive session.