CS435 Compiler Tools
Interactive tools for CS435: regular expressions, finite automata, scanners, and the rest of the compiler pipeline.
- Source
- Lexical analysis 8 tools
- Syntax analysis 8 tools
- Semantic analysis
- Intermediate code
- Code generation
- Target
The big picture
Compilers, interpreters, and how they are built
- C- Compiler Write a C- program and follow it through scanning, parsing, semantic analysis, three-address code, and TINY Machine code, then run it. Lecture reference: Intro (cont’d): Compiler architecture Lecture reference: Introduction to Parsing Lecture reference: Ambiguity, Precedence, Associativity & Top-Down Parsing Lecture reference: Intro: Compilers, interpreters, and language processors
- Compiler Phases Follow a statement through scanning, parsing, type checking, three-address code, optimization, and code generation. Lecture reference: Intro (cont’d): Compiler architecture Lecture reference: Intro (cont’d): Compiler structure with examples Lecture reference: Lexical Analysis
- T-Diagrams Compose compilers drawn as T-diagrams to model cross compilers, retargeting, and bootstrapping. Lecture reference: Intro (cont’d): Preprocessors, bootstrapping, history
Lexical analysis
Characters → tokens
- Regular Expressions Parse a regular expression, see its structure, list the strings it denotes, and test or compare strings and expressions. Lecture reference: Lexical Analysis Lecture reference: Lexical Analysis II
- Finite Automata Draw or load a DFA or NFA, check whether it is deterministic, and run strings through it step by step. Lecture reference: Lexical Analysis III
- Thompson's Construction Build an NFA from a regular expression one fragment at a time. Lecture reference: Lexical Analysis IV
- Subset Construction Convert an NFA to a DFA using ε-closures, one table row at a time. Lecture reference: Lexical Analysis III Lecture reference: Lexical Analysis IV
- DFA Minimization Merge equivalent DFA states by partition refinement and find strings that tell two states apart. Lecture reference: Lexical Analysis IV
- Scanner Rules Write token rules as regular expressions and watch maximal munch split an input into (token, lexeme) pairs. Lecture reference: Lexical Analysis II Lecture reference: Lexical Analysis Lecture reference: Intro (cont’d): Compiler structure with examples
- Scanner DFAs Run a scanner's DFA from its transition table with the table-driven loop, or as hand-coded switch statements. Lecture reference: Lexical Analysis IV Lecture reference: Lexical Analysis II
- Flex Playground Run a flex specification on sample input in the browser and step through each match yylex() makes. Lecture reference: Lexical Analysis III (cont’d)
Syntax analysis
Tokens → parse trees
- Context-Free Grammars Write a grammar, derive strings one replacement at a time, and see the parse tree each derivation defines. Lecture reference: Introduction to Parsing
- Ambiguity and Precedence List every parse tree of a string, then remove the ambiguity by rewriting the grammar or by declaring precedence and associativity. Lecture reference: Ambiguity, Precedence, Associativity & Top-Down Parsing
- Recursive Descent with Backtracking Step through recursive-descent parsing as it tries each production in order, matches tokens, and backtracks. Lecture reference: Top-Down Parsing
- Predictive Recursive Descent Rewrite a grammar with EBNF so one token of lookahead picks each rule, then run the generated recursive-descent parser. Lecture reference: Top-Down Parsing Lecture reference: Top-Down Parsing
- LL(1) Parsing Table Compute First and Follow sets, build the LL(1) parsing table of a grammar, rewrite a grammar that is not LL(1), and trace the table-driven parser on a token string. Lecture reference: Table-based Predictive Parsing Lecture reference: Table-based Predictive Parsing
- Shift-Reduce Parsing Parse a token string bottom-up with the LR(1) table of a grammar: the shift-reduce trace with its divider, the parse tree growing over the tokens, and the handle of every reduction. Lecture reference: Bottom-Up Parsing Lecture reference: Bottom-up Parsing II
- LR(1) Parser Builder Build the LR(1) parsing DFA of a grammar with Closure and Transition, fill in its action/goto table, and run the LR parsing algorithm on a token string. Lecture reference: Bottom-up Parsing II Lecture reference: Bottom-up Parsing III
- Conflicts & Precedence List the shift/reduce and reduce/reduce conflicts of an LR(1) table, settle them with bison’s %left, %right and %nonassoc, compare the parse trees, and read the Parser.output bison writes. Lecture reference: Bottom-up Parsing III Lecture reference: Bottom-up Parsing III
Execution
Machines that run the result
Reference
Symbols and conventions shared by the tools, and the midterm review list