The big picture

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 · slide 4
  • Lecture reference: Introduction to Parsing · slide 31
  • Lecture reference: Ambiguity, Precedence, Associativity & Top-Down Parsing · slide 2
  • Lecture reference: Intro: Compilers, interpreters, and language processors · slides 14–17

The program compiled.

Lecture reference: Intro (cont’d): Compiler architecture · slide 4

Source

Tab inserts a tab. Press Escape, then Tab, to move focus out of the editor.

The numbers input() reads, in order, separated by spaces or line breaks.

Language options
Identifiers

ID = letter letter*, as the language defines it: x1 is ID x, NUM 1.

Compilation

Nothing is selected. A token, a tree node, a symbol, a quad, an instruction or the caret in the source selects a piece of the program; every view then marks what belongs to it.

69 tokens, then ENDFILE. White space and 1 comment produce no token.

Tokens in source order
Line:colTokenLexemeValue
5:1 "int"
5:5 "gcd"
5:8 "("
5:9 "int"
5:13 "u"
5:14 ","
5:16 "int"
5:20 "v"
5:21 ")"
6:1 "{"
7:3 "if"
7:6 "("
7:7 "v"
7:9 "=="
7:12 "0"0
7:13 ")"
8:5 "return"
8:12 "u"
8:13 ";"
9:3 "return"
9:10 "gcd"
9:13 "("
9:14 "v"
9:15 ","
9:17 "u"
9:19 "-"
9:21 "u"
9:23 "/"
9:25 "v"
9:27 "*"
9:29 "v"
9:30 ")"
9:31 ";"
10:1 "}"
12:1 "void"
12:6 "main"
12:10 "("
12:11 "void"
12:15 ")"
13:1 "{"
14:3 "int"
14:7 "a"
14:8 ";"
15:3 "int"
15:7 "b"
15:8 ";"
16:3 "a"
16:5 "="
16:7 "input"
16:12 "("
16:13 ")"
16:14 ";"
17:3 "b"
17:5 "="
17:7 "input"
17:12 "("
17:13 ")"
17:14 ";"
18:3 "output"
18:9 "("
18:10 "gcd"
18:13 "("
18:14 "a"
18:15 ","
18:17 "b"
18:18 ")"
18:19 ")"
18:20 ";"
19:1 "}"
20:1ENDFILE ""