1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
%{
#include <stdio.h>
#include <string.h>
#include <fstream.h>
#include <iostream.h>
/* extern fstream yyin;*/
int yyparse(void);
extern int yylex(void);
void yyerror(const char *str)
{
fprintf(stderr,"error: %s\n",str);
}
int yywrap()
{
return 1;
}
%}
%start ...
%token ...
%%
....
....
....
.
.
.
.
%%
int parser(int argc, char **argv)
{
char *ligne;
ifstream yyin(argv[0]);
if(!yyin) {
printf("Source file \"%s\" not correct.\n",argv[0]); exit(3);
} else
while (getline( yyin, ligne ) ){
cout << ligne << endl; /*lecture du fichier */
yyparse();
}
yyin.close();
return(0);
}
int main( int argc, char **argv )
{
++argv, --argc; /* skip over program name */
if ( argc > 0 ) return(parser(argc, argv));
else { printf("Error Enter a File\n"); exit(3);}
} |
Partager