CSC 4101 Chapter : Parsing

12 views5 pages
15 Mar 2019
School
Course
Professor

Document Summary

Node* parsex() { ch = getnexttoken(); if (ch!="a") error(""); y = parsey(); ch = getnexttoken(); if (ch!="b") error(""); z = parsez(); ch = getnexttoken(); if (ch!="c") error(""); return new x(y, z); Terminal symbols (tokens) id, num, -, (, ), +, *, / N -> x where n is a non-terminal and x"s are (non-) terminals. = bottom-up parsing (yacc, bison, etc. , lr(1), lalr(1)) Parse trees x * y + z exp exp exp op exp exp op exp exp op exp + id id * exp op exp z x id * id x y id + id y z. | add-op exp term -> factor trest trest. | ( exp ) add-op -> + | - mul-op -> * | / Every parse function assumes first token was already read. Node* parsefactor() { if (tok->gettype() == id) { tok = getnexttoken(); return new ident(); else if (tok->gettype() == lparen) { tok = getnexttoken(); t = parseexp();

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents

Related Questions