Browse Source

Table des symboles ok, start expressions arithm

Foussats Morgane 3 years ago
parent
commit
22d9a82ba6
11 changed files with 921 additions and 833 deletions
  1. 0
    13
      Table_Symboles/main.c
  2. BIN
      a.out
  3. 582
    580
      analyse_syntaxique.output
  4. 203
    194
      analyse_syntaxique.tab.c
  5. 19
    9
      analyse_syntaxique.y
  6. 0
    0
      gen_assembleur.c
  7. 21
    0
      gen_assembleur.h
  8. 18
    0
      poubelle/test.c
  9. 3
    6
      script.sh
  10. 52
    24
      table_symboles.c
  11. 23
    7
      table_symboles.h

+ 0
- 13
Table_Symboles/main.c View File

@@ -1,13 +0,0 @@
1
-#include <stdio.h>
2
-#include "table_symboles.h"
3
-
4
-int main() {
5
-    Table_Symboles T;
6
-    initialise_table(&T);
7
-    add_symbole_top(&T, "toto", 0, 1);
8
-    add_symbole_top(&T, "titi", 1, 0);
9
-    add_symbole_bottom(&T, "titi", 0, 1);
10
-    print_table(&T);
11
-
12
-    return 0;
13
-}

BIN
a.out View File


+ 582
- 580
analyse_syntaxique.output
File diff suppressed because it is too large
View File


+ 203
- 194
analyse_syntaxique.tab.c View File

@@ -162,8 +162,13 @@ int yyparse (void);
162 162
 #line 6 "analyse_syntaxique.y" /* yacc.c:358  */
163 163
 
164 164
 #include <stdio.h>
165
+#include "table_symboles.h"
165 166
 
166
-#line 167 "analyse_syntaxique.tab.c" /* yacc.c:358  */
167
+enum Initialised_Variable init;
168
+enum Symbole_Type type;
169
+Table_Symboles table;
170
+
171
+#line 172 "analyse_syntaxique.tab.c" /* yacc.c:358  */
167 172
 
168 173
 #ifdef short
169 174
 # undef short
@@ -405,14 +410,14 @@ union yyalloc
405 410
 /* YYFINAL -- State number of the termination state.  */
406 411
 #define YYFINAL  4
407 412
 /* YYLAST -- Last index in YYTABLE.  */
408
-#define YYLAST   132
413
+#define YYLAST   133
409 414
 
410 415
 /* YYNTOKENS -- Number of terminals.  */
411 416
 #define YYNTOKENS  35
412 417
 /* YYNNTS -- Number of nonterminals.  */
413
-#define YYNNTS  24
418
+#define YYNNTS  23
414 419
 /* YYNRULES -- Number of rules.  */
415
-#define YYNRULES  54
420
+#define YYNRULES  53
416 421
 /* YYNSTATES -- Number of states.  */
417 422
 #define YYNSTATES  125
418 423
 
@@ -463,12 +468,12 @@ static const yytype_uint8 yytranslate[] =
463 468
   /* YYRLINE[YYN] -- Source line where rule number YYN was defined.  */
464 469
 static const yytype_uint8 yyrline[] =
465 470
 {
466
-       0,    63,    63,    65,    66,    68,    71,    72,    75,    77,
467
-      78,    80,    81,    82,    83,    84,    85,    87,    89,    90,
468
-      92,    93,    95,    96,    98,   100,   102,   103,   104,   105,
469
-     106,   107,   108,   109,   110,   112,   113,   115,   116,   118,
470
-     120,   121,   123,   125,   126,   127,   128,   129,   130,   131,
471
-     132,   133,   135,   137,   139
471
+       0,    68,    68,    70,    71,    73,    76,    77,    80,    82,
472
+      83,    85,    86,    87,    88,    89,    90,    92,    94,    95,
473
+      97,    98,   100,   101,   104,   106,   107,   108,   109,   110,
474
+     111,   112,   113,   114,   117,   118,   120,   121,   123,   125,
475
+     126,   128,   130,   131,   132,   133,   134,   135,   136,   137,
476
+     138,   140,   142,   144
472 477
 };
473 478
 #endif
474 479
 
@@ -483,8 +488,8 @@ static const char *const yytname[] =
483 488
   "tINT", "tPRINT", "tRETURN", "tOR", "tAND", "tIF", "tELSE", "tWHILE",
484 489
   "tCONST", "tVAR", "tNOT", "$accept", "Main", "Params", "Param",
485 490
   "SuiteParams", "Body", "Instructions", "Instruction", "Decl",
486
-  "SuiteDecl", "Type", "Valeur", "Affbis", "Aff", "E", "Args", "SuiteArgs",
487
-  "If", "Else", "While", "Cond", "Invocation", "Print", "Return", YY_NULLPTR
491
+  "SuiteDecl", "Type", "Valeur", "Aff", "E", "Args", "SuiteArgs", "If",
492
+  "Else", "While", "Cond", "Invocation", "Print", "Return", YY_NULLPTR
488 493
 };
489 494
 #endif
490 495
 
@@ -500,10 +505,10 @@ static const yytype_uint16 yytoknum[] =
500 505
 };
501 506
 # endif
502 507
 
503
-#define YYPACT_NINF -36
508
+#define YYPACT_NINF -35
504 509
 
505 510
 #define yypact_value_is_default(Yystate) \
506
-  (!!((Yystate) == (-36)))
511
+  (!!((Yystate) == (-35)))
507 512
 
508 513
 #define YYTABLE_NINF -1
509 514
 
@@ -514,19 +519,19 @@ static const yytype_uint16 yytoknum[] =
514 519
      STATE-NUM.  */
515 520
 static const yytype_int8 yypact[] =
516 521
 {
517
-      -7,    -4,    26,    18,   -36,     9,    12,    40,    36,   -36,
518
-      50,     9,   -36,    54,   -36,    36,   -36,    55,    68,    79,
519
-      39,    -2,    63,    54,   -36,    60,    80,   -36,   -36,   -36,
520
-      81,   -36,    82,    64,    15,    15,   -36,    65,    19,    19,
521
-      88,   -36,    86,    89,   -36,   -36,   -36,   -36,    93,   -36,
522
-      19,    19,    96,    15,    48,    97,   -36,    99,    91,   100,
523
-      24,    66,   -36,    60,    98,   101,     1,    52,   -36,    19,
524
-      19,    19,    19,    19,    19,    19,    19,    19,    19,    15,
525
-      15,   102,   103,    78,   -36,   -36,   -36,    89,   -36,   -36,
526
-     -36,     5,     1,   108,   -36,    24,    24,    24,    24,    24,
527
-      24,   -36,   -36,    54,    54,    91,   -36,   105,   106,   -36,
528
-      90,   -36,    -6,   -36,    54,   110,   109,    15,   -36,   112,
529
-     113,    54,   111,    90,   -36
522
+      -3,   -12,    31,    34,   -35,    20,    25,    50,    44,   -35,
523
+      57,    20,   -35,    46,   -35,    44,   -35,    52,    60,    65,
524
+      56,    -4,    58,    46,   -35,    43,   -35,   -35,   -35,    69,
525
+     -35,    79,    61,    14,    14,   -35,    63,    16,    16,    85,
526
+     -35,    82,    91,   -35,   -35,    90,   -35,    16,    16,    98,
527
+      14,    45,    99,   -35,   100,   101,   102,    81,    97,   -35,
528
+      16,    43,   103,   104,     8,    22,   -35,    16,    16,    16,
529
+      16,    16,    16,    16,    16,    16,    16,    14,    14,   108,
530
+     109,    80,   -35,   -35,   -35,   -35,    49,    91,   -35,   -35,
531
+     -35,     1,     8,   106,   -35,    49,    49,    49,    49,    49,
532
+      49,   -35,   -35,    46,    46,   101,   -35,   110,   111,   -35,
533
+      94,   -35,    -5,   -35,    46,   112,   113,    14,   -35,   105,
534
+     115,    46,   116,    94,   -35
530 535
 };
531 536
 
532 537
   /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
@@ -536,33 +541,33 @@ static const yytype_uint8 yydefact[] =
536 541
 {
537 542
        0,     0,     0,     0,     1,     3,     0,     0,     7,     5,
538 543
        0,     0,     4,    10,     2,     7,    20,     0,     0,     0,
539
-       0,     0,     0,    10,    15,     0,     0,    11,    12,    13,
540
-       0,    14,     0,     0,     0,     0,    21,    36,     0,     0,
541
-       0,     9,    22,    19,    23,    25,    16,     6,     0,    26,
542
-       0,     0,    27,     0,     0,     0,    32,     0,    38,     0,
543
-      24,     0,     8,     0,     0,     0,    34,     0,    51,     0,
544
+       0,     0,     0,    10,    15,     0,    11,    12,    13,     0,
545
+      14,     0,     0,     0,     0,    21,    35,     0,     0,     0,
546
+       9,    23,    19,    16,     6,     0,    25,     0,     0,    26,
547
+       0,     0,     0,    32,     0,    37,     0,     0,     0,     8,
548
+       0,     0,     0,     0,    31,     0,    50,     0,     0,     0,
544 549
        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
545
-       0,     0,     0,     0,    35,    52,    54,    19,    17,    53,
546
-      33,    28,    30,    29,    31,    43,    44,    45,    46,    48,
547
-      47,    50,    49,    10,    10,    38,    18,     0,     0,    37,
548
-       0,    42,     0,    39,    10,     0,     0,     0,    40,     0,
549
-       0,    10,     0,     0,    41
550
+       0,     0,    34,    51,    24,    53,    22,    19,    17,    52,
551
+      33,    27,    29,    28,    30,    42,    43,    44,    45,    47,
552
+      46,    49,    48,    10,    10,    37,    18,     0,     0,    36,
553
+       0,    41,     0,    38,    10,     0,     0,     0,    39,     0,
554
+       0,    10,     0,     0,    40
550 555
 };
551 556
 
552 557
   /* YYPGOTO[NTERM-NUM].  */
553 558
 static const yytype_int8 yypgoto[] =
554 559
 {
555
-     -36,   -36,   -36,   114,   115,   -36,   -22,   -36,   -36,    41,
556
-     -36,    69,   -19,   -36,   -35,   -36,    21,   -36,     4,   -36,
557
-     -33,   -13,   -36,   -36
560
+     -35,   -35,   -35,   118,   117,   -35,   -22,   -35,   -35,    40,
561
+     -35,    70,   -35,   -34,   -35,    28,   -35,     7,   -35,   -32,
562
+     -13,   -35,   -35
558 563
 };
559 564
 
560 565
   /* YYDEFGOTO[NTERM-NUM].  */
561 566
 static const yytype_int8 yydefgoto[] =
562 567
 {
563
-      -1,     2,     7,     8,    12,    14,    22,    23,    24,    64,
564
-      25,    43,    26,    27,    54,    59,    84,    28,   113,    29,
565
-      55,    56,    31,    40
568
+      -1,     2,     7,     8,    12,    14,    22,    23,    24,    62,
569
+      25,    42,    26,    51,    56,    82,    27,   113,    28,    52,
570
+      53,    30,    39
566 571
 };
567 572
 
568 573
   /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM.  If
@@ -570,38 +575,38 @@ static const yytype_int8 yydefgoto[] =
570 575
      number is the opposite.  If YYTABLE_NINF, syntax error.  */
571 576
 static const yytype_uint8 yytable[] =
572 577
 {
573
-      30,    41,    57,    60,    61,   114,    44,    37,    71,    72,
574
-      30,    70,    71,    72,    38,    66,    67,     1,    49,     3,
575
-      68,    50,    49,   115,    51,    50,     4,     5,    51,    69,
576
-      70,    71,    72,     6,    91,    92,    93,    94,    95,    96,
577
-      97,    98,    99,   100,    44,     9,   101,   102,    52,    53,
578
-      10,    11,    52,    69,    70,    71,    72,    69,    70,    71,
579
-      72,    13,    90,    36,    33,    73,    74,    75,    76,    77,
580
-      78,    69,    70,    71,    72,    79,    80,    34,    16,    17,
581
-      86,   107,   108,    18,   119,    19,    20,    21,    35,    39,
582
-      30,    30,   116,    42,    45,    46,    47,    48,    58,   122,
583
-      62,    30,    38,    65,    63,    37,    83,    81,    30,    82,
584
-      85,   105,    88,   103,   104,    89,    72,   110,   111,   117,
585
-     112,   118,   120,   123,   121,    15,   109,   124,   106,     0,
586
-      32,     0,    87
578
+      29,    40,    54,    57,    58,    36,   114,    68,    69,    70,
579
+      29,     3,    37,    64,    65,    69,    70,    46,    66,    46,
580
+      47,     1,    47,    48,   115,    48,    86,    67,    68,    69,
581
+      70,     4,    90,    91,    92,    93,    94,    95,    96,    97,
582
+      98,    99,   100,     5,     6,   101,   102,    49,    50,    49,
583
+      67,    68,    69,    70,    67,    68,    69,    70,     9,    11,
584
+      10,    32,    71,    72,    73,    74,    75,    76,    13,    33,
585
+      16,    17,    77,    78,    34,    18,    41,    19,    20,    21,
586
+      35,   107,   108,    43,    38,   119,    67,    68,    69,    70,
587
+      29,    29,   116,    44,    45,    84,    55,    59,    60,   122,
588
+      63,    29,    67,    68,    69,    70,    61,    36,    29,    79,
589
+      80,    85,    83,   105,    70,   120,    81,    88,    89,   103,
590
+     104,   117,   110,   111,   112,   118,   121,   106,   123,    15,
591
+     124,    87,    31,   109
587 592
 };
588 593
 
589
-static const yytype_int8 yycheck[] =
594
+static const yytype_uint8 yycheck[] =
590 595
 {
591
-      13,    23,    35,    38,    39,    11,    25,     9,     7,     8,
592
-      23,     6,     7,     8,    16,    50,    51,    24,     3,    23,
593
-      53,     6,     3,    29,     9,     6,     0,     9,     9,     5,
594
-       6,     7,     8,    24,    69,    70,    71,    72,    73,    74,
595
-      75,    76,    77,    78,    63,    33,    79,    80,    33,    34,
596
-      10,    15,    33,     5,     6,     7,     8,     5,     6,     7,
597
-       8,    11,    10,    24,     9,    17,    18,    19,    20,    21,
598
-      22,     5,     6,     7,     8,    27,    28,     9,    24,    25,
599
-      14,   103,   104,    29,   117,    31,    32,    33,     9,    26,
600
-     103,   104,   114,    33,    14,    14,    14,    33,    33,   121,
601
-      12,   114,    16,    10,    15,     9,    15,    10,   121,    10,
602
-      10,    33,    14,    11,    11,    14,     8,    12,    12,     9,
603
-      30,    12,    10,    12,    11,    11,   105,   123,    87,    -1,
604
-      15,    -1,    63
596
+      13,    23,    34,    37,    38,     9,    11,     6,     7,     8,
597
+      23,    23,    16,    47,    48,     7,     8,     3,    50,     3,
598
+       6,    24,     6,     9,    29,     9,    60,     5,     6,     7,
599
+       8,     0,    10,    67,    68,    69,    70,    71,    72,    73,
600
+      74,    75,    76,     9,    24,    77,    78,    33,    34,    33,
601
+       5,     6,     7,     8,     5,     6,     7,     8,    33,    15,
602
+      10,     9,    17,    18,    19,    20,    21,    22,    11,     9,
603
+      24,    25,    27,    28,     9,    29,    33,    31,    32,    33,
604
+      24,   103,   104,    14,    26,   117,     5,     6,     7,     8,
605
+     103,   104,   114,    14,    33,    14,    33,    12,    16,   121,
606
+      10,   114,     5,     6,     7,     8,    15,     9,   121,    10,
607
+      10,    14,    10,    33,     8,    10,    15,    14,    14,    11,
608
+      11,     9,    12,    12,    30,    12,    11,    87,    12,    11,
609
+     123,    61,    15,   105
605 610
 };
606 611
 
607 612
   /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
@@ -610,17 +615,17 @@ static const yytype_uint8 yystos[] =
610 615
 {
611 616
        0,    24,    36,    23,     0,     9,    24,    37,    38,    33,
612 617
       10,    15,    39,    11,    40,    38,    24,    25,    29,    31,
613
-      32,    33,    41,    42,    43,    45,    47,    48,    52,    54,
614
-      56,    57,    39,     9,     9,     9,    24,     9,    16,    26,
615
-      58,    41,    33,    46,    47,    14,    14,    14,    33,     3,
616
-       6,     9,    33,    34,    49,    55,    56,    55,    33,    50,
617
-      49,    49,    12,    15,    44,    10,    49,    49,    55,     5,
618
-       6,     7,     8,    17,    18,    19,    20,    21,    22,    27,
619
-      28,    10,    10,    15,    51,    10,    14,    46,    14,    14,
620
-      10,    49,    49,    49,    49,    49,    49,    49,    49,    49,
621
-      49,    55,    55,    11,    11,    33,    44,    41,    41,    51,
622
-      12,    12,    30,    53,    11,    29,    41,     9,    12,    55,
623
-      10,    11,    41,    12,    53
618
+      32,    33,    41,    42,    43,    45,    47,    51,    53,    55,
619
+      56,    39,     9,     9,     9,    24,     9,    16,    26,    57,
620
+      41,    33,    46,    14,    14,    33,     3,     6,     9,    33,
621
+      34,    48,    54,    55,    54,    33,    49,    48,    48,    12,
622
+      16,    15,    44,    10,    48,    48,    54,     5,     6,     7,
623
+       8,    17,    18,    19,    20,    21,    22,    27,    28,    10,
624
+      10,    15,    50,    10,    14,    14,    48,    46,    14,    14,
625
+      10,    48,    48,    48,    48,    48,    48,    48,    48,    48,
626
+      48,    54,    54,    11,    11,    33,    44,    41,    41,    50,
627
+      12,    12,    30,    52,    11,    29,    41,     9,    12,    54,
628
+      10,    11,    41,    12,    52
624 629
 };
625 630
 
626 631
   /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
@@ -628,10 +633,10 @@ static const yytype_uint8 yyr1[] =
628 633
 {
629 634
        0,    35,    36,    37,    37,    38,    39,    39,    40,    41,
630 635
       41,    42,    42,    42,    42,    42,    42,    43,    44,    44,
631
-      45,    45,    46,    46,    47,    48,    49,    49,    49,    49,
632
-      49,    49,    49,    49,    49,    50,    50,    51,    51,    52,
633
-      53,    53,    54,    55,    55,    55,    55,    55,    55,    55,
634
-      55,    55,    56,    57,    58
636
+      45,    45,    46,    46,    47,    48,    48,    48,    48,    48,
637
+      48,    48,    48,    48,    49,    49,    50,    50,    51,    52,
638
+      52,    53,    54,    54,    54,    54,    54,    54,    54,    54,
639
+      54,    55,    56,    57
635 640
 };
636 641
 
637 642
   /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN.  */
@@ -639,10 +644,10 @@ static const yytype_uint8 yyr2[] =
639 644
 {
640 645
        0,     2,     6,     0,     2,     2,     4,     0,     4,     2,
641 646
        0,     1,     1,     1,     1,     1,     2,     4,     3,     0,
642
-       1,     2,     1,     1,     3,     2,     1,     1,     3,     3,
643
-       3,     3,     1,     3,     2,     2,     0,     3,     0,     8,
644
-       4,     9,     7,     3,     3,     3,     3,     3,     3,     3,
645
-       3,     2,     4,     5,     3
647
+       1,     2,     3,     1,     4,     1,     1,     3,     3,     3,
648
+       3,     2,     1,     3,     2,     0,     3,     0,     8,     4,
649
+       9,     7,     3,     3,     3,     3,     3,     3,     3,     3,
650
+       2,     4,     5,     3
646 651
 };
647 652
 
648 653
 
@@ -1319,205 +1324,205 @@ yyreduce:
1319 1324
   switch (yyn)
1320 1325
     {
1321 1326
         case 2:
1322
-#line 63 "analyse_syntaxique.y" /* yacc.c:1646  */
1323
-    {printf("Dans main\n");}
1324
-#line 1325 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1327
+#line 68 "analyse_syntaxique.y" /* yacc.c:1646  */
1328
+    {}
1329
+#line 1330 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1325 1330
     break;
1326 1331
 
1327 1332
   case 3:
1328
-#line 65 "analyse_syntaxique.y" /* yacc.c:1646  */
1333
+#line 70 "analyse_syntaxique.y" /* yacc.c:1646  */
1329 1334
     {printf("Sans params\n");}
1330
-#line 1331 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1335
+#line 1336 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1331 1336
     break;
1332 1337
 
1333 1338
   case 5:
1334
-#line 68 "analyse_syntaxique.y" /* yacc.c:1646  */
1339
+#line 73 "analyse_syntaxique.y" /* yacc.c:1646  */
1335 1340
     {printf("Parametre : %s\n", (yyvsp[0].id));}
1336
-#line 1337 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1341
+#line 1342 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1337 1342
     break;
1338 1343
 
1339 1344
   case 8:
1340
-#line 75 "analyse_syntaxique.y" /* yacc.c:1646  */
1345
+#line 80 "analyse_syntaxique.y" /* yacc.c:1646  */
1341 1346
     {printf("Dans body\n");}
1342
-#line 1343 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1343
-    break;
1344
-
1345
-  case 17:
1346
-#line 87 "analyse_syntaxique.y" /* yacc.c:1646  */
1347
-    {printf("Declaration\n");}
1348
-#line 1349 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1347
+#line 1348 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1349 1348
     break;
1350 1349
 
1351 1350
   case 20:
1352
-#line 92 "analyse_syntaxique.y" /* yacc.c:1646  */
1353
-    {printf("int\n");}
1354
-#line 1355 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1351
+#line 97 "analyse_syntaxique.y" /* yacc.c:1646  */
1352
+    {type = TYPE_INT;}
1353
+#line 1354 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1355 1354
     break;
1356 1355
 
1357 1356
   case 21:
1358
-#line 93 "analyse_syntaxique.y" /* yacc.c:1646  */
1359
-    {printf("const int\n");}
1360
-#line 1361 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1357
+#line 98 "analyse_syntaxique.y" /* yacc.c:1646  */
1358
+    {type = TYPE_CONST_INT;}
1359
+#line 1360 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1361 1360
     break;
1362 1361
 
1363 1362
   case 22:
1364
-#line 95 "analyse_syntaxique.y" /* yacc.c:1646  */
1365
-    {printf("Declaration %s\n", (yyvsp[0].id));}
1366
-#line 1367 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1363
+#line 100 "analyse_syntaxique.y" /* yacc.c:1646  */
1364
+    {add_symbole_top(&table, (yyvsp[-2].id), type, INITIALISED, table.depth);}
1365
+#line 1366 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1366
+    break;
1367
+
1368
+  case 23:
1369
+#line 101 "analyse_syntaxique.y" /* yacc.c:1646  */
1370
+    {add_symbole_top(&table, (yyvsp[0].id), type, NOT_INITIALISED, table.depth);}
1371
+#line 1372 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1367 1372
     break;
1368 1373
 
1369 1374
   case 24:
1370
-#line 98 "analyse_syntaxique.y" /* yacc.c:1646  */
1371
-    {printf("Affectation : %s\n", (yyvsp[-2].id));}
1372
-#line 1373 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1375
+#line 104 "analyse_syntaxique.y" /* yacc.c:1646  */
1376
+    {printf("Affectation : %s\n", (yyvsp[-3].id));}
1377
+#line 1378 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1373 1378
     break;
1374 1379
 
1375
-  case 26:
1376
-#line 102 "analyse_syntaxique.y" /* yacc.c:1646  */
1380
+  case 25:
1381
+#line 106 "analyse_syntaxique.y" /* yacc.c:1646  */
1377 1382
     {printf("int %d\n", (yyvsp[0].nombre));}
1378
-#line 1379 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1383
+#line 1384 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1379 1384
     break;
1380 1385
 
1381
-  case 27:
1382
-#line 103 "analyse_syntaxique.y" /* yacc.c:1646  */
1386
+  case 26:
1387
+#line 107 "analyse_syntaxique.y" /* yacc.c:1646  */
1383 1388
     {printf("var %s\n", (yyvsp[0].id));}
1384
-#line 1385 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1389
+#line 1390 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1385 1390
     break;
1386 1391
 
1387
-  case 28:
1388
-#line 104 "analyse_syntaxique.y" /* yacc.c:1646  */
1392
+  case 27:
1393
+#line 108 "analyse_syntaxique.y" /* yacc.c:1646  */
1389 1394
     {printf("Addition\n");}
1390
-#line 1391 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1395
+#line 1396 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1391 1396
     break;
1392 1397
 
1393
-  case 29:
1394
-#line 105 "analyse_syntaxique.y" /* yacc.c:1646  */
1398
+  case 28:
1399
+#line 109 "analyse_syntaxique.y" /* yacc.c:1646  */
1395 1400
     {printf("Multiplication\n");}
1396
-#line 1397 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1401
+#line 1402 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1397 1402
     break;
1398 1403
 
1399
-  case 30:
1400
-#line 106 "analyse_syntaxique.y" /* yacc.c:1646  */
1404
+  case 29:
1405
+#line 110 "analyse_syntaxique.y" /* yacc.c:1646  */
1401 1406
     {printf("Soustraction\n");}
1402
-#line 1403 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1407
+#line 1408 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1403 1408
     break;
1404 1409
 
1405
-  case 31:
1406
-#line 107 "analyse_syntaxique.y" /* yacc.c:1646  */
1410
+  case 30:
1411
+#line 111 "analyse_syntaxique.y" /* yacc.c:1646  */
1407 1412
     {printf("Division\n");}
1408
-#line 1409 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1413
+#line 1414 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1409 1414
     break;
1410 1415
 
1411
-  case 33:
1412
-#line 109 "analyse_syntaxique.y" /* yacc.c:1646  */
1413
-    {printf("Parenthèse\n");}
1414
-#line 1415 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1416
+  case 31:
1417
+#line 112 "analyse_syntaxique.y" /* yacc.c:1646  */
1418
+    {printf("Soustraction\n");}
1419
+#line 1420 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1415 1420
     break;
1416 1421
 
1417
-  case 34:
1418
-#line 110 "analyse_syntaxique.y" /* yacc.c:1646  */
1419
-    {printf("Soustraction\n");}
1420
-#line 1421 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1422
+  case 33:
1423
+#line 114 "analyse_syntaxique.y" /* yacc.c:1646  */
1424
+    {printf("Parenthèse\n");}
1425
+#line 1426 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1421 1426
     break;
1422 1427
 
1423
-  case 39:
1424
-#line 118 "analyse_syntaxique.y" /* yacc.c:1646  */
1428
+  case 38:
1429
+#line 123 "analyse_syntaxique.y" /* yacc.c:1646  */
1425 1430
     {printf("Dans if\n");}
1426
-#line 1427 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1431
+#line 1432 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1427 1432
     break;
1428 1433
 
1429
-  case 40:
1430
-#line 120 "analyse_syntaxique.y" /* yacc.c:1646  */
1434
+  case 39:
1435
+#line 125 "analyse_syntaxique.y" /* yacc.c:1646  */
1431 1436
     {printf("else\n");}
1432
-#line 1433 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1437
+#line 1438 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1433 1438
     break;
1434 1439
 
1435
-  case 41:
1436
-#line 121 "analyse_syntaxique.y" /* yacc.c:1646  */
1440
+  case 40:
1441
+#line 126 "analyse_syntaxique.y" /* yacc.c:1646  */
1437 1442
     {printf("elsif\n");}
1438
-#line 1439 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1443
+#line 1444 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1439 1444
     break;
1440 1445
 
1441
-  case 42:
1442
-#line 123 "analyse_syntaxique.y" /* yacc.c:1646  */
1446
+  case 41:
1447
+#line 128 "analyse_syntaxique.y" /* yacc.c:1646  */
1443 1448
     {printf("Dans while\n");}
1444
-#line 1445 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1449
+#line 1450 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1445 1450
     break;
1446 1451
 
1447
-  case 43:
1448
-#line 125 "analyse_syntaxique.y" /* yacc.c:1646  */
1452
+  case 42:
1453
+#line 130 "analyse_syntaxique.y" /* yacc.c:1646  */
1449 1454
     {printf("Cond ==\n");}
1450
-#line 1451 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1455
+#line 1456 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1451 1456
     break;
1452 1457
 
1453
-  case 44:
1454
-#line 126 "analyse_syntaxique.y" /* yacc.c:1646  */
1458
+  case 43:
1459
+#line 131 "analyse_syntaxique.y" /* yacc.c:1646  */
1455 1460
     {printf("Cond !=\n");}
1456
-#line 1457 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1461
+#line 1462 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1457 1462
     break;
1458 1463
 
1459
-  case 45:
1460
-#line 127 "analyse_syntaxique.y" /* yacc.c:1646  */
1464
+  case 44:
1465
+#line 132 "analyse_syntaxique.y" /* yacc.c:1646  */
1461 1466
     {printf("Cond <\n");}
1462
-#line 1463 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1467
+#line 1468 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1463 1468
     break;
1464 1469
 
1465
-  case 46:
1466
-#line 128 "analyse_syntaxique.y" /* yacc.c:1646  */
1470
+  case 45:
1471
+#line 133 "analyse_syntaxique.y" /* yacc.c:1646  */
1467 1472
     {printf("Cond >\n");}
1468
-#line 1469 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1473
+#line 1474 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1469 1474
     break;
1470 1475
 
1471
-  case 47:
1472
-#line 129 "analyse_syntaxique.y" /* yacc.c:1646  */
1476
+  case 46:
1477
+#line 134 "analyse_syntaxique.y" /* yacc.c:1646  */
1473 1478
     {printf("Cond <=\n");}
1474
-#line 1475 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1479
+#line 1480 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1475 1480
     break;
1476 1481
 
1477
-  case 48:
1478
-#line 130 "analyse_syntaxique.y" /* yacc.c:1646  */
1482
+  case 47:
1483
+#line 135 "analyse_syntaxique.y" /* yacc.c:1646  */
1479 1484
     {printf("Cond >=\n");}
1480
-#line 1481 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1485
+#line 1486 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1481 1486
     break;
1482 1487
 
1483
-  case 49:
1484
-#line 131 "analyse_syntaxique.y" /* yacc.c:1646  */
1488
+  case 48:
1489
+#line 136 "analyse_syntaxique.y" /* yacc.c:1646  */
1485 1490
     {printf("Cond &&\n");}
1486
-#line 1487 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1491
+#line 1492 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1487 1492
     break;
1488 1493
 
1489
-  case 50:
1490
-#line 132 "analyse_syntaxique.y" /* yacc.c:1646  */
1494
+  case 49:
1495
+#line 137 "analyse_syntaxique.y" /* yacc.c:1646  */
1491 1496
     {printf("Cond ||\n");}
1492
-#line 1493 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1497
+#line 1498 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1493 1498
     break;
1494 1499
 
1495
-  case 51:
1496
-#line 133 "analyse_syntaxique.y" /* yacc.c:1646  */
1500
+  case 50:
1501
+#line 138 "analyse_syntaxique.y" /* yacc.c:1646  */
1497 1502
     {printf("Cond !\n");}
1498
-#line 1499 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1503
+#line 1504 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1499 1504
     break;
1500 1505
 
1501
-  case 52:
1502
-#line 135 "analyse_syntaxique.y" /* yacc.c:1646  */
1506
+  case 51:
1507
+#line 140 "analyse_syntaxique.y" /* yacc.c:1646  */
1503 1508
     {printf("Dans invocation\n");}
1504
-#line 1505 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1509
+#line 1510 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1505 1510
     break;
1506 1511
 
1507
-  case 53:
1508
-#line 137 "analyse_syntaxique.y" /* yacc.c:1646  */
1512
+  case 52:
1513
+#line 142 "analyse_syntaxique.y" /* yacc.c:1646  */
1509 1514
     {printf("printf de %s\n", (yyvsp[-2].id));}
1510
-#line 1511 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1515
+#line 1516 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1511 1516
     break;
1512 1517
 
1513
-  case 54:
1514
-#line 139 "analyse_syntaxique.y" /* yacc.c:1646  */
1518
+  case 53:
1519
+#line 144 "analyse_syntaxique.y" /* yacc.c:1646  */
1515 1520
     {printf("return\n");}
1516
-#line 1517 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1521
+#line 1522 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1517 1522
     break;
1518 1523
 
1519 1524
 
1520
-#line 1521 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1525
+#line 1526 "analyse_syntaxique.tab.c" /* yacc.c:1646  */
1521 1526
       default: break;
1522 1527
     }
1523 1528
   /* User semantic actions sometimes alter yychar, and that requires
@@ -1745,10 +1750,14 @@ yyreturn:
1745 1750
 #endif
1746 1751
   return yyresult;
1747 1752
 }
1748
-#line 141 "analyse_syntaxique.y" /* yacc.c:1906  */
1753
+#line 146 "analyse_syntaxique.y" /* yacc.c:1906  */
1749 1754
 
1750 1755
 #include <stdio.h>
1751 1756
 void main(void){
1757
+    initialise_table(&table);
1752 1758
     yyparse();
1759
+    print_table(&table);
1760
+    remove_symboles(&table, 0);
1761
+    print_table(&table);
1753 1762
 }
1754 1763
 

+ 19
- 9
analyse_syntaxique.y View File

@@ -5,6 +5,11 @@ char id[30];
5 5
 
6 6
 %{
7 7
 #include <stdio.h>
8
+#include "table_symboles.h"
9
+
10
+enum Initialised_Variable init;
11
+enum Symbole_Type type;
12
+Table_Symboles table;
8 13
 %}
9 14
 
10 15
 
@@ -60,7 +65,7 @@ char id[30];
60 65
 //Fonction : tINT tVAR tPO Params tPF Body;
61 66
 
62 67
 
63
-Main : tINT tMAIN tPO Params tPF Body {printf("Dans main\n");};
68
+Main : tINT tMAIN tPO Params tPF Body {};
64 69
 
65 70
 Params : {printf("Sans params\n");} ;
66 71
 Params : Param SuiteParams ;
@@ -84,20 +89,19 @@ Instruction : Print ;
84 89
 Instruction : Decl ;
85 90
 Instruction : Invocation tPV ;
86 91
 
87
-Decl : Type Valeur SuiteDecl tPV {printf("Declaration\n");} ;
92
+Decl : Type Valeur SuiteDecl tPV ;
88 93
 
89 94
 SuiteDecl: tVIRGULE Valeur SuiteDecl ;
90 95
 SuiteDecl: ;
91 96
 
92
-Type : tINT {printf("int\n");} ; 
93
-Type : tCONST tINT {printf("const int\n");} ;
97
+Type : tINT {type = TYPE_INT;} ; 
98
+Type : tCONST tINT {type = TYPE_CONST_INT;} ;
94 99
 
95
-Valeur : tVAR {printf("Declaration %s\n", $1);};
96
-Valeur : Affbis ;
100
+Valeur : tVAR tAFFECTATION E {add_symbole_top(&table, $1, type, INITIALISED, table.depth);};
101
+Valeur : tVAR {add_symbole_top(&table, $1, type, NOT_INITIALISED, table.depth);};
97 102
 
98
-Affbis : tVAR tAFFECTATION E {printf("Affectation : %s\n", $1);};
99 103
 
100
-Aff : Affbis tPV ;
104
+Aff : tVAR tAFFECTATION E tPV {printf("Affectation : %s\n", $1);};
101 105
 
102 106
 E : tENTIER {printf("int %d\n", $1);};
103 107
 E : tVAR {printf("var %s\n", $1);}; 
@@ -105,9 +109,10 @@ E : E tADD E {printf("Addition\n");} ;
105 109
 E : E tMUL E {printf("Multiplication\n");}  ; 
106 110
 E : E tSUB E {printf("Soustraction\n");} ;
107 111
 E : E tDIV E {printf("Division\n");} ;
112
+E : tSUB E {printf("Soustraction\n");} ;
108 113
 E : Invocation ;
109 114
 E : tPO E tPF {printf("Parenthèse\n");} ;
110
-E : tSUB E {printf("Soustraction\n");} ;
115
+
111 116
 
112 117
 Args : tVAR SuiteArgs ;
113 118
 Args : ;
@@ -141,6 +146,11 @@ Return : tRETURN E tPV {printf("return\n");};
141 146
 %%
142 147
 #include <stdio.h>
143 148
 void main(void){
149
+    //TODO: rajouter gestion des erreurs
150
+    initialise_table(&table);
144 151
     yyparse();
152
+    print_table(&table);
153
+    remove_symboles(&table, 0);
154
+    print_table(&table);
145 155
 }
146 156
 

+ 0
- 0
gen_assembleur.c View File


+ 21
- 0
gen_assembleur.h View File

@@ -0,0 +1,21 @@
1
+#ifndef GEN_ASSEMBLEUR_H
2
+#define GEN_ASSEMBLEUR_H
3
+
4
+#define INSTRUCTION_TABLE_SIZE 1000
5
+#define INSTRUCTION_SIZE 100
6
+
7
+//table des instructions
8
+typedef struct table{
9
+    char* 
10
+}
11
+
12
+enum operation{ADD, SUB, MUL, DIV};
13
+
14
+
15
+void gen_arithmetique(enum operation op, int arg1, int arg2);
16
+
17
+
18
+//renvoie l'index (ou valeur?) de la premiere @ dispo
19
+int new_temp();
20
+
21
+#endif

+ 18
- 0
poubelle/test.c View File

@@ -0,0 +1,18 @@
1
+#include <stdio.h>
2
+#include "table_symboles.h"
3
+
4
+int main() {
5
+    
6
+    Table_Symboles table;
7
+    initialise_table(&table);
8
+
9
+    add_symbole_top(&table, "var1" , TYPE_INT, INITIALISED);
10
+    add_symbole_top(&table, "var1" , TYPE_INT, INITIALISED);
11
+
12
+    add_symbole_top(&table, "var2" , TYPE_INT, INITIALISED);
13
+    add_symbole_bottom(&table, "varTemp1" , TYPE_CONST_INT, INITIALISED);
14
+    add_symbole_bottom(&table, "varTemp2" , TYPE_INT, NOT_INITIALISED);
15
+
16
+    print_table(&table);
17
+    return 0;
18
+}

+ 3
- 6
script.sh View File

@@ -3,12 +3,9 @@ flex analyse_lexicale.lex
3 3
 gcc -w *.c -ly
4 4
 echo "
5 5
     int main(){
6
-        const int toto = 1, mimi, lolo = 6;
7
-        int tata = 5, lala;
8
-        while (tata == 5){
9
-            printf(tata);
10
-            lala = lolo + 6;
11
-        } 
6
+        const int var1 = 1, var2;
7
+        int var2;
8
+        int var3, var4 = 1;
12 9
         return 1;
13 10
     }
14 11
 " | ./a.out

Table_Symboles/table_symboles.c → table_symboles.c View File

@@ -1,7 +1,3 @@
1
-//
2
-// Created by Nahom Belay on 31/03/2021.
3
-//
4
-
5 1
 #include "table_symboles.h"
6 2
 #include <stdio.h>
7 3
 #include <string.h>
@@ -10,31 +6,33 @@
10 6
 void initialise_table(Table_Symboles * table){
11 7
     table->indexAvailableBottom = TABLE_SIZE - 1;
12 8
     table->indexAvailableTop = 0;
9
+    table->depth = 0;
13 10
 }
14 11
 
15 12
 int variable_exists(Table_Symboles * table, char * varName){
16 13
     for (int i = 0; i < table->indexAvailableTop; i++){
17 14
         if (strcmp(varName, table->array[i].Variable_Name) == 0){
18
-            return -1;
15
+            return i;
19 16
         }
20 17
     }
21 18
 
22 19
     for (int i = (table->indexAvailableBottom + 1); i < TABLE_SIZE; i++){
23 20
         if (strcmp(varName, table->array[i].Variable_Name) == 0){
24
-            return -1;
21
+            return i;
25 22
         }
26 23
     }
27 24
     return 0;
28 25
 }
29
-int add_symbole_top(Table_Symboles * table, char * varName, enum Symbole_Type type, enum Initialised_Variable init){
26
+int add_symbole_top(Table_Symboles * table, char * varName, enum Symbole_Type type, enum Initialised_Variable init, int depth){
30 27
     Symbole symbole;
31
-    symbole.Variable_Name = varName;
28
+    strcpy(symbole.Variable_Name, varName);
32 29
     symbole.addr = table->indexAvailableTop;
33 30
     symbole.init = init;
34 31
     symbole.type = type;
32
+    symbole.symbole_depth = table->depth;
35 33
     if (table->indexAvailableTop >= table->indexAvailableBottom){
36 34
         return -1;
37
-    } else if (variable_exists(table, varName) == -1){
35
+    } else if (variable_exists(table, varName) != 0){
38 36
         return -2;
39 37
     } else {
40 38
         table->array[table->indexAvailableTop] = symbole;
@@ -45,13 +43,14 @@ int add_symbole_top(Table_Symboles * table, char * varName, enum Symbole_Type ty
45 43
 
46 44
 int add_symbole_bottom(Table_Symboles * table, char * varName, enum Symbole_Type type, enum Initialised_Variable init){
47 45
     Symbole symbole;
48
-    symbole.Variable_Name = varName;
46
+    strcpy(symbole.Variable_Name, varName);
49 47
     symbole.addr = table->indexAvailableBottom;
50 48
     symbole.init = init;
51 49
     symbole.type = type;
50
+    //symbole.symbole_depth = -1;
52 51
     if (table->indexAvailableTop >= table->indexAvailableBottom){
53 52
         return -1;
54
-    } else if (variable_exists(table, varName) == 1){
53
+    } else if (variable_exists(table, varName) != 0){
55 54
         return -2;
56 55
     } else {
57 56
         table->array[table->indexAvailableBottom] = symbole;
@@ -60,28 +59,55 @@ int add_symbole_bottom(Table_Symboles * table, char * varName, enum Symbole_Type
60 59
     return 0;
61 60
 }
62 61
 
62
+int remove_symboles(Table_Symboles * table, int depth){
63
+    int index;
64
+    if (depth < table->depth){
65
+        return -1;
66
+    } else {
67
+        index = table->indexAvailableTop;
68
+        while(table->array[index].symbole_depth == depth && index >=0){
69
+            //remove
70
+            table->indexAvailableTop--;
71
+            index--;
72
+        }
73
+
74
+        //TODO: vérifier qu'il n'y a pas de varaibles temporarires au moment de changement de profondeur
75
+    }
76
+    return 0;
77
+}
78
+
79
+int initialise_symbole(Table_Symboles * table, char * varName){
80
+    int index = variable_exists(table, varName);
81
+    if (index == -1){
82
+        return -1;
83
+    } else {
84
+        table->array[index].init = INITIALISED;
85
+    }
86
+}
87
+
63 88
 void print_symbole(Symbole * symbole){
64 89
     char * var = symbole->Variable_Name;
65 90
     int addr = symbole->addr;
66
-    int type = symbole->type;
67
-    char * typeStr;
68
-    if (type == 0){
69
-        typeStr = "INT";
91
+    enum Symbole_Type type = symbole->type;
92
+    char typeStr[20];
93
+    if (type == TYPE_INT){
94
+        strcpy(typeStr, "INT");
70 95
     } else{
71
-        typeStr = "CONST_INT";
96
+        strcpy(typeStr, "CONST_INT");
72 97
     }
73
-    int init = symbole->init;
74
-    char * initStr;
75
-    if (type == 0){
76
-        initStr = "INITIALISED";
98
+    enum Initialised_Variable init = symbole->init;
99
+    char initStr[20];
100
+    if (init == INITIALISED){
101
+        strcpy(initStr,"INITIALISED");
77 102
     } else{
78
-        initStr = "NOT_INITIALISED";
103
+        strcpy(initStr,"NOT_INITIALISED");
79 104
     }
80
-    printf("%-20s\t\t %-12s\t\t %-12d\t %-12s\n", var, typeStr, addr, initStr);
105
+    int depth = symbole->symbole_depth;
106
+    printf("%-20s\t\t %-12s\t\t %-12d\t %-20s\t %-12d\n", var, typeStr, addr, initStr, depth);
81 107
 }
82 108
 
83 109
 void print_table(Table_Symboles * table){
84
-    printf("%-20s\t\t %-12s\t\t %-12s\t %-12s\n", "Variable Name", "Type", "Address", "Initialised");
110
+    printf("%-20s\t\t %-12s\t\t %-12s\t %-20s\t %-12s\n", "Variable Name", "Type", "Address", "Initialised", "Depth");
85 111
     int indexTop = table->indexAvailableTop;
86 112
     int indexBottom = table->indexAvailableBottom;
87 113
     Symbole symbole;
@@ -90,11 +116,13 @@ void print_table(Table_Symboles * table){
90 116
         print_symbole(&symbole);
91 117
     }
92 118
     if (table->indexAvailableBottom != TABLE_SIZE - 1){
93
-        printf("%-20s\t\t %-12s\t\t %-12s\t %-12s\n", "...", "...", "...", "...");
119
+        printf("%-20s\t\t %-12s\t\t %-12s\t %-20s\t %-12s\n", "...", "...", "...", "...", "...");
94 120
         for (int i = (indexBottom + 1); i < TABLE_SIZE; i++){
95 121
             symbole = table->array[i];
96 122
             print_symbole(&symbole);
97 123
         }
98 124
     }
99 125
 
126
+    
127
+
100 128
 }

Table_Symboles/table_symboles.h → table_symboles.h View File

@@ -1,26 +1,25 @@
1
-//
2
-// Created by Nahom Belay on 31/03/2021.
3
-//
4
-
5 1
 #ifndef TABLE_SYMBOLES_H
6 2
 #define TABLE_SYMBOLES_H
7 3
 
8 4
 #define TABLE_SIZE 50
5
+#define VARIABLE_SIZE 30
9 6
 
10 7
 enum Symbole_Type {TYPE_INT , TYPE_CONST_INT};
11 8
 enum Initialised_Variable{INITIALISED , NOT_INITIALISED};
12 9
 
13 10
 typedef struct Symboles {
14
-    char * Variable_Name;
11
+    char Variable_Name[VARIABLE_SIZE];
15 12
     int addr ;
16 13
     enum Symbole_Type type;
17 14
     enum Initialised_Variable init;
15
+    int symbole_depth;
18 16
 } Symbole;
19 17
 
20 18
 typedef struct Table_Symboles {
21 19
     Symbole array[TABLE_SIZE];
22 20
     int indexAvailableTop;
23 21
     int indexAvailableBottom;
22
+    int depth;
24 23
 } Table_Symboles;
25 24
 
26 25
 /**
@@ -37,7 +36,7 @@ void initialise_table(Table_Symboles * table);
37 36
  * @param init
38 37
  * @return if symbole added successfully, -1 if the table is full and -2 if the varaible already exists in the table
39 38
  */
40
-int add_symbole_top(Table_Symboles * table, char * varName, enum Symbole_Type type , enum Initialised_Variable init);
39
+int add_symbole_top(Table_Symboles * table, char * varName, enum Symbole_Type type , enum Initialised_Variable init, int depth);
41 40
 
42 41
 /**
43 42
  * Adds a symbole at the bottom (temp variables)
@@ -58,6 +57,23 @@ int add_symbole_bottom(Table_Symboles * table, char * varName, enum Symbole_Type
58 57
 int variable_exists(Table_Symboles * table, char * varName);
59 58
 
60 59
 /**
60
+ * Removes symbole from table having certain depth
61
+ * @param table
62
+ * @param depth
63
+ * @return -1 if the symbole isn't in the table, 0 otherwise
64
+ */
65
+int remove_symboles(Table_Symboles * table, int depth);
66
+
67
+/**
68
+ * Initialises an already exisiting symbole
69
+ * @param table
70
+ * @param varName
71
+ * @return -1 if the symbole isn't in the table, 0 otherwise
72
+ */
73
+int initialise_symbole(Table_Symboles * table, char * varName);
74
+
75
+
76
+/**
61 77
  * Prints a symbole with this format
62 78
  * varName      | Type  | Address   | Initialised/Not_Initialised
63 79
  * @param symbole
@@ -70,4 +86,4 @@ void print_symbole(Symbole * symbole);
70 86
  */
71 87
 void print_table(Table_Symboles * table);
72 88
 
73
-#endif TABLE_SYMBOLES_H
89
+#endif

Loading…
Cancel
Save