23
• Syntax Trees MathWorks Compiler Course – Day 5

Syntax Trees MathWorks Compiler Course – Day 5. Syntax Trees MathWorks Compiler Course – Day 5 Parser lexemes shift/reduce seq. Cfg tables Tree Symbols

  • View
    247

  • Download
    2

Embed Size (px)

Citation preview

Page 1: Syntax Trees MathWorks Compiler Course – Day 5. Syntax Trees MathWorks Compiler Course – Day 5 Parser lexemes shift/reduce seq. Cfg tables Tree Symbols

• Syntax Trees

MathWorks Compiler Course – Day 5

Page 2: Syntax Trees MathWorks Compiler Course – Day 5. Syntax Trees MathWorks Compiler Course – Day 5 Parser lexemes shift/reduce seq. Cfg tables Tree Symbols

• Syntax Trees

MathWorks Compiler Course – Day 5

Parser

lexemes

shift/reduce seq.

Cfg tables

Tree

Symbols

syntax tree.

symbol table.

Page 3: Syntax Trees MathWorks Compiler Course – Day 5. Syntax Trees MathWorks Compiler Course – Day 5 Parser lexemes shift/reduce seq. Cfg tables Tree Symbols

• Syntax Trees – Construction

MathWorks Compiler Course – Day 5

Page 4: Syntax Trees MathWorks Compiler Course – Day 5. Syntax Trees MathWorks Compiler Course – Day 5 Parser lexemes shift/reduce seq. Cfg tables Tree Symbols

• Syntax Trees – Construction

• Stack shifted tokens• Pop stack to build reduce nodes

MathWorks Compiler Course – Day 5

Page 5: Syntax Trees MathWorks Compiler Course – Day 5. Syntax Trees MathWorks Compiler Course – Day 5 Parser lexemes shift/reduce seq. Cfg tables Tree Symbols

• Syntax Trees – Construction– Walking

MathWorks Compiler Course – Day 5

Page 6: Syntax Trees MathWorks Compiler Course – Day 5. Syntax Trees MathWorks Compiler Course – Day 5 Parser lexemes shift/reduce seq. Cfg tables Tree Symbols

• Syntax Trees – Construction– Walking

• Inherited attributes– Passed by parameter to getNode

MathWorks Compiler Course – Day 5

Page 7: Syntax Trees MathWorks Compiler Course – Day 5. Syntax Trees MathWorks Compiler Course – Day 5 Parser lexemes shift/reduce seq. Cfg tables Tree Symbols

• Syntax Trees – Construction– Walking

• Inherited attributes– Passed by parameter to walker methods

• Synthesized attributes– Returned values from walker methods

MathWorks Compiler Course – Day 5

Page 8: Syntax Trees MathWorks Compiler Course – Day 5. Syntax Trees MathWorks Compiler Course – Day 5 Parser lexemes shift/reduce seq. Cfg tables Tree Symbols

• Syntax Trees – Construction– Walking– Tree Transformations

MathWorks Compiler Course – Day 5

Page 9: Syntax Trees MathWorks Compiler Course – Day 5. Syntax Trees MathWorks Compiler Course – Day 5 Parser lexemes shift/reduce seq. Cfg tables Tree Symbols

• Syntax Trees – Construction– Walking– Tree Transformations

• Abstract Syntax Trees

MathWorks Compiler Course – Day 5

Page 10: Syntax Trees MathWorks Compiler Course – Day 5. Syntax Trees MathWorks Compiler Course – Day 5 Parser lexemes shift/reduce seq. Cfg tables Tree Symbols

• Syntax Trees – Construction– Walking– Tree Transformations

• Abstract Syntax Trees– Chain shortening– Leaf node elimination– Parenthesis elimination

MathWorks Compiler Course – Day 5

Page 11: Syntax Trees MathWorks Compiler Course – Day 5. Syntax Trees MathWorks Compiler Course – Day 5 Parser lexemes shift/reduce seq. Cfg tables Tree Symbols

• Syntax Trees – Construction– Walking– Tree Transformations

• Abstract Syntax Trees• Decorations

MathWorks Compiler Course – Day 5

Page 12: Syntax Trees MathWorks Compiler Course – Day 5. Syntax Trees MathWorks Compiler Course – Day 5 Parser lexemes shift/reduce seq. Cfg tables Tree Symbols

• Syntax Trees – Construction– Walking– Tree Transformations

• Abstract Syntax Trees• Decorations

– Attributes– Symbol Table Index

MathWorks Compiler Course – Day 5

Page 13: Syntax Trees MathWorks Compiler Course – Day 5. Syntax Trees MathWorks Compiler Course – Day 5 Parser lexemes shift/reduce seq. Cfg tables Tree Symbols

• Syntax Trees – Construction– Walking– Tree Transformations

• Abstract Syntax Trees• Decorations• Optimization

MathWorks Compiler Course – Day 5

Page 14: Syntax Trees MathWorks Compiler Course – Day 5. Syntax Trees MathWorks Compiler Course – Day 5 Parser lexemes shift/reduce seq. Cfg tables Tree Symbols

• Syntax Trees – Construction– Walking– Tree Transformations

• Abstract Syntax Trees• Decorations• Optimizations

– Constant evaluation– Code motion

MathWorks Compiler Course – Day 5

Page 15: Syntax Trees MathWorks Compiler Course – Day 5. Syntax Trees MathWorks Compiler Course – Day 5 Parser lexemes shift/reduce seq. Cfg tables Tree Symbols

• Syntax Trees

• Symbol Tables

MathWorks Compiler Course – Day 5

Page 16: Syntax Trees MathWorks Compiler Course – Day 5. Syntax Trees MathWorks Compiler Course – Day 5 Parser lexemes shift/reduce seq. Cfg tables Tree Symbols

• Symbol Table

MathWorks Compiler Course – Day 5

lexemes

shift/reduce seq.

Cfg tables

Tree

Symbols

syntax tree.

symbol table.

Generator

semantic actions.

Page 17: Syntax Trees MathWorks Compiler Course – Day 5. Syntax Trees MathWorks Compiler Course – Day 5 Parser lexemes shift/reduce seq. Cfg tables Tree Symbols

• Symbol Table– Frames

• Symbol frame• Runtime frame

MathWorks Compiler Course – Day 5

Page 18: Syntax Trees MathWorks Compiler Course – Day 5. Syntax Trees MathWorks Compiler Course – Day 5 Parser lexemes shift/reduce seq. Cfg tables Tree Symbols

• Symbol Table– Frames

• Symbol frame• Runtime frame

– temporary variables

MathWorks Compiler Course – Day 5

Page 19: Syntax Trees MathWorks Compiler Course – Day 5. Syntax Trees MathWorks Compiler Course – Day 5 Parser lexemes shift/reduce seq. Cfg tables Tree Symbols

• Symbol Table– Frames– Scope

• not in xcom

MathWorks Compiler Course – Day 5

Page 20: Syntax Trees MathWorks Compiler Course – Day 5. Syntax Trees MathWorks Compiler Course – Day 5 Parser lexemes shift/reduce seq. Cfg tables Tree Symbols

• Symbol Table– Frames– Scope– Variable Attributes

• Use– Left/Right

MathWorks Compiler Course – Day 5

Page 21: Syntax Trees MathWorks Compiler Course – Day 5. Syntax Trees MathWorks Compiler Course – Day 5 Parser lexemes shift/reduce seq. Cfg tables Tree Symbols

• Symbol Table– Frames– Scope– Variable Attributes

• Use• Type constraints

– All -- logical | integer | real (nothing excluded)– Arithmetic -- integer | real– None -- 0 (nothing allowed)

MathWorks Compiler Course – Day 5

Page 22: Syntax Trees MathWorks Compiler Course – Day 5. Syntax Trees MathWorks Compiler Course – Day 5 Parser lexemes shift/reduce seq. Cfg tables Tree Symbols

• Symbol Table– Frames– Scope– Variable Attributes– Look-up

• Linear• Hash

MathWorks Compiler Course – Day 5

Page 23: Syntax Trees MathWorks Compiler Course – Day 5. Syntax Trees MathWorks Compiler Course – Day 5 Parser lexemes shift/reduce seq. Cfg tables Tree Symbols

• Symbol Table– Frames– Scope– Variable Attributes– Look-up– Inference

• passes

MathWorks Compiler Course – Day 5