Raw input, a given: { fact = 1; i = 1; while (i < 7) do { fact = (fact * i); i = (i + 1) } print f } First stage: seems trivial but it's important '{', ' ', 'f', 'a', 'c', 't', ' ', '=', '1', ';', ' ', 'i', ' ', '=', ..., '}', EOF Second stage: "{", punctuation, 0 "fact", identifier, 0 "=", operator, 0 "1", number, 1 ... "while", reserved_word, 0 ... "^D", end_of_file, 0 Lexical analysis Third stage: Parsing ------------------------- | block | | | | | | | | | ----------|---|---|---|-- | | | | | | | v | | | ------------- v v | | print | | | | ----------|-- . . | | . . | v . . | --------------------- | | variable | "fact" | | --------------------- v ----------------- | while | | | | | ----------|---|-- | v ----------------- | block | | | | | ----------|---|-- | | | | | v | | . | . | . | v --------------------------- | assignment | "fact" | | | ------------------------|-- v ---------------------------- | expression | "*" | | | | | ---------------------|---|-- | | | | | | v v Fourth stage, could be compilation: turn that into assembly language, or could be interpretation: a big recursive function that does what the tree says.