Tutorial on Type Analysis


We start with a very simple kernel language where a Program
is a Block consisting of Declarations for variables,
assignment Statements , and trivial Expressions .
Other forms of Declarations
and Expressions are added to the grammar when the
type analysis task is further refined.
Here is a simple example program:
SimpleExamp[1]==
begin
var int i, int j,
bool b, bool c,
real r, real s;
i = 1;
b = true;
r = 3.4;
j = i;
c = b;
s = r;
end
This macro is attached to a product file.
The concrete kernel grammar is specified as follows:
Core.con[2]==
Program: Block.
Block: 'begin' Declaration* Statement* 'end'.
Declaration: 'var' ObjDecls ';'.
ObjDecls: ObjDecl // ',' / .
ObjDecl: TypeDenoter DefIdent.
TypeDenoter: TypeUseIdent.
Statement: Variable '=' Expression ';'.
Statement: Expression ';'.
Expression: Factor.
Factor: Operand.
Operand: IntNumber.
Operand: RealNumber.
Operand: Variable.
Variable: UseIdent.
This macro is attached to a product file.
The expression syntax is prepared to introduce operators
of different precedences (2 for binary and 1 for unary operators).
Factor and Operand are represented by
Expression contexts in the tree grammar.
Opr.sym[3]==
Expression ::= Factor Operand.
This macro is attached to a product file.
The notation of identifiers and numbers is chosen as in Pascal.
Core.gla[4]==
Ident: PASCAL_IDENTIFIER
IntNumber: PASCAL_INTEGER
RealNumber: PASCAL_REAL
PASCAL_COMMENT
This macro is attached to a product file.


|