Compiler Design
Spring 2018
3.5 Limitations of context-free grammars 4.0 Semantic analysis
1
Compiler Design Spring 2018 3.5 Limitations of context-free - - PowerPoint PPT Presentation
Compiler Design Spring 2018 3.5 Limitations of context-free grammars 4.0 Semantic analysis Thomas R. Gross Computer Science Department ETH Zurich, Switzerland 1 Context-free grammars Efficient parsers exist for context-free languages
1
2
3
§ Some kinds of errors can be detected only at runtime
4
5
6
7
9
10
11
12
13
14
15
16
§ After parsing § Before code generation
17
§ “The food is here!” vs. “The food is here?”
18
19
§ Type casts § Add default parameters to method/function calls § Construct initializer
20
21
22
§ Value obtained from attributes of children of non-terminal
§ Value obtained from attribute of parent of non-terminal § Or from attribute(s) of sibling(s) of non-terminal
23
25
27
28
29
30
32
34
35
36
37
38
39
40
42
44
class A { int a, n; int foo (int j) { int k, n; a = j * 2; return n + 1; } } class B { int a, j; void bar (int j) { … } }
45
48
§ Size (bytes) § Location (offset from ’this’ reference) § Alignment constraints
§ Location of code
§ Location: Absolute in a segment
50
§ Size in bytes § Alignment constraints § Location (offset from frame pointer)
51
52
53
§ Can go into method symbol tables § Can go into class symbol tables
54
56
boolean constant