[Skip to Body]
Primary:
[Front Door]
[Current]
[Glance]
-
[Honesty]
[Instructions]
[Links]
[Search]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Project]
[Readings]
[Reference]
Misc:
[2001S]
[2002F]
[SamR]
Back to Class Cancelled. On to Type Checking (1): Introduction.
Held: Monday, 29 March 2004
Summary: Today we consider ways to extend parse trees so that they can be used to compute relevant values.
Related Pages:
Notes:
Overview:
neighboringnodes (children, parent, siblings).
Exp ::= Term Exp.value = Term.value Exp.type = Term.type Term ::= Factor Term.value = Factor.value Term.type = Factor.type Factor ::= OPEN Exp CLOSE Factor.value = Exp.value Facator.type = Exp.type
Factor ::= NUMBER Factor.value = NUMBER.value Factor.type = NUMBER.type
string representation, we will need to convert it
Factor ::= NUMBER Factor.value = stringToNumber(NUMBER.string)
Factor ::= ID Factor.type = lookupType(symbols,ID)
Exp_0 ::= Exp_1 + Term Exp_0.value = Exp_1.value + Term.value Exp_0.type = mostGeneral(Exp1.type,Term,type) Exp_0 ::= Exp_1 - Term Exp_0.value = Exp_1.value - Term.value Exp_0.type = mostGeneral(Exp1.type,Term,type)
yacc
or bison
and pay
attention to only values, the rules will look like
exp : exp '+' exp { $$ = $1 + $3; } exp : exp '-' exp { $$ = $1 - $3; }
MULTIPLY
and DIVIDE
as tokens,
we might write something like
MulOp ::= MULTIPLY MulOp.fun = (lambda (x y) (* x y)) MulOp ::= DIVIDE MulOp.fun = (lambda (x y) (/ x y))
Term_0 ::= Term_1 MulOp Factor Term_0.value = MulOp.fun(Term_1.value, Factor.value) Term_0.type = mostGeneral(Term1.type,Factor,type)
executedby the parser.
compute a value from other valuesaspect of the grammar, the value attribute is synthesized, computed only from children.
S ::= StatementList StatementList ::= Statement ';' StatementList | epsilon Statement ::= AssignmentStatement | PrintStatement AssignmentStatement ::= ID ASSIGN Exp PrintStatement ::= PRINT ID
symbol table.
PrintStatment ::= PRINT ID display PrintStatement.valueOf(ID.name)))
Statement ::= PrintStatement PrintStatement.valueOf = Statement.valueOf
StatementList_0 ::= Statement ';' StatementList_1 Statement.valueOf = StatementList_0.valueOf
S ::= StatementList StatementList.valueOf = (lambda (x) 'undefined) StatementList_0 ::= Statement ';' StatementList_1 StatementList_1.valueOf = extend(StatementList_0.valueOf,Statement.extension)
Back to Class Cancelled. On to Type Checking (1): Introduction.
[Skip to Body]
Primary:
[Front Door]
[Current]
[Glance]
-
[Honesty]
[Instructions]
[Links]
[Search]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Project]
[Readings]
[Reference]
Misc:
[2001S]
[2002F]
[SamR]
Disclaimer:
I usually create these pages on the fly
, which means that I rarely
proofread them and they may contain bad grammar and incorrect details.
It also means that I tend to update them regularly (see the history for
more details). Feel free to contact me with any suggestions for changes.
This document was generated by
Siteweaver on Wed May 5 11:47:08 2004.
The source to the document was last modified on Tue Jan 20 23:06:46 2004.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS362/2004S/Outlines/outline.24.html
.
You may wish to
validate this document's HTML
;
;
Check with Bobby