-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_example.c
More file actions
55 lines (46 loc) · 937 Bytes
/
Copy pathbasic_example.c
File metadata and controls
55 lines (46 loc) · 937 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
* basic_example.c
*
* Arquivo de exemplo para demonstrar o funcionamento completo do compilador:
* - Função de soma
* - Controle de fluxo (for, while, if/else, switch)
*
* Serve como caso de teste para as fases de análise léxica,
* análise sintática, análise semântica e geração de código assembly.
*/
int soma(int x, int y) {
return x + y;
}
int main() {
int a = 0;
int b = 5;
int c;
for (int i = 0; i < 10; i = i + 1) {
if (i % 2 == 0) {
continue;
}
if (i == 7) {
break;
}
a = a + i;
}
while (a < 30) {
a = a + 1;
}
if (a > b && b < 10) {
c = soma(a, b);
} else {
c = a - b;
}
switch (c) {
case 5:
c = c + 10;
break;
case 10:
c = c + 20;
break;
default:
c = 0;
}
return c;
}