02Chapter 2: Tokens, lexemes, and patternsThis chapter defines the three terms the lexical analyzer (lexer) is built on. It assumes you know basic regular expressions and have read the previous chapter on compiler phases. Later chapters build on it: regular expressions, automata, and the lexer implementation.4 min read
03Chapter 3: Specifying tokens with regular expressionsThis chapter assumes you know what a token, lexeme and pattern are (the previous chapter) and have seen basic set notation and string concatenation. Here you learn the notation used to write token patterns precisely, and the mistakes that make a pattern accept the wrong lexemes.3 min read
04Chapter 4: NFAs and DFAs as token recognizersThis chapter assumes you know basic set notation, can read a state-transition diagram, and have met regular expressions. The previous chapters defined tokens and wrote patterns for them. Here we turn those patterns into machines that decide whether a string of characters is a lexeme of a given token3 min read
05Chapter 5: From regular expression to NFA to DFAThis chapter assumes you know what a regular expression, an NFA and a DFA are, and that you can read a transition table. It shows the pipeline a lexer generator follows: a regular expression becomes an NFA, the NFA becomes a DFA, and the DFA gets minimized.4 min read
06Chapter 6: Building a lexer: maximal munch, rule priority, and lexical errorsThis chapter assumes you know regular expressions, NFAs and DFAs, and the idea of a token, a lexeme and a pattern from earlier chapters. Here you turn a set of token patterns into a working scanner and learn the rules that settle conflicts between patterns.5 min read
07Chapter 7: Context-free grammarsA context-free grammar (CFG) is the notation a compiler uses to describe the structure of a program. This chapter assumes you know regular expressions, basic set notation, and recursion. It also assumes you have seen the idea of a pushdown automaton. The goal is to read a grammar, say what language 4 min read
08Chapter 8: Leftmost and rightmost derivations and parse treesThis chapter assumes you can read a context-free grammar (CFG): a set of productions, a start symbol, nonterminals, and terminals. It also assumes you know what a stack and a tree are. Here you learn how a string is generated from the start symbol, how the choices made during generation are recorded5 min read
09Chapter 9: Ambiguity and how to resolve itThis chapter assumes you can write a context-free grammar, derive strings from it, and draw a parse tree. It builds on leftmost and rightmost derivations. The goal is to recognize an ambiguous grammar, show that it is ambiguous, and fix it in the ways GATE questions expect.5 min read
10Chapter 10: Removing left recursion and left factoringThis chapter assumes you can read a context-free grammar, expand a derivation, and compute FIRST and FOLLOW sets. It covers the two grammar rewrites that make a grammar usable by a top-down parser.4 min read
11Chapter 11: Computing FIRST and FOLLOWThis chapter assumes you can read a context-free grammar, know what a terminal and a nonterminal are, and can write a derivation. It also assumes you are comfortable with set union and set difference. FIRST and FOLLOW feed the LL(1) table in the next chapter and the SLR(1) reduce actions later on.4 min read
12Chapter 12: LL(1) grammars and predictive parsing tablesThis chapter assumes you can compute FIRST and FOLLOW sets and can remove left recursion and left-factor a grammar. It shows how those sets become a parsing table, how a table-driven parser uses it, and how to tell when a grammar is not LL(1).4 min read
13Chapter 13: Recursive descent parsersThis chapter assumes you can compute FIRST and FOLLOW sets and fill an LL(1) table, and that you are comfortable reading short Python. A recursive descent parser is a top-down parser written as ordinary code. It has one function per nonterminal, and the call stack plays the role of the parse stack i3 min read
14Chapter 14: Shift-reduce parsing and handlesThis chapter assumes you know context-free grammars, derivations, and parse trees. It also assumes you are comfortable with stacks. The main idea is that a bottom-up parser builds a parse tree from the leaves up. It does this by tracing a rightmost derivation backwards.4 min read
15Chapter 15: LR(0) item sets and SLR(1) tablesThis chapter assumes you know FIRST and FOLLOW sets, derivations, and how a shift-reduce parser uses a stack. It shows how to build the table that tells such a parser when to shift and when to reduce.5 min read
16Chapter 16: CLR(1) and LALR(1) parsersThis chapter assumes you can build LR(0) item sets, compute FIRST and FOLLOW, and fill an SLR(1) table. SLR(1) uses FOLLOW(A) as the lookahead set for every reduction by A -> α. That is too coarse, and CLR(1) and LALR(1) fix it by tracking lookaheads more precisely.4 min read
17Chapter 17: Conflicts and the power hierarchy of parsersThis chapter assumes you can build LR(0) item sets, compute FIRST and FOLLOW, and fill an SLR(1) table. It covers what a conflict is, why the four LR variants differ in how many conflicts they report, and how LL(1) relates to them. GATE asks for this in two forms: "is this grammar SLR(1), LALR(1), b4 min read
18Chapter 18: Operator precedence parsingThis chapter assumes you know what a shift-reduce parser is (stack, input, shift, reduce, handle) and how FIRST and FOLLOW sets are built. Operator precedence parsing is a bottom-up method that decides between shift and reduce by comparing only the terminals. GATE CS asks you to fill in precedence t4 min read
19Chapter 19: Syntax error detection and recoveryThis chapter assumes you can build an LL(1) table and an LR ACTION/GOTO table, and that you know FIRST and FOLLOW sets. It covers how those parsers notice a bad input, and how they continue so that one mistake does not hide every later one.3 min read
20Chapter 20: Syntax-directed definitions: synthesized and inherited attributesThis chapter assumes you can read a context-free grammar, draw a parse tree, and trace a derivation. It also assumes you know what a symbol table is. Later chapters cover dependency graphs, S-attributed and L-attributed classes, and translation schemes. Here we only define attributes and learn to te4 min read
21Chapter 21: Dependency graphs, S-attributed and L-attributed definitionsThis chapter assumes you know what synthesized and inherited attributes are, how a parse tree is built, and how LL(1) and LR parsers read input. It covers the order in which attribute values can be computed and which kinds of definition a one-pass parser can evaluate.4 min read
23Chapter 23: Applications: expression evaluation, postfix output, and syntax treesThis chapter assumes you know context-free grammars, LR and LL(1) parsing, and the difference between synthesized and inherited attributes. It applies those ideas to three standard uses of syntax-directed translation (SDT): computing a value, emitting postfix code, and building a syntax tree. Each u5 min read