Browse Source

Finish syntaxic analysis

Arnaud Vergnet 3 years ago
parent
commit
ee4ec4f3f9
3 changed files with 17 additions and 2 deletions
  1. 5
    0
      .gitignore
  2. 8
    1
      as.y
  3. 4
    1
      test.c

+ 5
- 0
.gitignore View File

@@ -0,0 +1,5 @@
1
+as.tab.c
2
+as.tab.h
3
+compilateur
4
+lex.yy.c
5
+

+ 8
- 1
as.y View File

@@ -60,12 +60,19 @@ Body : tAO Instructions tAF ;
60 60
 
61 61
 Instructions : Instruction Instructions | ;
62 62
 
63
-Instruction : Aff | Printf  | If ;
63
+Instruction : Aff | Printf  | If | Declaration ;
64 64
 
65 65
 Aff : tID tEQ E tPV ;
66 66
 
67 67
 E : tNB | tID | E tADD E | E tMUL E | E tSUB E | E tDIV E | tPO E tPF | tSUB E ;
68 68
 
69
+DeclarationBody : tID tVIRG DeclarationBody | tID ;
70
+
71
+DeclarationInt : tINT DeclarationBody tPV ;
72
+
73
+DeclarationConst : tCONST DeclarationBody tPV ;
74
+
75
+Declaration : DeclarationInt | DeclarationConst ;
69 76
 
70 77
 If : IfSimple | IfElse ;
71 78
 

+ 4
- 1
test.c View File

@@ -1,7 +1,10 @@
1 1
 int main(){
2
-    x = 3 + 6;
2
+    int x, y, z;
3
+    const PL5_op, b, c;
3 4
     printf(x);
4 5
     if (x == x && y != 5 + 6 || 1 + 2 == 2 + 1 && !(x == x)) {
5 6
         printf(x);
7
+    } else {
8
+        x = 3 + 2;
6 9
     }
7 10
 }

Loading…
Cancel
Save