Foussats Morgane 8 months ago
parent
commit
1214af43d7
11 changed files with 3532 additions and 201 deletions
  1. BIN
      Lex/a.out
  2. 0
    80
      Lex/analyse_lexicale.lex
  3. 0
    0
      Makefile
  4. 93
    0
      analyse_lexicale.lex
  5. 1452
    0
      analyse_syntaxique.output
  6. 1543
    0
      analyse_syntaxique.tab.c
  7. 104
    0
      analyse_syntaxique.tab.h
  8. 107
    0
      analyse_syntaxique.y
  9. 175
    121
      lex.yy.c
  10. 31
    0
      script.sh
  11. 27
    0
      test

BIN
Lex/a.out View File


+ 0
- 80
Lex/analyse_lexicale.lex View File

@@ -1,80 +0,0 @@
1
-ADD         "+"
2
-SUB         "-"
3
-MUL         "*"
4
-DIV         "/"
5
-tPO         "("
6
-tPF         ")"
7
-tAO         "{"
8
-tAF         "}"
9
-EOL         "\n"
10
-EOI         ";"
11
-SPACE       " "
12
-TAB         "\t"
13
-VIRGULE     ","
14
-EGAL        "="
15
-LT          "<"
16
-GT          ">"
17
-tINT        "int"
18
-tMAIN       "main"  
19
-tPRINT      "printf"
20
-tRETURN     "return"
21
-tIF         "if"
22
-tELSE       "else"
23
-tWHILE      "while"
24
-tNOT        "!"
25
-tAND        "&&"
26
-tOR         "||"
27
-DIGIT       [0-9]
28
-VARIABLE    [A-Za-z0-9_]+
29
-DECIMAL     {DIGIT}+
30
-EXPONENTIEL {DIGIT}+"^"{DIGIT}+
31
-ENTIER      {DECIMAL}|{EXPONENTIEL}
32
-OPERATION   {ADD}|{SUB}|{MUL}|{DIV}
33
-COMPARATEUR {EGAL}|{LT}|{GT}
34
-SEPARATOR   {SPACE}|{TAB}
35
-
36
-%%
37
-
38
-{ADD}           {printf("tADD ");}
39
-{SUB}           {printf("tSUB ");}
40
-{MUL}           {printf("tMUL ");}
41
-{DIV}           {printf("tDIV ");}
42
-
43
-{tPO}           {printf("tPO ");}
44
-{tPF}           {printf("tPF ");}
45
-{tAO}           {printf("tAO ");}
46
-{tAF}           {printf("tAF ");}
47
-
48
-{EOI}           {printf("tPV ");}
49
-{SEPARATOR}     {}
50
-{EOL}           {}
51
-{VIRGULE}       {printf("tVIRGULE ");}
52
-
53
-{EGAL}          {printf("tEGAL ");}
54
-{LT}            {printf("tLT ");}
55
-{GT}            {printf("tGT ");}
56
-
57
-{tMAIN}         {printf("tMAIN ");}
58
-{tINT}          {printf("tINT ");}
59
-{tPRINT}        {printf("tPRINT ");}
60
-{tRETURN}       {printf("tRETURN ");}
61
-
62
-{tOR}           {printf("tOR ");}
63
-{tAND}          {printf("tAND ");}
64
-
65
-{tIF}           {printf("tIF ");}
66
-{tELSE}         {printf("tELSE ");}
67
-{tWHILE}        {printf("tWHILE ");}
68
-
69
-{ENTIER}        {printf("tENTIER ");}
70
-{VARIABLE}      {printf("tVAR ");}
71
-
72
-%%
73
-int yywrap(void){
74
-    return 1;
75
-}
76
-int main(void){
77
-    yylex();
78
-}
79
-
80
-

Lex/Makefile → Makefile View File


+ 93
- 0
analyse_lexicale.lex View File

@@ -0,0 +1,93 @@
1
+ADD         "+"
2
+SUB         "-"
3
+MUL         "*"
4
+DIV         "/"
5
+tPO         "("
6
+tPF         ")"
7
+tAO         "{"
8
+tAF         "}"
9
+EOL         "\n"
10
+EOI         ";"
11
+SPACE       " "
12
+TAB         "\t"
13
+VIRGULE     ","
14
+AFFECTATION        "="
15
+EQUAL       "=="
16
+LT          "<"
17
+GT          ">"
18
+LTE          "<="
19
+GTE          ">="
20
+tINT        "int"
21
+tMAIN       "main"  
22
+tPRINT      "printf"
23
+tRETURN     "return"
24
+tIF         "if"
25
+tELSE       "else"
26
+tWHILE      "while"
27
+tNOT        "!"
28
+tAND        "&&"
29
+tOR         "||"
30
+tDIFF       "!="
31
+DIGIT       [0-9]
32
+VARIABLE    [A-Za-z0-9_]+
33
+CONST       "const"
34
+DECIMAL     {DIGIT}+
35
+EXPONENTIEL {DIGIT}+"^"{DIGIT}+
36
+ENTIER      {DECIMAL}|{EXPONENTIEL}
37
+OPERATION   {ADD}|{SUB}|{MUL}|{DIV}
38
+COMPARATEUR {EGAL}|{LT}|{GT}
39
+SEPARATOR   {SPACE}|{TAB}
40
+
41
+%%
42
+
43
+{ADD}           {return tADD ;}
44
+{SUB}           {return tSUB ;}
45
+{MUL}           {return tMUL ;}
46
+{DIV}           {return tDIV ;}
47
+
48
+{tPO}           {return tPO ;}
49
+{tPF}           {return tPF ;}
50
+{tAO}           {return tAO ;}
51
+{tAF}           {return tAF ;}
52
+
53
+{EOI}           {return tPV ;}
54
+{SEPARATOR}     {}
55
+{EOL}           {}
56
+{VIRGULE}       {return tVIRGULE ;}
57
+
58
+{AFFECTATION}   {return tAFFECTATION ;}
59
+
60
+{EQUAL}          {return tEGAL ;}
61
+{tDIFF}          {return tDIFF ;}
62
+{LT}            {return tLT ;}
63
+{GT}            {return tGT ;}
64
+{LTE}           {return tLTE ;}
65
+{GTE}           {return tGTE ;}
66
+{tNOT}           {return tNOT ;}
67
+
68
+
69
+{tMAIN}         {return tMAIN ;}
70
+{tINT}          {return tINT ;}
71
+{tPRINT}        {return tPRINT ;}
72
+{tRETURN}       {return tRETURN ;}
73
+
74
+{tOR}           {return tOR ;}
75
+{tAND}          {return tAND ;}
76
+
77
+{tIF}           {return tIF ;}
78
+{tELSE}         {return tELSE ;}
79
+{tWHILE}        {return tWHILE ;}
80
+
81
+{CONST}         {return tCONST ;}
82
+{ENTIER}        {return tENTIER ;}
83
+{VARIABLE}      {return tVAR ;}
84
+
85
+%%
86
+int yywrap(void){
87
+    return 1;
88
+}
89
+//int main(void){
90
+//    yylex();
91
+//}
92
+
93
+

+ 1452
- 0
analyse_syntaxique.output
File diff suppressed because it is too large
View File


+ 1543
- 0
analyse_syntaxique.tab.c
File diff suppressed because it is too large
View File


+ 104
- 0
analyse_syntaxique.tab.h View File

@@ -0,0 +1,104 @@
1
+/* A Bison parser, made by GNU Bison 3.0.4.  */
2
+
3
+/* Bison interface for Yacc-like parsers in C
4
+
5
+   Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc.
6
+
7
+   This program is free software: you can redistribute it and/or modify
8
+   it under the terms of the GNU General Public License as published by
9
+   the Free Software Foundation, either version 3 of the License, or
10
+   (at your option) any later version.
11
+
12
+   This program is distributed in the hope that it will be useful,
13
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
+   GNU General Public License for more details.
16
+
17
+   You should have received a copy of the GNU General Public License
18
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19
+
20
+/* As a special exception, you may create a larger work that contains
21
+   part or all of the Bison parser skeleton and distribute that work
22
+   under terms of your choice, so long as that work isn't itself a
23
+   parser generator using the skeleton or a modified version thereof
24
+   as a parser skeleton.  Alternatively, if you modify or redistribute
25
+   the parser skeleton itself, you may (at your option) remove this
26
+   special exception, which will cause the skeleton and the resulting
27
+   Bison output files to be licensed under the GNU General Public
28
+   License without this special exception.
29
+
30
+   This special exception was added by the Free Software Foundation in
31
+   version 2.2 of Bison.  */
32
+
33
+#ifndef YY_YY_ANALYSE_SYNTAXIQUE_TAB_H_INCLUDED
34
+# define YY_YY_ANALYSE_SYNTAXIQUE_TAB_H_INCLUDED
35
+/* Debug traces.  */
36
+#ifndef YYDEBUG
37
+# define YYDEBUG 1
38
+#endif
39
+#if YYDEBUG
40
+extern int yydebug;
41
+#endif
42
+
43
+/* Token type.  */
44
+#ifndef YYTOKENTYPE
45
+# define YYTOKENTYPE
46
+  enum yytokentype
47
+  {
48
+    tENTIER = 258,
49
+    tADD = 259,
50
+    tSUB = 260,
51
+    tMUL = 261,
52
+    tDIV = 262,
53
+    tPO = 263,
54
+    tPF = 264,
55
+    tAO = 265,
56
+    tAF = 266,
57
+    tERROR = 267,
58
+    tPV = 268,
59
+    tVIRGULE = 269,
60
+    tAFFECTATION = 270,
61
+    tEGAL = 271,
62
+    tDIFF = 272,
63
+    tLT = 273,
64
+    tGT = 274,
65
+    tGTE = 275,
66
+    tLTE = 276,
67
+    tMAIN = 277,
68
+    tINT = 278,
69
+    tPRINT = 279,
70
+    tRETURN = 280,
71
+    tOR = 281,
72
+    tAND = 282,
73
+    tIF = 283,
74
+    tELSE = 284,
75
+    tWHILE = 285,
76
+    tCONST = 286,
77
+    tVAR = 287,
78
+    tNOT = 288
79
+  };
80
+#endif
81
+
82
+/* Value type.  */
83
+#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
84
+
85
+union YYSTYPE
86
+{
87
+#line 1 "analyse_syntaxique.y" /* yacc.c:1909  */
88
+
89
+int nombre;
90
+
91
+#line 92 "analyse_syntaxique.tab.h" /* yacc.c:1909  */
92
+};
93
+
94
+typedef union YYSTYPE YYSTYPE;
95
+# define YYSTYPE_IS_TRIVIAL 1
96
+# define YYSTYPE_IS_DECLARED 1
97
+#endif
98
+
99
+
100
+extern YYSTYPE yylval;
101
+
102
+int yyparse (void);
103
+
104
+#endif /* !YY_YY_ANALYSE_SYNTAXIQUE_TAB_H_INCLUDED  */

+ 107
- 0
analyse_syntaxique.y View File

@@ -0,0 +1,107 @@
1
+%union {
2
+int nombre;
3
+}
4
+
5
+%token<nombre> tENTIER
6
+%token tADD
7
+%token tSUB
8
+%token tMUL
9
+%token tDIV
10
+
11
+%token tPO
12
+%token tPF
13
+%token tAO
14
+%token tAF
15
+
16
+%token tERROR
17
+
18
+%token tPV
19
+%token tVIRGULE
20
+%token tAFFECTATION
21
+%token tEGAL
22
+%token tDIFF
23
+%token tLT
24
+%token tGT
25
+%token tGTE
26
+%token tLTE
27
+%token tMAIN
28
+%token tINT
29
+%token tPRINT
30
+%token tRETURN
31
+%token tOR
32
+%token tAND
33
+%token tIF
34
+%token tELSE
35
+%token tWHILE
36
+%token tCONST
37
+%token tVAR
38
+%token tNOT
39
+
40
+%left tADD
41
+%left tSUB
42
+%right tEGAL
43
+
44
+%type<nombre> E
45
+%%
46
+
47
+C : Fonctions Main ;
48
+Fonctions : Fonction Fonctions | Fonction | ;
49
+
50
+Fonction : tINT tVAR tPO Params tPF Body ;
51
+
52
+Main : tINT tMAIN tPO tPF Body ;
53
+
54
+Params : | Param SuiteParams ;
55
+Param : tINT tVAR ;
56
+
57
+
58
+// Ps : P Ps | ;
59
+// P : tINT tID ttVIRGULE
60
+// Ps =>* tINT tID ttVIRGULE tINT tID ttVIRGULE
61
+// Ps => P Ps => P P Ps ...
62
+
63
+SuiteParams : tVIRGULE Param SuiteParams | ;
64
+
65
+Body : tAO Instructions tAF ;
66
+
67
+Instructions : Instruction Instructions | ;
68
+
69
+Instruction : Aff | If | While | tRETURN | Print | Decl | Invocation tPV ;
70
+
71
+Decl : Type Valeur SuiteDecl tPV;
72
+
73
+SuiteDecl: tVIRGULE Valeur SuiteDecl | ;
74
+
75
+Type : tINT | tCONST tINT ; 
76
+
77
+Valeur : tVAR | Affbis ;
78
+
79
+Affbis : tVAR tAFFECTATION E;
80
+
81
+Aff : Affbis tPV ;
82
+
83
+E : tENTIER | tVAR | E tADD E | E tMUL E | E tSUB E | E tDIV E | Invocation | tPO E tPF | tSUB E ;
84
+
85
+// E : tID tPlus tID | ...
86
+
87
+If : tIF tPO Cond tPF Body Else;
88
+
89
+Else : | tELSE Body |tELSE tIF tPO Cond tPF Body Else;
90
+
91
+While : tWHILE tPO Cond tPF Body ;
92
+
93
+Cond : Cond tAND Cond | Cond tOR Cond | E tEGAL E | E tDIFF E | E tLT E | E tGT E | E tLTE E | E tGTE E| tNOT Cond ;
94
+
95
+Print : tPRINT tPO tVAR tPF tPV ;
96
+
97
+Invocation : tVAR tPO  Args  tPF ;
98
+
99
+Args : | Arg SuiteArgs ;
100
+
101
+Arg : tVAR ;
102
+
103
+SuiteArgs : tVIRGULE Arg SuiteArgs ;
104
+
105
+RETURN : tRETURN E tPV ;
106
+
107
+%%

Lex/lex.yy.c → lex.yy.c View File

@@ -351,8 +351,8 @@ static void yynoreturn yy_fatal_error ( const char* msg  );
351 351
 	(yy_hold_char) = *yy_cp; \
352 352
 	*yy_cp = '\0'; \
353 353
 	(yy_c_buf_p) = yy_cp;
354
-#define YY_NUM_RULES 25
355
-#define YY_END_OF_BUFFER 26
354
+#define YY_NUM_RULES 33
355
+#define YY_END_OF_BUFFER 34
356 356
 /* This struct is not used in this scanner,
357 357
    but its presence is necessary. */
358 358
 struct yy_trans_info
@@ -360,13 +360,15 @@ struct yy_trans_info
360 360
 	flex_int32_t yy_verify;
361 361
 	flex_int32_t yy_nxt;
362 362
 	};
363
-static const flex_int16_t yy_accept[49] =
363
+static const flex_int16_t yy_accept[70] =
364 364
     {   0,
365
-        0,    0,   26,   25,   23,   24,   25,    5,    6,    3,
366
-        1,   10,    2,    4,   12,    9,   13,   11,   14,   22,
367
-       22,   22,   22,   22,    7,   25,    8,   19,   12,   22,
368
-        0,   22,   20,   22,   22,   22,   18,   12,   22,   16,
369
-       22,   22,   21,   15,   22,   22,   17,    0
365
+        0,    0,   34,   33,   10,   11,   20,   33,    5,    6,
366
+        3,    1,   12,    2,    4,   31,    9,   16,   13,   17,
367
+       32,   32,   32,   32,   32,   32,   32,   32,    7,   33,
368
+        8,   15,   26,   31,   32,    0,   18,   14,   19,   32,
369
+       32,   27,   32,   32,   32,   32,   32,   25,   31,   32,
370
+       32,   22,   32,   32,   32,   32,   32,   28,   21,   32,
371
+       32,   32,   30,   32,   32,   29,   23,   24,    0
370 372
     } ;
371 373
 
372 374
 static const YY_CHAR yy_ec[256] =
@@ -374,17 +376,17 @@ static const YY_CHAR yy_ec[256] =
374 376
         1,    1,    1,    1,    1,    1,    1,    1,    2,    3,
375 377
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
376 378
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
377
-        1,    4,    1,    1,    1,    1,    1,    5,    1,    6,
378
-        7,    8,    9,   10,   11,    1,   12,   13,   13,   13,
379
-       13,   13,   13,   13,   13,   13,   13,    1,   14,   15,
380
-       16,   17,    1,    1,   18,   18,   18,   18,   18,   18,
381
-       18,   18,   18,   18,   18,   18,   18,   18,   18,   18,
382
-       18,   18,   18,   18,   18,   18,   18,   18,   18,   18,
383
-        1,    1,    1,   19,   18,    1,   20,   18,   18,   18,
384
-
385
-       21,   22,   18,   18,   23,   18,   18,   24,   25,   26,
386
-       18,   27,   18,   28,   29,   30,   18,   18,   18,   18,
387
-       18,   18,   31,   32,   33,    1,    1,    1,    1,    1,
379
+        1,    4,    5,    1,    1,    1,    1,    6,    1,    7,
380
+        8,    9,   10,   11,   12,    1,   13,   14,   14,   14,
381
+       14,   14,   14,   14,   14,   14,   14,    1,   15,   16,
382
+       17,   18,    1,    1,   19,   19,   19,   19,   19,   19,
383
+       19,   19,   19,   19,   19,   19,   19,   19,   19,   19,
384
+       19,   19,   19,   19,   19,   19,   19,   19,   19,   19,
385
+        1,    1,    1,   20,   19,    1,   21,   19,   22,   19,
386
+
387
+       23,   24,   19,   25,   26,   19,   19,   27,   28,   29,
388
+       30,   31,   19,   32,   33,   34,   35,   19,   36,   19,
389
+       19,   19,   37,   38,   39,    1,    1,    1,    1,    1,
388 390
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
389 391
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
390 392
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
@@ -401,64 +403,76 @@ static const YY_CHAR yy_ec[256] =
401 403
         1,    1,    1,    1,    1
402 404
     } ;
403 405
 
404
-static const YY_CHAR yy_meta[34] =
406
+static const YY_CHAR yy_meta[40] =
405 407
     {   0,
406 408
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
407
-        1,    1,    2,    1,    1,    1,    1,    2,    2,    2,
409
+        1,    1,    1,    2,    1,    1,    1,    1,    2,    2,
408 410
         2,    2,    2,    2,    2,    2,    2,    2,    2,    2,
409
-        1,    1,    1
411
+        2,    2,    2,    2,    2,    2,    1,    1,    1
410 412
     } ;
411 413
 
412
-static const flex_int16_t yy_base[50] =
414
+static const flex_int16_t yy_base[71] =
413 415
     {   0,
414
-        0,    0,   77,   78,   78,   78,   71,   78,   78,   78,
415
-       78,   78,   78,   78,   21,   78,   78,   78,   78,   56,
416
-       17,   16,   24,   18,   78,   42,   78,   78,   26,   54,
417
-       59,   28,   52,   29,   30,   31,   78,   57,   37,   50,
418
-       36,   41,   49,   47,   33,   42,   46,   78,   49
416
+        0,    0,  116,  117,  117,  117,   98,  108,  117,  117,
417
+      117,  117,  117,  117,  117,   26,  117,   96,   95,   94,
418
+       90,   21,   22,   23,   24,   28,   30,   34,  117,   71,
419
+      117,  117,  117,   41,   88,   93,  117,  117,  117,   36,
420
+       37,   86,   38,   42,   43,   44,   47,  117,   91,   46,
421
+       51,   84,   55,   56,   57,   60,   61,   83,   82,   62,
422
+       66,   68,   81,   69,   70,   80,   77,   74,  117,   81
419 423
     } ;
420 424
 
421
-static const flex_int16_t yy_def[50] =
425
+static const flex_int16_t yy_def[71] =
422 426
     {   0,
423
-       48,    1,   48,   48,   48,   48,   48,   48,   48,   48,
424
-       48,   48,   48,   48,   49,   48,   48,   48,   48,   49,
425
-       49,   49,   49,   49,   48,   48,   48,   48,   49,   49,
426
-       48,   49,   49,   49,   49,   49,   48,   48,   49,   49,
427
-       49,   49,   49,   49,   49,   49,   49,    0,   48
427
+       69,    1,   69,   69,   69,   69,   69,   69,   69,   69,
428
+       69,   69,   69,   69,   69,   70,   69,   69,   69,   69,
429
+       70,   70,   70,   70,   70,   70,   70,   70,   69,   69,
430
+       69,   69,   69,   70,   70,   69,   69,   69,   69,   70,
431
+       70,   70,   70,   70,   70,   70,   70,   69,   69,   70,
432
+       70,   70,   70,   70,   70,   70,   70,   70,   70,   70,
433
+       70,   70,   70,   70,   70,   70,   70,   70,    0,   69
428 434
     } ;
429 435
 
430
-static const flex_int16_t yy_nxt[112] =
436
+static const flex_int16_t yy_nxt[157] =
431 437
     {   0,
432 438
         4,    5,    6,    5,    7,    8,    9,   10,   11,   12,
433
-       13,   14,   15,   16,   17,   18,   19,   20,    4,   20,
434
-       21,   20,   22,   20,   23,   20,   24,   20,   20,   20,
435
-       25,   26,   27,   29,   48,   48,   48,   33,   29,   31,
436
-       32,   34,   48,   35,   31,   36,   48,   48,   48,   48,
437
-       30,   48,   41,   42,   48,   48,   39,   43,   40,   48,
438
-       48,   44,   46,   47,   48,   48,   45,   48,   48,   38,
439
-       48,   38,   48,   37,   48,   28,   48,    3,   48,   48,
440
-       48,   48,   48,   48,   48,   48,   48,   48,   48,   48,
441
-       48,   48,   48,   48,   48,   48,   48,   48,   48,   48,
442
-
443
-       48,   48,   48,   48,   48,   48,   48,   48,   48,   48,
444
-       48
439
+       13,   14,   15,   16,   17,   18,   19,   20,   21,    4,
440
+       21,   22,   23,   21,   21,   24,   21,   25,   21,   21,
441
+       26,   27,   21,   21,   21,   28,   29,   30,   31,   34,
442
+       69,   69,   69,   69,   44,   36,   42,   69,   41,   69,
443
+       40,   43,   46,   69,   34,   69,   69,   69,   47,   45,
444
+       36,   69,   69,   69,   50,   69,   69,   53,   54,   51,
445
+       69,   52,   56,   58,   69,   69,   69,   55,   57,   69,
446
+       69,   69,   35,   59,   60,   69,   62,   69,   69,   69,
447
+       66,   61,   67,   69,   63,   64,   69,   65,   68,   69,
448
+
449
+       69,   69,   69,   69,   49,   69,   49,   69,   48,   69,
450
+       39,   38,   37,   33,   32,   69,    3,   69,   69,   69,
451
+       69,   69,   69,   69,   69,   69,   69,   69,   69,   69,
452
+       69,   69,   69,   69,   69,   69,   69,   69,   69,   69,
453
+       69,   69,   69,   69,   69,   69,   69,   69,   69,   69,
454
+       69,   69,   69,   69,   69,   69
445 455
     } ;
446 456
 
447
-static const flex_int16_t yy_chk[112] =
457
+static const flex_int16_t yy_chk[157] =
448 458
     {   0,
449 459
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
450 460
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
451 461
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
452
-        1,    1,    1,   15,   22,   21,   24,   22,   29,   15,
453
-       21,   22,   23,   23,   29,   24,   32,   34,   35,   36,
454
-       49,   45,   35,   36,   41,   39,   32,   39,   34,   42,
455
-       46,   41,   45,   46,   47,   44,   42,   43,   40,   38,
456
-       33,   31,   30,   26,   20,    7,    3,   48,   48,   48,
457
-       48,   48,   48,   48,   48,   48,   48,   48,   48,   48,
458
-       48,   48,   48,   48,   48,   48,   48,   48,   48,   48,
459
-
460
-       48,   48,   48,   48,   48,   48,   48,   48,   48,   48,
461
-       48
462
+        1,    1,    1,    1,    1,    1,    1,    1,    1,   16,
463
+       22,   23,   24,   25,   25,   16,   24,   26,   23,   27,
464
+       22,   24,   27,   28,   34,   40,   41,   43,   28,   26,
465
+       34,   44,   45,   46,   40,   50,   47,   44,   45,   41,
466
+       51,   43,   47,   51,   53,   54,   55,   46,   50,   56,
467
+       57,   60,   70,   53,   54,   61,   56,   62,   64,   65,
468
+       62,   55,   64,   68,   57,   60,   67,   61,   65,   66,
469
+
470
+       63,   59,   58,   52,   49,   42,   36,   35,   30,   21,
471
+       20,   19,   18,    8,    7,    3,   69,   69,   69,   69,
472
+       69,   69,   69,   69,   69,   69,   69,   69,   69,   69,
473
+       69,   69,   69,   69,   69,   69,   69,   69,   69,   69,
474
+       69,   69,   69,   69,   69,   69,   69,   69,   69,   69,
475
+       69,   69,   69,   69,   69,   69
462 476
     } ;
463 477
 
464 478
 static yy_state_type yy_last_accepting_state;
@@ -476,7 +490,7 @@ int yy_flex_debug = 0;
476 490
 #define YY_RESTORE_YY_MORE_OFFSET
477 491
 char *yytext;
478 492
 #line 1 "analyse_lexicale.lex"
479
-#line 480 "lex.yy.c"
493
+#line 494 "lex.yy.c"
480 494
 
481 495
 #define INITIAL 0
482 496
 
@@ -693,10 +707,10 @@ YY_DECL
693 707
 		}
694 708
 
695 709
 	{
696
-#line 35 "analyse_lexicale.lex"
710
+#line 41 "analyse_lexicale.lex"
697 711
 
698 712
 
699
-#line 700 "lex.yy.c"
713
+#line 714 "lex.yy.c"
700 714
 
701 715
 	while ( /*CONSTCOND*/1 )		/* loops until end-of-file is reached */
702 716
 		{
@@ -723,13 +737,13 @@ yy_match:
723 737
 			while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
724 738
 				{
725 739
 				yy_current_state = (int) yy_def[yy_current_state];
726
-				if ( yy_current_state >= 49 )
740
+				if ( yy_current_state >= 70 )
727 741
 					yy_c = yy_meta[yy_c];
728 742
 				}
729 743
 			yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
730 744
 			++yy_cp;
731 745
 			}
732
-		while ( yy_base[yy_current_state] != 78 );
746
+		while ( yy_base[yy_current_state] != 117 );
733 747
 
734 748
 yy_find_action:
735 749
 		yy_act = yy_accept[yy_current_state];
@@ -755,131 +769,171 @@ do_action:	/* This label is used only to access EOF actions. */
755 769
 
756 770
 case 1:
757 771
 YY_RULE_SETUP
758
-#line 37 "analyse_lexicale.lex"
759
-{printf("tADD");}
772
+#line 43 "analyse_lexicale.lex"
773
+{return tADD ;}
760 774
 	YY_BREAK
761 775
 case 2:
762 776
 YY_RULE_SETUP
763
-#line 38 "analyse_lexicale.lex"
764
-{printf("tSUB");}
777
+#line 44 "analyse_lexicale.lex"
778
+{return tSUB ;}
765 779
 	YY_BREAK
766 780
 case 3:
767 781
 YY_RULE_SETUP
768
-#line 39 "analyse_lexicale.lex"
769
-{printf("tMUL");}
782
+#line 45 "analyse_lexicale.lex"
783
+{return tMUL ;}
770 784
 	YY_BREAK
771 785
 case 4:
772 786
 YY_RULE_SETUP
773
-#line 40 "analyse_lexicale.lex"
774
-{printf("tDIV");}
787
+#line 46 "analyse_lexicale.lex"
788
+{return tDIV ;}
775 789
 	YY_BREAK
776 790
 case 5:
777 791
 YY_RULE_SETUP
778
-#line 41 "analyse_lexicale.lex"
779
-{printf("tPO");}
792
+#line 48 "analyse_lexicale.lex"
793
+{return tPO ;}
780 794
 	YY_BREAK
781 795
 case 6:
782 796
 YY_RULE_SETUP
783
-#line 42 "analyse_lexicale.lex"
784
-{printf("tPF");}
797
+#line 49 "analyse_lexicale.lex"
798
+{return tPF ;}
785 799
 	YY_BREAK
786 800
 case 7:
787 801
 YY_RULE_SETUP
788
-#line 43 "analyse_lexicale.lex"
789
-{printf("tAO");}
802
+#line 50 "analyse_lexicale.lex"
803
+{return tAO ;}
790 804
 	YY_BREAK
791 805
 case 8:
792 806
 YY_RULE_SETUP
793
-#line 44 "analyse_lexicale.lex"
794
-{printf("tAF");}
807
+#line 51 "analyse_lexicale.lex"
808
+{return tAF ;}
795 809
 	YY_BREAK
796 810
 case 9:
797 811
 YY_RULE_SETUP
798
-#line 45 "analyse_lexicale.lex"
799
-{printf("tPV");}
812
+#line 53 "analyse_lexicale.lex"
813
+{return tPV ;}
800 814
 	YY_BREAK
801 815
 case 10:
802 816
 YY_RULE_SETUP
803
-#line 46 "analyse_lexicale.lex"
804
-{printf("tVIRGULE");}
817
+#line 54 "analyse_lexicale.lex"
818
+{}
805 819
 	YY_BREAK
806 820
 case 11:
821
+/* rule 11 can match eol */
807 822
 YY_RULE_SETUP
808
-#line 47 "analyse_lexicale.lex"
809
-{printf("tEGAL");}
823
+#line 55 "analyse_lexicale.lex"
824
+{}
810 825
 	YY_BREAK
811 826
 case 12:
812 827
 YY_RULE_SETUP
813
-#line 48 "analyse_lexicale.lex"
814
-{printf("tENTIER");}
828
+#line 56 "analyse_lexicale.lex"
829
+{return tVIRGULE ;}
815 830
 	YY_BREAK
816 831
 case 13:
817 832
 YY_RULE_SETUP
818
-#line 49 "analyse_lexicale.lex"
819
-{printf("tLT");}
833
+#line 58 "analyse_lexicale.lex"
834
+{return tAFFECTATION ;}
820 835
 	YY_BREAK
821 836
 case 14:
822 837
 YY_RULE_SETUP
823
-#line 50 "analyse_lexicale.lex"
824
-{printf("tGT");}
838
+#line 60 "analyse_lexicale.lex"
839
+{return tEGAL ;}
825 840
 	YY_BREAK
826 841
 case 15:
827 842
 YY_RULE_SETUP
828
-#line 51 "analyse_lexicale.lex"
829
-{printf("tMAIN");}
843
+#line 61 "analyse_lexicale.lex"
844
+{return tDIFF ;}
830 845
 	YY_BREAK
831 846
 case 16:
832 847
 YY_RULE_SETUP
833
-#line 52 "analyse_lexicale.lex"
834
-{printf("tINT");}
848
+#line 62 "analyse_lexicale.lex"
849
+{return tLT ;}
835 850
 	YY_BREAK
836 851
 case 17:
837 852
 YY_RULE_SETUP
838
-#line 53 "analyse_lexicale.lex"
839
-{printf("tPRINT");}
853
+#line 63 "analyse_lexicale.lex"
854
+{return tGT ;}
840 855
 	YY_BREAK
841 856
 case 18:
842 857
 YY_RULE_SETUP
843
-#line 54 "analyse_lexicale.lex"
844
-{printf("tOR");}
858
+#line 64 "analyse_lexicale.lex"
859
+{return tLTE ;}
845 860
 	YY_BREAK
846 861
 case 19:
847 862
 YY_RULE_SETUP
848
-#line 55 "analyse_lexicale.lex"
849
-{printf("tAND");}
863
+#line 65 "analyse_lexicale.lex"
864
+{return tGTE ;}
850 865
 	YY_BREAK
851 866
 case 20:
852 867
 YY_RULE_SETUP
853
-#line 56 "analyse_lexicale.lex"
854
-{printf("tIF");}
868
+#line 66 "analyse_lexicale.lex"
869
+{return tNOT ;}
855 870
 	YY_BREAK
856 871
 case 21:
857 872
 YY_RULE_SETUP
858
-#line 57 "analyse_lexicale.lex"
859
-{printf("tELSE");}
873
+#line 69 "analyse_lexicale.lex"
874
+{return tMAIN ;}
860 875
 	YY_BREAK
861 876
 case 22:
862 877
 YY_RULE_SETUP
863
-#line 58 "analyse_lexicale.lex"
864
-{printf("tVAR");}
878
+#line 70 "analyse_lexicale.lex"
879
+{return tINT ;}
865 880
 	YY_BREAK
866 881
 case 23:
867 882
 YY_RULE_SETUP
868
-#line 59 "analyse_lexicale.lex"
869
-{}
883
+#line 71 "analyse_lexicale.lex"
884
+{return tPRINT ;}
870 885
 	YY_BREAK
871 886
 case 24:
872
-/* rule 24 can match eol */
873 887
 YY_RULE_SETUP
874
-#line 60 "analyse_lexicale.lex"
875
-{}
888
+#line 72 "analyse_lexicale.lex"
889
+{return tRETURN ;}
876 890
 	YY_BREAK
877 891
 case 25:
878 892
 YY_RULE_SETUP
879
-#line 61 "analyse_lexicale.lex"
893
+#line 74 "analyse_lexicale.lex"
894
+{return tOR ;}
895
+	YY_BREAK
896
+case 26:
897
+YY_RULE_SETUP
898
+#line 75 "analyse_lexicale.lex"
899
+{return tAND ;}
900
+	YY_BREAK
901
+case 27:
902
+YY_RULE_SETUP
903
+#line 77 "analyse_lexicale.lex"
904
+{return tIF ;}
905
+	YY_BREAK
906
+case 28:
907
+YY_RULE_SETUP
908
+#line 78 "analyse_lexicale.lex"
909
+{return tELSE ;}
910
+	YY_BREAK
911
+case 29:
912
+YY_RULE_SETUP
913
+#line 79 "analyse_lexicale.lex"
914
+{return tWHILE ;}
915
+	YY_BREAK
916
+case 30:
917
+YY_RULE_SETUP
918
+#line 81 "analyse_lexicale.lex"
919
+{return tCONST ;}
920
+	YY_BREAK
921
+case 31:
922
+YY_RULE_SETUP
923
+#line 82 "analyse_lexicale.lex"
924
+{return tENTIER ;}
925
+	YY_BREAK
926
+case 32:
927
+YY_RULE_SETUP
928
+#line 83 "analyse_lexicale.lex"
929
+{return tVAR ;}
930
+	YY_BREAK
931
+case 33:
932
+YY_RULE_SETUP
933
+#line 85 "analyse_lexicale.lex"
880 934
 ECHO;
881 935
 	YY_BREAK
882
-#line 883 "lex.yy.c"
936
+#line 937 "lex.yy.c"
883 937
 case YY_STATE_EOF(INITIAL):
884 938
 	yyterminate();
885 939
 
@@ -1176,7 +1230,7 @@ static int yy_get_next_buffer (void)
1176 1230
 		while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
1177 1231
 			{
1178 1232
 			yy_current_state = (int) yy_def[yy_current_state];
1179
-			if ( yy_current_state >= 49 )
1233
+			if ( yy_current_state >= 70 )
1180 1234
 				yy_c = yy_meta[yy_c];
1181 1235
 			}
1182 1236
 		yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
@@ -1204,11 +1258,11 @@ static int yy_get_next_buffer (void)
1204 1258
 	while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
1205 1259
 		{
1206 1260
 		yy_current_state = (int) yy_def[yy_current_state];
1207
-		if ( yy_current_state >= 49 )
1261
+		if ( yy_current_state >= 70 )
1208 1262
 			yy_c = yy_meta[yy_c];
1209 1263
 		}
1210 1264
 	yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
1211
-	yy_is_jam = (yy_current_state == 48);
1265
+	yy_is_jam = (yy_current_state == 69);
1212 1266
 
1213 1267
 		return yy_is_jam ? 0 : yy_current_state;
1214 1268
 }
@@ -1884,14 +1938,14 @@ void yyfree (void * ptr )
1884 1938
 
1885 1939
 #define YYTABLES_NAME "yytables"
1886 1940
 
1887
-#line 61 "analyse_lexicale.lex"
1941
+#line 85 "analyse_lexicale.lex"
1888 1942
 
1889 1943
 int yywrap(void){
1890 1944
     return 1;
1891 1945
 }
1892
-int main(void){
1893
-    yylex();
1894
-}
1946
+//int main(void){
1947
+//    yylex();
1948
+//}
1895 1949
 
1896 1950
 
1897 1951
 

+ 31
- 0
script.sh View File

@@ -0,0 +1,31 @@
1
+bison -d -t analyse_syntaxique.y -v
2
+flex analyse_lexicale.lex 
3
+gcc *.c -ly
4
+echo "
5
+    int fonction1(int toto){
6
+    toto = toto + 1 ;
7
+    return toto;
8
+    }
9
+
10
+    int fonction2(){
11
+        int i = 0;
12
+        while (i <= 2){
13
+            printf(i);
14
+            i = i +1 ;
15
+        }
16
+        return i;
17
+    }
18
+
19
+    int main(){
20
+        const int toto = 1, mimi, lolo = 6;
21
+        int tata = 5, lala;
22
+
23
+        if (tata == 5){
24
+            fonction1(lolo);
25
+        } else if (toto == 1){
26
+            fonction2();
27
+        }
28
+
29
+        return 1;
30
+    }
31
+" | ./a.out

+ 27
- 0
test View File

@@ -0,0 +1,27 @@
1
+
2
+int fonction1(int toto){
3
+    toto = toto + 1 ;
4
+    return toto;
5
+}
6
+
7
+int fonction2(){
8
+    int i = 0;
9
+    while (i <= 2){
10
+        print(i);
11
+        i = i +1 ;
12
+    }
13
+    return i;
14
+}
15
+
16
+int main(){
17
+    const int toto = 1, mimi, lolo = 6;
18
+    int tata = 5, lala;
19
+
20
+    if (tata == 5){
21
+        fonction(lolo);
22
+    } else if (toto == 1){
23
+        fonction2();
24
+    }
25
+
26
+    return 1;
27
+}

Loading…
Cancel
Save