Semantic Actions #2 (Part 6 of 7)


Date assigned: 4/9/07
Date due: 4/23/07
Points: 50

You are to write the module to perform all of the semantic actions associated with the bottom-up parser. This module will be passed the handle popped by the botton-up parser and will return the attributes of the dummy nonterminal to be pushed on the expression stack. You must also implement the output statement in your top-down parser.

The expression stack is changing form. Each entry on the stack now has four attributes: (1) class (2) value (3) level (4) address. Level and address indicate where the actual value of the dummy nonterminal may be found.

The semantic actions must perform all tasks necessary for every distinct handle popped from the expression stack. You also need to perform the following semantic error checks:

1) Check to insure that only array-type id's precede []'s.

2) Check to insure that function calls use id's of type FUNCNAME.

3) Check to insure that all id's have been declared.

You need to extensively test your program. To test your program, you are to run your quad file through the interpreter found at /home/CS480/interpreter on zeus. The file is called interpreter07.tar.gz.


Consider the following program:

main ()
{
  int a;

  a = 100;
  a = a + 1;
  output (a);
}
Let's take a look at the final quad file produced by the compilation of this program by our compiler.
 1  27   0   0   0   0   0   0
 2  22   0   2   0   0   0   0
 2  26   2   1   0   0   3   1
 2   1   4   1   2   2   3   2
 2  26   4   2   0   0   3   1
 2  20   4   1   0   0   0   0
 2  25   0   1   0   0   0   0
 2  26   0   0   0   0   1   0
 2  23   0   0   0   0   0   0
 1  21   0   0   0   0   0   1
 1  28   0   0   0   0   0   0
3
0
100
1

If you are having trouble debugging this portion of the compiler, I would suggest the following:

1) Start the interpreter in trace mode.

2) On the first quad, get a stack dump.

3) On each subsequent quad, get a stack dump until you isolate the quad that is causing the problem.

4) Fix your error and test the same way.

Note1: You can also set a breakpoint in the interpreter to get to a spot in the quad file sooner.

Note2: It is essential that you fully understand everything in this quad file before beginning the coding of this portion of the compiler. Further, I would suggest that you have some kind of design that includes all of the logic necessary for implementing the semantic actions before writing any code.

Note3: Remember, your compiler is to be in a directory called yourlastname. In that directory there is to be a makefile that I simply use to compile your project creating the executable pcc. Continue creating subdirectories within yourlastname directory as needed. Also, continue to use subversion more than ever as we go back and modify existing code.

Note4: Use the submit script to submit your solution: zeus$ submit cs480s07 user.tar.gz

Note5: On the day the program is due, turn in a colored hard copy of the source code in this order:

1. makefile
2. main .h/.c
3. bu .h/.c
4. semantic actions for bu .h/.c
5. any new .h/.c source file combinations

Note6: Please name your testcases sa2.1.c, sa2.2.c, ... and submit all of the testcases you used to test your program in the tar file. Place all of these testcases in a directory called testfiles. Finally, your program might not be able to handle an all inclusive testcase, but I would like you to write one anyway. Call this testcase sa2all.c.

Note7: This assignment is HARD!!! If you put the majority of the coding of this project off until the second weekend, you will most likely be sorry. Further, many of you suffered (or are continuing to suffer) from errors caused by the lexical analyzer. Well here we are again. A poor design/implementation of this module will cause you much grief with the final semantic actions assignment which is worth 100 points. If you want to know how painful this might be, just go to the top-down parser grammar and look for EXPRESSION!!! You can do this, but you must start early.

Clarification:

As output, generate a complete source listing followed by 0 Errors or a complete dump of the error table using the format described in the earlier assignment. Further, the any testfile must end with a .c and must generate a .q file with the same prefix.


Douglas J. Ryan / ryandj@pacificu.edu