3460:430/530 Theory of
Programming Languages Summer
2004
Dr. C.-C. Chan Due: 6/7/04
Project #2 (30 pts)
Problem: Based on Project 1, extend
the language to allow the following features:
1. Use semicolon instead of newline to separate input expressions.
2. Allow assignment operator, =, has the lowest priority and is right associative.
3. Allow an input expression to across multiple lines. e.g.,
x =
1 + 3
+ 4;
should be treated as a valid input.
4. 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.
Variable names may be of 32 characters long and consist of letters of upper or lower cases. They are case-insensitive.
5. Operations of char include assignment.
6. Add a built-in function printVars that prints out values of variables defined in the symbol table.
Implementation:
1. Add new token types for built-in functions and type names.
2. Add new rules and corresponding actions to reflect the new features.
3. Extend yylex function to recognize new features.
4. You must create a symbol.c source file to implement the symbol table.
Error Checking:
1. References to undefined variables should cause errors.
2. Each variable can only be defined once.
Submissions:
1. Name your source files as "p2.y". "p2.h", and "symbol.c".
2. Send
the source file by e-mail to chan@cs.uakron.edu
3. The project is due by midnight of the due day.