Files
zut-n1-kompilatory/z5.l
2025-12-04 00:03:08 +01:00

53 lines
1.2 KiB
Plaintext

%{
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include "def.tab.hh"
#define INFILE_ERROR 1
#define OUTFILE_ERROR 2
#define YY_DECL int yyFlexLexer::yylex()
%}
%option noyywrap
%option c++
%option yylineno
%%
"let" {std::fprintf(stdout, "LET\n"); return LET;}
"Int" {std::fprintf(stdout, "INT_TYPE\n"); return INT_TYPE;}
":" {std::fprintf(stdout, ":\n"); return COLON;}
";" {std::fprintf(stdout, ";\n"); return SEMICOLON;}
\+ {std::fprintf(stdout, "+\n"); return '+';}
\* {std::fprintf(stdout, "*\n"); return '*';}
\( {std::fprintf(stdout, "(\n"); return '(';}
\) {std::fprintf(stdout, ")\n"); return ')';}
\/ {std::fprintf(stdout, "/\n"); return '/';}
\- {std::fprintf(stdout, "-\n"); return '-';}
\= {std::fprintf(stdout, "=\n"); return '=';}
[0-9]+ {
std::fprintf(stdout, "liczba: %s\n", yytext);
yylval.ival = atoi(yytext);
return INT_LIT;
}
[A-Za-z_][A-Za-z0-9_]* {
std::fprintf(stdout, "identyfikator: %s\n", yytext);
yylval.text = strdup(yytext);
return ID;
}
[ \t]+ {/* ignoruj białe znaki */}
\n {/* nowa linia */}
. {
std::fprintf(stderr, "Blad leksykalny w linii %d\n", lineno());
exit(1);
}
%%