Revert "Add c++ support"

This reverts commit 5762271fd0.
This commit is contained in:
2025-12-04 22:30:44 +01:00
parent 5762271fd0
commit eb527222b0
8 changed files with 99 additions and 130 deletions

59
z5.l
View File

@@ -1,52 +1,45 @@
%{
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "def.tab.hh"
#define INFILE_ERROR 1
#define OUTFILE_ERROR 2
#define YY_DECL int yyFlexLexer::yylex()
extern int yylineno;
void yyerror(char *msg, ...);
%}
%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 '=';}
"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]+ {
std::fprintf(stdout, "liczba: %s\n", yytext);
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);
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);
}
[ \t]+ {;}
\n {yylineno++;}
. {yyerror("Blad leksykalny\n");}
%%
void yyerror(char *msg, ...)
{
printf("%d: %s", yylineno, msg);
exit(1);
}