[Skip to Body]
Primary:
[Front Door]
[Schedule]
[Piazza]

[Academic Honesty]
[Instructions]
Current:
[Current Outline]
[Current EBoard]

[Current Assignment]
[Current Lab]
Groupings:
[Assignments]
[Documents]
[EBoards]
[Examples]
[Exams]
[Handouts]
[Labs]
[Outlines]
[Readings]
Related Courses:
[CSC362 2004S (Rebelsky)]
[CSC362 2010S (Stone)]
Misc:
[SamR]
[GNU Coding Standards]
[Dragon Book]
[Pascal Standards]
Back to MidSemester Examination. On to Type Checking (1) Introduction.
This outline is also available in PDF.
Held: Friday, 28 October 2011
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 : LPAREN exp RPAREN factor.value = exp.value factor.type = exp.type
factor : NUMBER factor.value = NUMBER.value factor.type = NUMBER.type
factor : INTEGER factor.value = INTEGER.value factor.type = integer factor : REAL factor.value = REAL.value factor.type = real
string representation, we will need to convert it
factor : NUMBER factor.value = stringToNumber(NUMBER.string)
factor : ID factor.type = lookupType(symbols,ID) factor.value = lookupValues(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 : statement_list statement_list : statement ';' statement  epsilon statment: : assignment_statement  print_statement assignment_statement : ID ASSIGN exp print_statement : PRINT ID
symbol table.
print_statement : PRINT ID display Printstatement.valueOf(ID.name)))
statment : print_statement print_statment.value_of = statement.value_of
statement_list_0 : statement ';' statement_list_1 statement.valueOf = statement_list_0.valueOf
S : statement_list statement_list.valueOf = (lambda (x) 'undefined) statement_list_0 : statement ';' statement_list_1 statement_list_1.valueOf = extend(statement_list_0.valueOf,statement.extension)
Back to MidSemester Examination. On to Type Checking (1) Introduction.
[Skip to Body]
Primary:
[Front Door]
[Schedule]
[Piazza]

[Academic Honesty]
[Instructions]
Current:
[Current Outline]
[Current EBoard]

[Current Assignment]
[Current Lab]
Groupings:
[Assignments]
[Documents]
[EBoards]
[Examples]
[Exams]
[Handouts]
[Labs]
[Outlines]
[Readings]
Related Courses:
[CSC362 2004S (Rebelsky)]
[CSC362 2010S (Stone)]
Misc:
[SamR]
[GNU Coding Standards]
[Dragon Book]
[Pascal Standards]
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 Dec 7 10:26:34 2011.
The source to the document was last modified on Fri Aug 26 13:03:12 2011.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS362/2011F/Outlines/outline.25.html
.