CFG and the attribute grammar
- FT with end tail = end product parent
- Use the cheat sheet for fig 4,3 to parse thru the tree?
Drawing 2025-02-25 05.46.55.excalidraw
Excalidraw Data
Text Elements
(7-1)*5
Embedded Files
12051a6973b770a604275ad3fa42a77230ebe8ff: Pasted Image 20250225064524_350.png
Link to original
AST
Constructing:
We think of this like reading, the leftmost on same depth will be the most immediate operation. So taking some - ⇒ will be + then -.
NNN+10−(3∗2.3)−(2−OU)/2
- left right side of EQ is deepest in tree
- Rightmost creates the “root”
- Order of ops really only matters for same depth
If we didn’t have parentheses around (2-OU), thenDrawing 2025-02-25 04.36.25.excalidraw
Excalidraw Data
Text Elements
Link to original\instead of-
If we had Instead, then 10 would be on depth 1, - on depth 0, (...) on depth 1 right side
Reading an AST:
Say we have
(-)
/ \
(-) (/)
/ \ / \
(-) 2 OU 2
/ \
(+) (*)
/ \ / \
NNN 10 3 2.3
We read LEFT to RIGHT visiting each child before moving on. Start with NNN+10, then deal with -, which has unvisited child of * which has children of 2.3 NNN+10-(3*2.3)
Repeat process as many times as needed
Fig 4.3 simplified (likely have on cheat sheet)
.stis with any func withop, and is the argument for func. .valis the output of the func/statement
- E T TT
- TT
- op T TT
- T F FT
- FT
- op F FT
-
.st,.val=parent.val
- F
- op
- (E)
- const
left box holds the st attribute
