c67370df93b76d9f8c905f569322c4c60691a9e0
7 #include "global_vars.h"
8 #include "lexical_analyzer.h"
9 #include "syntactic_analyzer.h"
10 #include "print_helper.h"
12 void do_lexical_analysis() {
13 c
= fgetwc(source
); // lecture du premier caractere
17 token
[tokenFound
].type
= tokenTypestr
[tokenType
];
19 } while (tokenType
!= FIN
); // tant que la fin du fichier n'est pas atteinte
22 void do_syntactic_analysis() {
23 c
= fgetwc(source
); // lecture du premier caractere
27 void print_usage(const char* name
) {
28 fprintf(stdout
,"Usage: %s [options]\n"
29 "Where [options] are:\n"
30 " -h, --help: display this help message\n"
31 " -l, --lexical-only: do only the lexical analysis\n"
32 " -i, --input<filename>: use <filename> as input file instead of standard input\n"
33 " -o, --output<filename>: use <filename> as output file instead of standard output\n",
37 int main(int argc
, char **argv
) {
38 /* In and out files name */
39 const char* in_file
= NULL
;
40 const char* out_file
= NULL
;
44 /* getopt_long stores the option index here. */
47 static struct option long_options
[] =
49 {"help", no_argument
, &hflag
, 1},
50 {"input", optional_argument
, NULL
, 'i'},
51 {"lexical-only", no_argument
, &lflag
, 1},
52 {"output", optional_argument
, NULL
, 'o'},
58 while ((c_in
= getopt_long(argc
, argv
, "hi::lo::", long_options
,
59 &option_index
)) != -1) {
78 /* getopt_long() set a variable, just keep going */
81 /* missing option argument */
82 pr_error("%s: option '-%c' requires an argument\n",
88 pr_error("%s: option '-%c' is invalid: ignored\n",
94 if (in_file
!= NULL
) {
95 // Ouvre le fichier source en lecture seulement (le fichier doit exister) :
96 source
= fopen(in_file
, "r+");
98 pr_error("Fail to open file %s\n", in_file
);
105 if (out_file
!= NULL
) {
106 // Cree et ouvre le fichier cible en lecture/ecriture
107 // avec suppression du contenu au prealable :
108 target
= fopen(out_file
, "w+");
109 if (target
== NULL
) {
110 pr_error("Fail to open file %s\n", out_file
);
118 print_usage(argv
[0]);
120 do_lexical_analysis();
122 do_syntactic_analysis();
125 if (source
!= NULL
) fclose(source
); // fermeture du fichier source
126 if (target
!= NULL
) fclose(target
); // fermeture du fichier target