Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %{
- #undef yywrap
- #define yywrap() 1
- #include <math.h>
- #include <unistd.h>
- %}
- CONSTANT ["][a-zA-Z0-9 :\*><+!=>><<::\.]*["]
- IDENTIFIER ^[a-zA-Z][a-zA-Z0-9]{0,7}
- DIGIT ^[0-9]
- FLOAT ^[1-9][0-9]*\.*[0-9]*
- %%
- "{" printf("%s with code : %d\n",yytext,2);return 3;
- "}" printf("%s with code : %d\n",yytext,3);return 3;
- "if" printf("%s with code : %d\n",yytext,51);return 3;
- "else" printf("%s with code : %d\n",yytext,52);return 3;
- "(" printf("%s with code : %d\n",yytext,71);return 3;
- ")" printf("%s with code : %d\n",yytext,72);return 3;
- "<" printf("%s with code : %d\n",yytext,73);return 3;
- ">" printf("%s with code : %d\n",yytext,74);return 3;
- "=" printf("%s with code : %d\n",yytext,75);return 3;
- ";" printf("%s with code : %d\n",yytext,76);return 3;
- "*" printf("%s with code : %d\n",yytext,77);return 3;
- "+" printf("%s with code : %d\n",yytext,78);return 3;
- "-" printf("%s with code : %d\n",yytext,79);return 3;
- "#include" printf("%s with code : %d\n",yytext,80);return 3;
- "using namespace" printf("%s with code : %d\n",yytext,81);return 3;
- "int main" printf("%s with code : %d\n",yytext,82);return 3;
- "int" printf("%s with code : %d\n",yytext,83);return 3;
- "double" printf("%s with code : %d\n",yytext,84);return 3;
- "const" printf("%s with code : %d\n",yytext,85);return 3;
- "while" printf("%s with code : %d\n",yytext,86);return 3;
- "cout" printf("%s with code : %d\n",yytext,87);return 3;
- "endl" printf("%s with code : %d\n",yytext,88);return 3;
- "return" printf("%s with code : %d\n",yytext,89);return 3;
- "!=" printf("%s with code : %d\n",yytext,90);return 3;
- "<<" printf("%s with code : %d\n",yytext,91);return 3;
- ">>" printf("%s with code : %d\n",yytext,92);return 3;
- "::" printf("%s with code : %d\n",yytext,93);return 3;
- "," printf("%s with code : %d\n",yytext,94);return 3;
- {CONSTANT} printf("CONSTANT %s \n",yytext);return 0;
- {DIGIT} printf("CONSTANT %s \n",yytext);return 0;
- {FLOAT} printf("CONSTANT %s \n",yytext);return 0;
- {IDENTIFIER} printf("IDENTIFIER %s\n",yytext);return 1;
- [ \t\n]+ /* eat up whitespace */
- . printf("Eroare\n");return -1;
- %%
- //";" printf("%s with code : %d",yytext,95);
- main( argc, argv )
- int argc;
- char **argv;
- {
- ++argv, --argc; /* skip over program name */
- if ( argc > 0 )
- yyin = fopen( argv[0], "r" );
- else
- yyin = stdin;
- int token = -1;
- while (token !=0) {
- token = yylex();
- printf("TOKEN IS %d\n",token);
- token = yylex();
- }
- // yylex();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement