Add c++ support

This commit is contained in:
2025-12-04 00:03:08 +01:00
parent 0474558835
commit 5762271fd0
8 changed files with 130 additions and 99 deletions

View File

@@ -434,9 +434,10 @@ static const flex_int32_t yy_rule_can_match_eol[18] =
#define YY_RESTORE_YY_MORE_OFFSET
#line 1 "z5.l"
#line 2 "z5.l"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include "def.tab.hh"
#define INFILE_ERROR 1
@@ -444,10 +445,8 @@ static const flex_int32_t yy_rule_can_match_eol[18] =
#define YY_DECL int yyFlexLexer::yylex()
extern int yylineno;
void yyerror(char *msg, ...);
#line 448 "lex.yy.cc"
#line 449 "lex.yy.cc"
#line 450 "lex.yy.cc"
#define INITIAL 0
@@ -579,7 +578,8 @@ YY_DECL
}
{
#line 20 "z5.l"
#line 19 "z5.l"
#line 584 "lex.yy.cc"
@@ -651,98 +651,101 @@ do_action: /* This label is used only to access EOF actions. */
case 1:
YY_RULE_SETUP
#line 21 "z5.l"
{fprintf(stdout, "LET\n"); return LET;}
{std::fprintf(stdout, "LET\n"); return LET;}
YY_BREAK
case 2:
YY_RULE_SETUP
#line 22 "z5.l"
{fprintf(stdout, "INT_TYPE\n"); return INT_TYPE;}
{std::fprintf(stdout, "INT_TYPE\n"); return INT_TYPE;}
YY_BREAK
case 3:
YY_RULE_SETUP
#line 23 "z5.l"
{fprintf(stdout, ":\n"); return COLON;}
{std::fprintf(stdout, ":\n"); return COLON;}
YY_BREAK
case 4:
YY_RULE_SETUP
#line 24 "z5.l"
{fprintf(stdout, ";\n"); return SEMICOLON;}
{std::fprintf(stdout, ";\n"); return SEMICOLON;}
YY_BREAK
case 5:
YY_RULE_SETUP
#line 25 "z5.l"
{fprintf(stdout, "+\n"); return '+';}
{std::fprintf(stdout, "+\n"); return '+';}
YY_BREAK
case 6:
YY_RULE_SETUP
#line 26 "z5.l"
{fprintf(stdout, "*\n"); return '*';}
{std::fprintf(stdout, "*\n"); return '*';}
YY_BREAK
case 7:
YY_RULE_SETUP
#line 27 "z5.l"
{fprintf(stdout, "(\n"); return '(';}
{std::fprintf(stdout, "(\n"); return '(';}
YY_BREAK
case 8:
YY_RULE_SETUP
#line 28 "z5.l"
{fprintf(stdout, ")\n"); return ')';}
{std::fprintf(stdout, ")\n"); return ')';}
YY_BREAK
case 9:
YY_RULE_SETUP
#line 29 "z5.l"
{fprintf(stdout, "/\n"); return '/';}
{std::fprintf(stdout, "/\n"); return '/';}
YY_BREAK
case 10:
YY_RULE_SETUP
#line 30 "z5.l"
{fprintf(stdout, "-\n"); return '-';}
{std::fprintf(stdout, "-\n"); return '-';}
YY_BREAK
case 11:
YY_RULE_SETUP
#line 31 "z5.l"
{fprintf(stdout, "=\n"); return '=';}
{std::fprintf(stdout, "=\n"); return '=';}
YY_BREAK
case 12:
YY_RULE_SETUP
#line 32 "z5.l"
#line 33 "z5.l"
{
fprintf(stdout, "liczba: %s\n", yytext);
std::fprintf(stdout, "liczba: %s\n", yytext);
yylval.ival = atoi(yytext);
return INT_LIT;
}
YY_BREAK
case 13:
YY_RULE_SETUP
#line 37 "z5.l"
#line 39 "z5.l"
{
fprintf(stdout, "identyfikator: %s\n", yytext);
std::fprintf(stdout, "identyfikator: %s\n", yytext);
yylval.text = strdup(yytext);
return ID;
}
YY_BREAK
case 14:
YY_RULE_SETUP
#line 42 "z5.l"
{;}
#line 45 "z5.l"
{/* ignoruj białe znaki */}
YY_BREAK
case 15:
/* rule 15 can match eol */
YY_RULE_SETUP
#line 43 "z5.l"
{yylineno++;}
#line 46 "z5.l"
{/* nowa linia */}
YY_BREAK
case 16:
YY_RULE_SETUP
#line 44 "z5.l"
{yyerror("Blad leksykalny\n");}
#line 47 "z5.l"
{
std::fprintf(stderr, "Blad leksykalny w linii %d\n", lineno());
exit(1);
}
YY_BREAK
case 17:
YY_RULE_SETUP
#line 45 "z5.l"
#line 52 "z5.l"
ECHO;
YY_BREAK
#line 745 "lex.yy.cc"
#line 748 "lex.yy.cc"
case YY_STATE_EOF(INITIAL):
yyterminate();
@@ -1714,11 +1717,6 @@ void yyfree (void * ptr )
#define YYTABLES_NAME "yytables"
#line 45 "z5.l"
#line 52 "z5.l"
void yyerror(char *msg, ...)
{
printf("%d: %s", yylineno, msg);
exit(1);
}