Primary:
[Skip To Body]
[Front Door]
[Current]
[Glance]
[Honesty]
[Instructions]
[Links]
[Search]
[Syllabus]
Sets:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Project]
[Readings]
[Reference]
ECA:
[About]
[Grades]
[Quizzes]
[Submit Work]
[Change Password]
[Reset Password]
Miscellaneous:
[2001S]
[98F]
[SamR]
[Glimmer Labs]
Back to Shift-Reduce Parsing, Concluded. On to Introduction to Type Checking.
Held Friday, October 11, 2002
Summary
Today we consider ways to extend parse trees so that they can be used to compute relevant values.
Notes
Overview
neighboringnodes (children, parent, siblings).
executedby the parser.
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)
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)
Thursday, 29 August 2002 [Samuel A. Rebelsky]
Friday, 11 October 2002 [Samuel A. Rebelsky]
Back to Shift-Reduce Parsing, Concluded. On to Introduction to Type Checking.
Primary:
[Skip To Body]
[Front Door]
[Current]
[Glance]
[Honesty]
[Instructions]
[Links]
[Search]
[Syllabus]
Sets:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Project]
[Readings]
[Reference]
ECA:
[About]
[Grades]
[Quizzes]
[Submit Work]
[Change Password]
[Reset Password]
Miscellaneous:
[2001S]
[98F]
[SamR]
[Glimmer Labs]
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 Fri Dec 6 10:38:16 2002.
The source to the document was last modified on Fri Oct 11 10:32:31 2002.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS362/2002F/Outlines/outline.19.html
.
You may wish to
validate this document's HTML
;
;
Check with Bobby