Compiler construction
Martin Steffen February 1, 2017
Contents
1 Abstract 1 1.1 Grammars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.1.2 Context-free grammars and BNF notation . . . . . . . . . . . . . . . . . . . . . . . . 3 1.1.3 Ambiguity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 1.1.4 Syntax diagrams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 1.1.5 Chomsky hierarchy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 1.1.6 Syntax of Tiny . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 2 Reference 20
1 Abstract
Abstract This is the handout version of the slides. It contains basically the same content, only in a way which allows more compact printing. Sometimes, the overlays, which make sense in a presentation, are not fully rendered here. Besides the material of the slides, the handout versions may also contain additional remarks and background information which may or may not be helpful in getting the bigger picture.
1.1 Grammars
- 30. 1. 2017
1.1.1 Introduction Bird’s eye view of a parser
sequence
- f tokens
Parser
tree repre- sentation
- check that the token sequence correspond to a syntactically correct program
– if yes: yield tree as intermediate representation for subsequent phases – if not: give understandable error message(s)
- we will encounter various kinds of trees
– derivation trees (derivation in a (context-free) grammar) – parse tree, concrete syntax tree – abstract syntax trees
- mentioned tree forms hang together, dividing line a bit fuzzy
- result of a parser: typically AST