Compilers and computer architecture From strings to ASTs (2): context free grammars
Martin Berger 1 October 2019
1Email: M.F.Berger@sussex.ac.uk, Office hours: Wed 12-13 in
Chi-2R312
1 / 1
Compilers and computer architecture From strings to ASTs (2): - - PowerPoint PPT Presentation
Compilers and computer architecture From strings to ASTs (2): context free grammars Martin Berger 1 October 2019 1 Email: M.F.Berger@sussex.ac.uk , Office hours: Wed 12-13 in Chi-2R312 1 / 1 Recall the function of compilers 2 / 1 Recall we
1Email: M.F.Berger@sussex.ac.uk, Office hours: Wed 12-13 in
1 / 1
2 / 1
Lexical analysis Syntax analysis Source program Semantic analysis, e.g. type checking Intermediate code generation Optimisation Code generation Translated program
3 / 1
4 / 1
T_while T_greater T_var ( n ) T_num ( 0 ) T_semicolon T_decrement T_var ( n ) T_update T_var ( res ) T_mult T_var ( res ) T_num ( 2 )
5 / 1
6 / 1
7 / 1
8 / 1
9 / 1
10 / 1
11 / 1
12 / 1
◮ l is a variable, i.e. l ∈ V. ◮ r is a string (possibly empty) over the new alphabet A ∪ V.
13 / 1
14 / 1
15 / 1
16 / 1
17 / 1
18 / 1
19 / 1
20 / 1
21 / 1
22 / 1
23 / 1
24 / 1
25 / 1
26 / 1
27 / 1
28 / 1
29 / 1
30 / 1
31 / 1
32 / 1
33 / 1
34 / 1
35 / 1
E E + E E * E 4 17 3
36 / 1
37 / 1
E E + E E * E 4 17 3
38 / 1
39 / 1
40 / 1
41 / 1
E E + E E * E 4 17 3 E E * E 4 + E 3 E 17
42 / 1
43 / 1
44 / 1
45 / 1
46 / 1
47 / 1
48 / 1
49 / 1
50 / 1
51 / 1
if B if Q P B' if B if Q P B' 52 / 1
53 / 1