[Instructions] [Search] [Current] [News] [Syllabus] [Handouts] [Outlines] [Assignments]
Held Friday, September 18, 1998
Notes
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.
Exp
/ | \
/ | \
Exp + Exp
| / | \
| / | \
num Exp * Exp
| |
| |
num num
Exp
/ | \
/ | \
Exp * Exp
/ | \ |
/ | \ |
Exp + Exp 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 ::= '+' | '-'
Term.
Exp ::= Exp AddOp Term
Term ::= Term MulOp Factor
Exp ::= Exp AddOp Term
| Term
Term ::= Term MulOp Factor
| Factor
Factor ::= '(' Exp ')'
| num
| id
-+num is meaningless, as is ---num).
Back to Grammars and parsing, continued. On to Predictive parsing.
History
[Instructions] [Search] [Current] [News] [Syllabus] [Handouts] [Outlines] [Assignments]
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.
Source text last modified Mon Sep 21 10:09:55 1998.
This page generated on Wed Sep 23 13:11:43 1998 by SiteWeaver.
Contact our webmaster at rebelsky@math.grin.edu