CSS Prepare

optional · CSS study notes

Syntax Analysis (Parsing)

  • Context-Free Grammar (CFG): the formal grammar type used to define a programming language's valid syntax structure (production rules)
  • Top-down parsers: build the parse tree from the root downward, predicting productions (e.g., LL(k) parsers — read Left-to-right, use Leftmost derivation, k lookahead tokens)
  • Bottom-up parsers: build the parse tree from the leaves upward toward the root (e.g., LR(k) parsers — read Left-to-right, use Rightmost derivation in reverse, k lookahead) — LR parsers are generally more powerful than LL parsers
  • FIRST and FOLLOW sets: FIRST(X) = set of terminals that can begin a string derived from X; FOLLOW(X) = set of terminals that can immediately follow X
  • Predictive Parsing (LL(1)): decides which production to use by looking at only one lookahead token, using a precomputed parsing table — requires the grammar to be unambiguous and free of left recursion
  • Syntax error handling/recovery: panic-mode, phrase-level, and error-productions strategies

MCQ Trap

  • LL parsers are top-down; LR parsers are bottom-up.