Tali Elies 8 months ago
parent
commit
62ec7ad082

BIN
Analyse_Lexicale/a.out View File


+ 38
- 0
Analyse_Lexicale/al.lex View File

@@ -0,0 +1,38 @@
1
+%{
2
+#include "as.tab.h"
3
+#include <stdio.h>
4
+%}
5
+
6
+%%
7
+
8
+"main"      { printf("tMAIN\n");} 
9
+"{"         { printf("tOBRACKET\n"); }
10
+"}"         { printf("tCBRACKET\n"); }
11
+"("			{ printf("tOBRACE\n"); }
12
+")"			{ printf("tCBRACE\n"); }
13
+"const"     { printf("tCONST\n"); }
14
+"int"       { printf("tINT\n"); }
15
+"printf"    { printf("tPRINTF\n"); } //Degeu mais à degager
16
+
17
+
18
+
19
+
20
+[0-9]+	{ printf("tNB\n"); }
21
+[0-9]+e[0-9]+	{ printf("tNBEXP\n"); } //Renvoyer le token tNB et pas tNBEXP
22
+"+"			{ printf("tADD\n"); }
23
+"-"			{ printf("tSUB\n"); }
24
+"*"         { printf("tMUL\n"); }
25
+"/"         { printf("tDIV\n"); }
26
+"="         { printf("tEQ\n"); }
27
+";"			{ printf("tPV\n"); }
28
+" "			{ printf("tSPACE\n"); } //Ne pas les retourner à Yacc
29
+"   "       { printf("tTAB\n"); } //Ne pas les retourner à Yacc
30
+","         { printf("tCOMA\n"); }
31
+"\n"        { printf("tRC\n") ; } //Ne pas les retourner à Yacc
32
+[a-zA-Z][a-zA-Z0-9_]* { printf("tID\n"); }
33
+.				{ return tERROR; }
34
+
35
+%%
36
+
37
+
38
+int yywrap(void){return 1;}

+ 1479
- 0
Analyse_Lexicale/as.tab.c
File diff suppressed because it is too large
View File


+ 81
- 0
Analyse_Lexicale/as.tab.h View File

@@ -0,0 +1,81 @@
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_AS_TAB_H_INCLUDED
34
+# define YY_YY_AS_TAB_H_INCLUDED
35
+/* Debug traces.  */
36
+#ifndef YYDEBUG
37
+# define YYDEBUG 0
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
+    tNB = 258,
49
+    tADD = 259,
50
+    tSUB = 260,
51
+    tOB = 261,
52
+    tCB = 262,
53
+    tPV = 263,
54
+    tERROR = 264,
55
+    tMAIN = 265
56
+  };
57
+#endif
58
+
59
+/* Value type.  */
60
+#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
61
+
62
+union YYSTYPE
63
+{
64
+#line 1 "as.y" /* yacc.c:1909  */
65
+
66
+	int nombre;
67
+
68
+#line 69 "as.tab.h" /* yacc.c:1909  */
69
+};
70
+
71
+typedef union YYSTYPE YYSTYPE;
72
+# define YYSTYPE_IS_TRIVIAL 1
73
+# define YYSTYPE_IS_DECLARED 1
74
+#endif
75
+
76
+
77
+extern YYSTYPE yylval;
78
+
79
+int yyparse (void);
80
+
81
+#endif /* !YY_YY_AS_TAB_H_INCLUDED  */

+ 44
- 0
Analyse_Lexicale/as.y View File

@@ -0,0 +1,44 @@
1
+%union {
2
+	int nombre;
3
+}
4
+
5
+%token tMAIN
6
+%token tOBRACKET tCBRACKET
7
+%token tOBRACE tCBRACE
8
+%token tINT
9
+%token tCONST
10
+%token tPV tCOMA
11
+%token tMUL tDIV tADD tSUB tEQ
12
+%token<nombre> tNB tNBEXP
13
+%token tPRINTF
14
+%token tERROR
15
+
16
+//%type<nombre> E
17
+
18
+/* 1 + 2 + 3 + 4 */
19
+
20
+/* E => E + E => 1 + E => 1 + E + E ... */
21
+/* E => E + E => E + 4 => E + E + 4 ... */
22
+
23
+%%
24
+
25
+/* S -> E ; S
26
+ * S ->
27
+ */
28
+S : E tPV
29
+						{ printf("RES: %d\n", $1); }
30
+		S
31
+	|					{ printf("END\n"); }
32
+	;
33
+
34
+E : E tADD E	{ $$ = $1 + $3; }
35
+	| E tSUB E	{ $$ = $1 - $3; }
36
+	| tOB E tCB	{ $$ = $2; }
37
+	| tNB				{ $$ = $1; }
38
+	;
39
+
40
+%%
41
+
42
+void main(void) {
43
+	yyparse();
44
+}

+ 5
- 0
Analyse_Lexicale/comp.sh View File

@@ -0,0 +1,5 @@
1
+bison -d as.y
2
+flex al.lex 
3
+gcc *.c -ly
4
+cat progC | ./a.out 
5
+

+ 52
- 0
Analyse_Lexicale/grammaire_c_minimaliste View File

@@ -0,0 +1,52 @@
1
+les fonctions (avec parametres)
2
+le if
3
+le while
4
+les declarations
5
+les affectations
6
+les operations arith.
7
+le retour de fonction
8
+l'invocation de fonctions
9
+
10
+
11
+C : Fonctions ;
12
+Fonctions : Fonction Fonctions | Fonction ;
13
+
14
+Fonction : tInt tID tPO Params tPF Body ;
15
+
16
+Params : | Param SuiteParams ;
17
+Param : tInt tID ;
18
+
19
+SuiteParams : tVirgule Param SuiteParams | ;
20
+
21
+// Ps : P Ps | ;
22
+// P : tInt tID tVirgule
23
+// Ps =>* tInt tID tVirgule tInt tID tVirgule
24
+// Ps => P Ps => P P Ps ...
25
+
26
+Body : tAO Instructions tAF ;
27
+
28
+Instructions : Instruction Instructions | ;
29
+
30
+Instruction : Aff | If | While | Return | Decl | Invocation tPV ;
31
+
32
+Aff : tID tEQ E tPV ;
33
+
34
+E : tNB | tID | E tADD E | E tMUL E | E tMINUS E | E tDIV E | Invocation | tPO E tPF | tMINUS E ;
35
+
36
+// E : tID tADD tID | ...
37
+
38
+If : tIF tPO Cond tPF Body ;
39
+
40
+Cond : Cond tAND Cond | Cond tOR Cond | E tEQ2 E | E tINF E | tNOT Cond ;
41
+
42
+Invocation : tID tPO  Args  tPF ;
43
+
44
+Args : .... cf params
45
+
46
+Return : tRET E tPV ;
47
+
48
+
49
+
50
+
51
+
52
+

+ 1876
- 0
Analyse_Lexicale/lex.yy.c
File diff suppressed because it is too large
View File


+ 7
- 0
Analyse_Lexicale/progC View File

@@ -0,0 +1,7 @@
1
+#include <stdio.h>
2
+
3
+int main(int x, int i){
4
+   int azertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbn; printf("%d\n", azertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbn);
5
+    int y = 2;
6
+    int res_2 = x + y;
7
+}

+ 7
- 0
Analyse_Lexicale/progC.c View File

@@ -0,0 +1,7 @@
1
+#include <stdio.h>
2
+
3
+int main(int x, int i){
4
+   int azertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbn; printf("%d\n", azertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbn);
5
+    int y = 2;
6
+    int res_2 = x + y;
7
+}

BIN
Analyse_Lexicale/test View File


+ 0
- 0
Analyse_Lexicale/truc View File


Loading…
Cancel
Save