Skip to content
Snippets Groups Projects
Commit 2ea27aec authored by Aliaksei Prybau's avatar Aliaksei Prybau
Browse files

Upload New File

parent cc4e0aa5
Branches
No related merge requests found
%option noyywrap
%option nounput
%option yylineno
%option noinput
%option never-interactive
WHITESPACE [[:space:]]
INTEGER [[:digit:]]+
FLOAT {INTEGER}"."{INTEGER}|"."{INTEGER}
%x COMMENT
%{
#include <stdlib.h>
#include "minako-syntax.tab.h"
%}
%%
{WHITESPACE}+ { /* ignore whitespaces */ }
"//".*\n { /* C++ Comment */ }
"/*" { BEGIN(COMMENT); /* C Comment */ }
<COMMENT>"*/" { BEGIN(INITIAL); }
<COMMENT>"*"[^/]
<COMMENT>[^*]+
"&&" return AND;
"||" return OR;
"==" return EQ;
"!=" return NEQ;
"<=" return LEQ;
">=" return GEQ;
"<" return LSS;
">" return GRT;
"bool" return KW_BOOLEAN;
"do" return KW_DO;
"else" return KW_ELSE;
"float" return KW_FLOAT;
"for" return KW_FOR;
"if" return KW_IF;
"int" return KW_INT;
"printf" return KW_PRINTF;
"return" return KW_RETURN;
"void" return KW_VOID;
"while" return KW_WHILE;
{FLOAT}([eE][\-+]?{INTEGER})? |
{INTEGER}([eE][\-+]?{INTEGER}) {
yylval.floatValue = strtod(yytext, NULL);
return CONST_FLOAT;
}
{INTEGER} {
yylval.intValue = strtol(yytext, NULL, 10);
return CONST_INT;
}
"true" { yylval.intValue = 1; return CONST_BOOLEAN; }
"false" { yylval.intValue = 0; return CONST_BOOLEAN; }
[[:alpha:]][[:alnum:]_]* {
yylval.string = malloc(yyleng + 1);
strcpy(yylval.string, yytext);
return ID;
}
\"[^\n\"]*\" {
yylval.string = malloc(yyleng - 2 + 1);
memcpy(yylval.string, yytext + 1, yyleng - 2);
yylval.string[yyleng - 2] = 0;
return CONST_STRING;
}
. return yytext[0];
%%
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment