A .wlp4ti file (pronounced woolpty?) is a text file containing a representation of a parse tree for a WLP4 program. It has the same structure as a .wlp4i file, except that lines corresponding to expression nodes in the parse tree are annotated with the type of the expressions. Once a parse tree for a WLP4 program has been annotated with type information during semantic analysis, this format can be produced by performing a preorder traversal of the tree:
BOF BOF
or EOF EOF
for the BOF and EOF nodes).NUM
or
NULL
, or if the kind of the token is an ID
and the ID
has a type (i.e., it represents a variable name rather than a procedure name),
print a space, then a colon (:
),
then another space, then the type of the value represented by
the node (int
or int*
).expr
, term
, factor
or
lvalue
, print a space, then a colon (:
),
then another space, then the type of the expression rooted
at the node (int
or int*
).int wain(int* start, int size) { int* end = NULL; end = start + size; while(start < end) { println(*start); } return 241; }
Original .wlp4i file (no type information) start BOF procedures EOF
BOF BOF
procedures main
main INT WAIN LPAREN dcl COMMA dcl RPAREN LBRACE dcls statements RETURN expr SEMI RBRACE
INT int
WAIN wain
LPAREN (
dcl type ID
type INT STAR
INT int
STAR *
ID start
COMMA ,
dcl type ID
type INT
INT int
ID size
RPAREN )
LBRACE {
dcls dcls dcl BECOMES NULL SEMI
dcls .EMPTY
dcl type ID
type INT STAR
INT int
STAR *
ID end
BECOMES =
NULL NULL
SEMI ;
statements statements statement
statements statements statement
statements .EMPTY
statement lvalue BECOMES expr SEMI
lvalue ID
ID end
BECOMES =
expr expr PLUS term
expr term
term factor
factor ID
ID start
PLUS +
term factor
factor ID
ID size
SEMI ;
statement WHILE LPAREN test RPAREN LBRACE statements RBRACE
WHILE while
LPAREN (
test expr LT expr
expr term
term factor
factor ID
ID start
LT <
expr term
term factor
factor ID
ID end
RPAREN )
LBRACE {
statements statements statement
statements .EMPTY
statement PRINTLN LPAREN expr RPAREN SEMI
PRINTLN println
LPAREN (
expr term
term factor
factor STAR factor
STAR *
factor ID
ID start
RPAREN )
SEMI ;
RBRACE }
RETURN return
expr term
term factor
factor NUM
NUM 241
SEMI ;
RBRACE }
EOF EOF
|
Type-annotated .wlp4ti file start BOF procedures EOF
BOF BOF
procedures main
main INT WAIN LPAREN dcl COMMA dcl RPAREN LBRACE dcls statements RETURN expr SEMI RBRACE
INT int
WAIN wain
LPAREN (
dcl type ID
type INT STAR
INT int
STAR *
ID start : int*
COMMA ,
dcl type ID
type INT
INT int
ID size : int
RPAREN )
LBRACE {
dcls dcls dcl BECOMES NULL SEMI
dcls .EMPTY
dcl type ID
type INT STAR
INT int
STAR *
ID end : int*
BECOMES =
NULL NULL : int*
SEMI ;
statements statements statement
statements statements statement
statements .EMPTY
statement lvalue BECOMES expr SEMI
lvalue ID : int*
ID end : int*
BECOMES =
expr expr PLUS term : int*
expr term : int*
term factor : int*
factor ID : int*
ID start : int*
PLUS +
term factor : int
factor ID : int
ID size : int
SEMI ;
statement WHILE LPAREN test RPAREN LBRACE statements RBRACE
WHILE while
LPAREN (
test expr LT expr
expr term : int*
term factor : int*
factor ID : int*
ID start : int*
LT <
expr term : int*
term factor : int*
factor ID : int*
ID end : int*
RPAREN )
LBRACE {
statements statements statement
statements .EMPTY
statement PRINTLN LPAREN expr RPAREN SEMI
PRINTLN println
LPAREN (
expr term : int
term factor : int
factor STAR factor : int
STAR *
factor ID : int*
ID start : int*
RPAREN )
SEMI ;
RBRACE }
RETURN return
expr term : int
term factor : int
factor NUM : int
NUM 241 : int
SEMI ;
RBRACE }
EOF EOF
|