46 lines
1.1 KiB
Plaintext
46 lines
1.1 KiB
Plaintext
%{
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <stdio.h>
|
|
#include "def.tab.hh"
|
|
|
|
#define INFILE_ERROR 1
|
|
#define OUTFILE_ERROR 2
|
|
|
|
void yyerror(const char *msg, ...);
|
|
%}
|
|
|
|
%option noyywrap
|
|
%%
|
|
"let" {fprintf(stdout, "LET\n"); return LET;}
|
|
"Int" {fprintf(stdout, "INT_TYPE\n"); return INT_TYPE;}
|
|
":" {fprintf(stdout, ":\n"); return COLON;}
|
|
";" {fprintf(stdout, ";\n"); return SEMICOLON;}
|
|
\+ {fprintf(stdout, "+\n"); return '+';}
|
|
\* {fprintf(stdout, "*\n"); return '*';}
|
|
\( {fprintf(stdout, "(\n"); return '(';}
|
|
\) {fprintf(stdout, ")\n"); return ')';}
|
|
\/ {fprintf(stdout, "/\n"); return '/';}
|
|
\- {fprintf(stdout, "-\n"); return '-';}
|
|
\= {fprintf(stdout, "=\n"); return '=';}
|
|
[0-9]+ {
|
|
fprintf(stdout, "liczba: %s\n", yytext);
|
|
yylval.ival = atoi(yytext);
|
|
return INT_LIT;
|
|
}
|
|
[A-Za-z_][A-Za-z0-9_]* {
|
|
fprintf(stdout, "identyfikator: %s\n", yytext);
|
|
yylval.text = strdup(yytext);
|
|
return ID;
|
|
}
|
|
[ \t]+ {;}
|
|
\n {yylineno++;}
|
|
. {yyerror("Blad leksykalny\n");}
|
|
%%
|
|
|
|
void yyerror(const char *msg, ...)
|
|
{
|
|
printf("%d: %s", yylineno, msg);
|
|
exit(1);
|
|
}
|