3460:430/530:080  Theory of Programming Languages                                                                  Fall 2003

Dr. C.-C. Chan                                                                                                                           Due:  10/19/03

Project #3  (30 pts)

 

Problem:  Based on Project 2, modify the language to allow the following features:

 

            1.  Variables may be declared as int, char, or float.  The syntax for declaring variables is

                             <var declaration>  ::=  <type name>  <var name> {, <var name>}+ ;

                   Variables must be declared before they are referenced.

 

              2. Implement type promotion rules for arithmetic operations:

                             char is promoted to int,

                             char and int are promoted to float.

 

3.      Do the following type checkings:

(1)     assignment of float to int or char is not allowed.

(2)     assignment of float or int to char is not allowed.

 

4.      Add an escape sequence (starting with !) to invoke the following utilities:

              (1)  !printvar printout names and values of all variables defined at this point.

              (2)  !<command>                execute the Linux <command>, which is any available command in Linux.

                  e.g.:  !ls  should perform the ls command, and !vi  should invoke the vi editor.

Note:  all utilities are in lower case, and we do not need ‘;’ to end the line

 

5.      The value assigned to a variable in an invalid input line should be discarded.

e.g.:  given the input sequence

              float a;

                             a = 5.0;

                             a = 4 + b;  //invalid inputs

                             a;

              the value of a should remain to be 5.0.

             

Implementation:

              1.  Add new token types for variable.

              2.  Add new rules and corresponding actions to reflect the new features.

              3.  Extend yylex function to recognize new features.

 

 

Submissions:

            Name your source file as yourlastname_p3.y and yourlastname_symbol.c

            Send the source file by e-mail to rthimma@uakron.edu and chan@cs.uakron.edu

            The project is due by midnight of the due date.