     CSE 109    Progam 5    Due   9 PM Thursday 9 April 2009
     (Late Collection dates:  9 PM  11, 12 April 2008)

     This programming assignment is the third step of four in which we
     will create a program to run FPCLAC programs on the STCALC calculator.
     For this assignment I ask you to write a program that parses PCALC
     programs (a restricted set of FPCALC programs).  PLEASE READ OVER THE
     WHOLE ASSIGNMENT BEFORE STARTING.

     Your program should read the command line, expecting the name of an
     input file and, optionally, the string "-v". The input file should
     consist of what purports to be a PCALC program. It then should run
     the program, parsing each line as it is encountered and either
     diagnosing a syntax error and quitting or executing the command on that
     line.

     Part of the parse involves determining whether a reference to a line
     number by some branch instruction is legitimate. Therefore, as you load
     the program, build a table (an instance of Table< , >) whose keys are
     the (distinct!) labels and whose data are the corresponding line numbers.

     The program should execute the PCALC program in one of two modes:
        (1)  Nonverbose (no -v argument on the command line). It simply
             displays to the terminal the data entered (as each is read in
             response to the command "enter") and the output (in response to
             the command "getScreen").
        (2)  Verbose (-v argument on the command line). In addition to the
             display in (1), also echo the text of the line being executed.

     To greatly simplify this assignment, assume that when your program parses
     a line it determines whether it satisfies the syntax of PCALC, whose
     diagrams I handed out in class. The diagrams can also be reached from a
     link on the  course web page. Note that the statements in PCALC are in
     one to one correspondence with the operations of STCALC. Thus, the
     parser  only accept statements like
              enter
              x+
              push
              push
              stack+
              getScreen
              jumpL  mumb0jumb0

     Assignment 6 will deal with the problem of parsing and executing the
     more complicated forms of these statements, e.g.,
            push x*x+4*(yot-two)
            jumpLE oNe

     It is VERY IMPORTANT for the next assignment that you create a subclass
     of StCalc, say ProgCalc, to implement PCALC.

     The use of class ProgCalc should look something like:
          ProgCalc p;
          ifstream in;
          bool verbose;
          ....
          .....
          p.load(in);
          p.run(verbose);

     It is also VERY IMPORTANT that the methods in ProgCalc be highly
     modularized, because in programming assignment #6 we will create
     a subclass of ProgCalc that will take advantage of the modularity
     and save a lot of work (i.e., avoid writing repetitive code).

     To submit your assignment, create a subdirectory of /cse109.091 called
     p5 (that is, from your root directory cse109.091/p5) for doing your
     work.  Finally, indicate you wish the assignment to be collected by
     executing the unix command "touch DONE", which will create a file of
     0 bytes named DONE.  Then all files in the subdirectory p5 (but not
     in subdirectories of the subdirectory p5) will be collected.  I will
     test your program using your Makefile.

     Note: This assignment depends on classes Lex, Word, Table< , >, Calc,
           and StCalc developed in earlier assignments.  It would be best if
           you used your versions of these files, but you can use the object
           files lex.o, calc.o, stcalc.o, word.o, and check.o, as well as the
           template and header files table.t, word.h, lex.h, calc.h, stcalc.h,
           and check.h

           To aid you I have stored these files in /proj/csc109/p5. If you
           use them, it is VERY IMPORTANT that you use them as I direct.
           Remember, you don't want to aggravate me.  First, in your Makefile,
           all references to the .o files used from /proj.csc109/p5 should be
           prefixed with /proj/csc109/p5.

           For example, the p5: command might be
               p5: p5.o /proj/csc109/p5/lex.o  /proj/csc109/p5/word.o
                          /proj/csc109/p5/calc.o /proj/csc109/p5/stcalc.o
                          /proj/csc109/p5/check.o   progcalc.o
               <tab>  g++ -o p5 p5.o /proj/csc109/p5/lex.o
                           /proj/csc109/p5/word.o
                          /proj/csc109/p5/calc.o /proj/csc109/p5/stcalc.o
                          /proj/csc109/p5/check.o   progcalc.o
           where the files for the given command are all on one line, which
           emacs will allow, but for which I have insufficient room here.
           Thus, the above example from the Makefile has only two (long) lines.

           Second, to use my .h files, your .cc files should have include
           statements that prefix the name of the particular .h file with
           /proj/csc109/p5/, e.g.,
           #include "/proj/csc109/p5/check.h"

     Note: I will store some test files in /proj/csc109/p5.  I will use
           these files, and perhaps others, to test your program.

     Note: You should compare the behavior of your program to the behavior
           of pcalc, my solution to this assignment.

     Note: I WILL NOT BE ABLE TO PROVIDE THE FILES progcalc.h and progcalc.cc
           when you do the next assignment. Thus, you must get p5 running in
           order to do p6.

     Note: As pointed out above, it will be useful to have a table for
           storing the line labels and their corresponding line numbers. It
           will also be useful to have a table for storing the names of
           the PROGCALC variables and their corresponding memory locations.

     Once again I remind you to avoid unfair collaboration.  To understand
     what is meant by "unfair collaboration" read the syllabus again.

