Last active
August 29, 2015 14:18
-
-
Save jogonba2/67ea935c6084461f0913 to your computer and use it in GitHub Desktop.
CMinilan.l
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Author: Overxfl0w13 // | |
BEGGIN begin | |
END end | |
DIGIT [0-9] | |
LETTER [a-zA-Z] | |
BLANK [ \t] | |
LINE \n | |
SCOMMENT ("//"({LETTER}|{BLANK})*) | |
MCOMMENT ("/**"({LETTER}|{BLANK}|{LINE})*"**/") | |
EOS ";" | |
INTEGER {DIGIT}+ | |
REAL ({INTEGER}"."{INTEGER}) | |
MINUS "-" | |
MULT "*" | |
DIV "/" | |
PLUS "+" | |
LP "(" | |
RP ")" | |
PRINT print | |
LT "<" | |
GT ">" | |
EQ "==" | |
SET "=" | |
VARIABLE ({LETTER}+({LETTER}|{DIGIT})*) | |
PARSEERROR . | |
%{ | |
#include <stdio.h> | |
#include "y.tab.h" | |
%} | |
%% | |
{INTEGER} { | |
printf("SCANNER:: INTEGER %d\n",atoi(yytext)); | |
yylval = atoi(yytext); | |
return INTEGER; | |
} | |
{REAL} { | |
printf("SCANNER:: REAL %f\n",atof(yytext)); | |
yylval = atof(yytext); | |
return FLOAT; | |
} | |
{MINUS} { | |
printf("SCANNER:: MINUS\n"); | |
return MINUS; | |
} | |
{PLUS} { | |
printf("SCANNER:: PLUS\n"); | |
return PLUS; | |
} | |
{MULT} { | |
printf("SCANNER:: MULT\n"); | |
return MULT; | |
} | |
{DIV} { | |
printf("SCANNER:: DIV\n"); | |
return DIV; | |
} | |
{RP} { | |
printf("SCANNER:: RP\n"); | |
return RP; | |
} | |
{LP} { | |
printf("SCANNER:: LP\n"); | |
return LP; | |
} | |
{PRINT} { | |
printf("SCANNER:: PRINT\n"); | |
yylval = *yytext; // No seguro // | |
return PRINT; | |
} | |
{BEGGIN} { | |
printf("SCANNER:: BEGIN\n"); | |
return BEGGIN; | |
} | |
{END} { | |
printf("SCANNER:: END\n"); | |
return END; | |
} | |
{EOS} { | |
printf("SCANNER:: EOS\n"); | |
return EOS; | |
} | |
{LT} { | |
printf("SCANNER:: LT\n"); | |
return *yytext; | |
} | |
{GT} { | |
printf("SCANNER:: GT\n"); | |
return *yytext; | |
} | |
{EQ} { | |
printf("SCANNER:: EQ\n"); | |
return *yytext; | |
} | |
{SET} { | |
printf("SCANNER:: SET\n"); | |
return *yytext; | |
} | |
{VARIABLE} { | |
printf("SCANNER:: ID <%s> \n",yytext); | |
yylval = *yytext; | |
return VARIABLE; | |
} | |
{SCOMMENT} { | |
printf("SCANNER:: SIMPLE COMMENT,ignoring: <%s>\n",yytext); | |
} | |
{MCOMMENT} { | |
printf("SCANNER:: MULT COMMENT,ignoring: <%s>\n",yytext); | |
} | |
{PARSEERROR} { | |
printf("SCANNER:: Unmatched input: <%s> \n",yytext); | |
} | |
%% | |
int yywrap(void){ return 1; } | |
//int main(void){ | |
// yylex(); | |
// return 0; | |
//} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment