[Instructions] [Search] [Current] [Syllabus] [Links] [Handouts] [Outlines] [Assignments] [Labs]
Back to Languages and Grammars. On to Discussion of Exam 1.
Held Friday, April 9
Summary
Contents
Handouts
::= for productions.
-> for productions.
::= to separate the two parts of a rule.
Program ::= 'program'
identifier
'('
Identifier-List
')'
Declaration-List
Compound-Statement
'.'
Compound-Statement ::= 'begin'
Statement-List
'end'
Statement-List ::= Statement Statement-List ::= Statement ';' Statement-List
Statement ::= Assignment-Statement Statement ::= Compound-Statement ... Assignment-Statement ::= identifier '=' Expression ...
Rock Anything Hardplace ::= Rock Hardplace
Exp ::= number
Exp ::= identifier
Exp ::= UnOp Exp
UnOp ::= '+' UnOp ::= '-'
Exp := Exp BinOp Exp
BinOp ::= '+' | '-' | '*' | '/'
Exp ::= '(' Exp ')'
a+b*2 is an expression? First,
we observe that the
lexer converts this to
identifier + identifier * number
Exp => // Exp ::= Exp BinOp Exp Exp BinOp Exp => // Exp ::= identifier identifier BinOp Exp => // BinOp ::= '+' identifier + Exp => // Exp ::= Exp BinOp Exp identifier + Exp BinOp Exp => // Exp ::= number identifier + Exp BinOp number => // Exp ::= identifier identifier + identifier BinOp number => identifier + identifier * number
Exp rather than the
first in Exp BinOp Exp.
Exp
/ | \
/ | \
Exp BinOp Exp------
/ | | \ \
/ | | \ \
identifier + Exp BinOp Exp
/ | |
/ | |
identifier * number
num + num * num.
num - num - num might be parsed with
two different trees.
Term.
Term? Something that may include
multiplication but does not include no unparenthesized addition.
AddExp
Term.
Term.
Factor.
Terms.
Term ::= Term MulOp Term MulOp ::= '*' | '/'
Terms? Those that don't include
multiplication. We've already called those Factors.
Term ::= Factor
Factor ::= '(' + Exp + ')'
Factor ::= num
Factor ::= id
Term, we can separate them into those that do and
those that don't.
Exp ::= Exp AddOp Exp Exp ::= Term AddOp ::= '+' | '-'
History
Back to Languages and Grammars. On to Discussion of Exam 1.
[Instructions] [Search] [Current] [Syllabus] [Links] [Handouts] [Outlines] [Assignments] [Labs]
Disclaimer Often, these pages were created ``on the fly'' with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.
This page may be found at http://www.math.grin.edu/~rebelsky/Courses/CS302/99S/Outlines/outline.27.html
Source text last modified Mon Apr 12 09:23:02 1999.
This page generated on Wed Apr 14 10:42:09 1999 by SiteWeaver. Validate this page's HTML.
Contact our webmaster at rebelsky@math.grin.edu