You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Each production is associated with a **semantic actions**. This semantic actions will be generated when the production is matched by the parser.
9
+
10
+
11
+
## Backpatching
12
+
When generating code for boolean expressions and flow-of-control statements is that of matching a jump instruction with the target of the jump. For example, the translation of the boolean expression B in **if ( B ) S**, the target of the jump when **B** is false will not be declared until **S** is examined. In a
13
+
one-pass translation, the problem is solved by passing labels as inherited attributes to where the relevant jump instructions were generated. But a separate pass is then needed to bind labels to addresses.
14
+
15
+
***Backpatching*** counters the problem of two-passes translation by having lists of jumps are passed as synthesized attributes. Specifically, when a jump
16
+
is generated, the target of the jump is temporarily left unspecified. Each such jump is put on a list of jumps whose labels are to be filled in when the proper
17
+
label can be determined.
18
+
19
+
20
+
## Assumptions
21
+
### Java Used Grammar
22
+
The input programs we are dealing with follow the below rules. These aren't a full java grammar but a subset of it.
23
+
24
+
```
25
+
method_body:
26
+
%empty
27
+
|statement_list
28
+
;
29
+
30
+
statement_list:
31
+
statement
32
+
|statement_list statement
33
+
;
34
+
35
+
statement:
36
+
declaration
37
+
|if
38
+
|while
39
+
|assignment
40
+
;
41
+
42
+
declaration: primitive_type IDENTIFIER ';';
43
+
44
+
primitive_type:
45
+
INT
46
+
|FLOAT
47
+
;
48
+
49
+
if:
50
+
IF '(' boolean_expression ')'
51
+
'{' statement_list '}'
52
+
ELSE '{' statement_list '}'
53
+
;
54
+
55
+
while:
56
+
WHILE '(' boolean_expression ')'
57
+
'{' statement_list '}'
58
+
;
59
+
60
+
assignment: IDENTIFIER '=' expression ';';
61
+
62
+
expression:
63
+
INT_NUM
64
+
|FLOAT_NUM
65
+
|IDENTIFIER
66
+
|expression ARITH_OP expression
67
+
|'(' expression ')'
68
+
;
69
+
70
+
boolean_expression:
71
+
TRUE
72
+
|FALSE
73
+
|expression BOOL_OP expression
74
+
|expression REL_OP expression
75
+
```
76
+
7
77
## Running & Testing
8
78
9
79
To run the program, use the script `run.sh` as follows:
0 commit comments