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

31
def.yy
View File

@@ -1,14 +1,17 @@
%{
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <FlexLexer.h>
#define INFILE_ERROR 1
#define OUTFILE_ERROR 2
extern int yylex(void);
extern void yyerror(const char *s);
extern int yylineno;
extern FILE *yyin;
extern yyFlexLexer lexer;
void yyerror(const char *s);
int yylex();
%}
%union {
@@ -45,7 +48,7 @@ statement
variable_declaration
: LET ID COLON INT_TYPE '=' expression SEMICOLON
{ printf("Deklaracja zmiennej: %s\n", $2); }
{ printf("Deklaracja zmiennej: %s\n", $2); free($2); }
;
expression
@@ -55,11 +58,21 @@ expression
| expression '/' expression { printf("Wyrazenie z /\n"); }
| '(' expression ')' { printf("Wyrazenie w nawiasach\n"); }
| INT_LIT { printf("Literal calkowity: %d\n", $1); }
| ID { printf("Identyfikator: %s\n", $1); }
| ID { printf("Identyfikator: %s\n", $1); free($1); }
;
%%
yyFlexLexer lexer;
int yylex() {
return lexer.yylex();
}
void yyerror(const char *s) {
fprintf(stderr, "Blad: %s w linii %d\n", s, lexer.lineno());
}
int main(int argc, char *argv[]) {
yyparse();
return 0;