diff --git a/Makefile b/Makefile index a41a741..200b012 100644 --- a/Makefile +++ b/Makefile @@ -5,18 +5,20 @@ BIN=out CC=gcc CFLAGS=-Wall -g -OBJ=y.tab.o lex.yy.o table.o +OBJ=yacc.tab.o lex.yy.o table.o all: $(BIN) @touch testFile # to prevent an error in case of deletion ./out < testFile +build: $(BIN) + %.o: %.c $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@ -y.tab.c: $(GRM) - bison --yacc -d $< +yacc.tab.c: $(GRM) + bison -d $< lex.yy.c: $(LEX) flex $< diff --git a/lex.l b/lex.l index 7d90db3..f4da442 100644 --- a/lex.l +++ b/lex.l @@ -1,8 +1,8 @@ %{ -#include "y.tab.h" +#include "table.h" +#include "yacc.tab.h" %} - /*options for compiling*/ %option noyywrap %option noinput @@ -52,9 +52,9 @@ INT_HEX 0x[0-9a-fA-F]+ ";" return(tSEMI); "," return(tCOMMA); -{ID} return(tID); -{INT_DEC} return(tNB); -{INT_HEX} return(tNB); +{ID} {strncpy(yylval.str, yytext, NAME_MAX_LENGTH); return(tID);} +{INT_DEC} {yylval.nbInt = atoi(yytext); return(tNB);} +{INT_HEX} {yylval.nbInt = atoi(yytext); return(tNB);} /*comments are ignored, same for spaces and lines*/ diff --git a/yacc.y b/yacc.y index 63165c1..4a07cc7 100644 --- a/yacc.y +++ b/yacc.y @@ -1,5 +1,3 @@ -%define parse.error detailed - %{ #include #include @@ -11,8 +9,7 @@ void yyerror (const char *); } -// TODO : PROBLEM DOES'NT COMPILE (enumVarType doesn't exist) -%union {int nbInt; /*enumVarType*/ int type; char* string;} +%union {char str[NAME_MAX_LENGTH]; int nbInt; enumVarType type; } /*loops keywords*/ %token tWHILE tIF tELSE /*reserved keywords*/ @@ -31,7 +28,7 @@ %token tLBRACE tRBRACE tLPAR tRPAR tSEMI tCOMMA /*nametags and values*/ -%token tID +%token tID %token tNB