



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
These lecture notes provide an overview of the final exam for cpsc 326 (spring 2013), including details about the exam format, topics covered, and strategies for dealing with left-associative operators and operator precedence in context-free grammars.
Typology: Study notes
1 / 5
This page cannot be seen from the preview
Don't miss anything!




Today ...
Basics
Dealing with left-associative operators
Example:
e → val ( ÷ val )∗
Expression* expr() { Expression* v1 = val(); advance(); while(tok.type() == DIV) { advance(); Expression* v2 = val(); v1 = new Div(v1, v2); } return v1; }
Operator precedence
2 + 3 / 4 ≡ 2 + (3 / 4) 2 / 3 + 4 ≡ (2 / 3) + 4
One solution: Encode precedence in the grammar
e → t ( ‘+’ t )∗
t → num ( ’/’ num )∗
Q: What is the parse tree for: 2 + 3 / 4?