Syntax Analysis

CFG $G$ is 4-tuple of:

$V = V_t \cup V_n$ is vocabulary

If $S \rightarrow^* \beta$, $\beta$ is a sentential form of $S$

Backus-Naur form (BNF):

  1. Non-terminals with angle brackets or capital letters
  2. Terminals with code font or underline

Scanning vs. Parsing

We use REs for numbers, keywords, etc.

However, grammars are used for parsing (brackets, if-else, etc.)

Derivations

Leftmost derivation: left-most nonterminal replaced at each step

Rightmost: respective

Precendence

We can introduce extra non-terminals (and derivations) to ensure an appropriate order.