tutorial10

tutorial10 - CS 230 Tutorial 10 March 21, 2011 Jonathan...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 230 Tutorial 10 March 21, 2011 Jonathan Rodriguez j2rodrig@uwaterloo.ca
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Tutorial 10 • Parsing Revisited • Assignment 4 Sample Solutions
Background image of page 2
Parsing 20 - 5 / 3 INTEGER “20” INTEGER “3” MINUS DIV INTEGER “5”
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Leftmost Derivation • Scans input from left to right • LL(k): Leftmost Linear with k tokens look-ahead • LL(1): Simplest form: 1 token look-ahead • Derivation can be done with a Recursive Descent Parser, which does top-down parsing
Background image of page 4
LL(1) Grammar expression : term moreexpr moreexpr : PLUS term moreexpr | MINUS term moreexpr | ε term : INTEGER moreterm moreterm : MULT INTEGER moreterm | DIV INTEGER moreterm | ε
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
A More Compact Grammar expression : term { (PLUS | MINUS) term } term : INTEGER { (MULT | DIV) INTEGER } Braces mean zero or more
Background image of page 6
Parser Code function term(): accept(INTEGER) while next token is MULT or DIV: accept(MULT or DIV) accept(INTEGER) function expression(): term() while next token is PLUS or MINUS: accept(PLUS or MINUS) term() Accepts the next token from the input stream (must be of given type)
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/28/2011 for the course CS 230 taught by Professor Bb during the Spring '11 term at Waterloo.

Page1 / 17

tutorial10 - CS 230 Tutorial 10 March 21, 2011 Jonathan...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online