added code provides and fixed .h inclusion
This commit is contained in:
parent
1a8e9766a0
commit
6bbc6c2d30
3 changed files with 12 additions and 13 deletions
8
Makefile
8
Makefile
|
@ -5,18 +5,20 @@ BIN=out
|
||||||
CC=gcc
|
CC=gcc
|
||||||
CFLAGS=-Wall -g
|
CFLAGS=-Wall -g
|
||||||
|
|
||||||
OBJ=y.tab.o lex.yy.o table.o
|
OBJ=yacc.tab.o lex.yy.o table.o
|
||||||
|
|
||||||
all: $(BIN)
|
all: $(BIN)
|
||||||
@touch testFile # to prevent an error in case of deletion
|
@touch testFile # to prevent an error in case of deletion
|
||||||
./out < testFile
|
./out < testFile
|
||||||
|
|
||||||
|
|
||||||
|
build: $(BIN)
|
||||||
|
|
||||||
%.o: %.c
|
%.o: %.c
|
||||||
$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
|
$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
|
||||||
|
|
||||||
y.tab.c: $(GRM)
|
yacc.tab.c: $(GRM)
|
||||||
bison --yacc -d $<
|
bison -d $<
|
||||||
|
|
||||||
lex.yy.c: $(LEX)
|
lex.yy.c: $(LEX)
|
||||||
flex $<
|
flex $<
|
||||||
|
|
10
lex.l
10
lex.l
|
@ -1,8 +1,8 @@
|
||||||
%{
|
%{
|
||||||
#include "y.tab.h"
|
#include "table.h"
|
||||||
|
#include "yacc.tab.h"
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
|
||||||
/*options for compiling*/
|
/*options for compiling*/
|
||||||
%option noyywrap
|
%option noyywrap
|
||||||
%option noinput
|
%option noinput
|
||||||
|
@ -52,9 +52,9 @@ INT_HEX 0x[0-9a-fA-F]+
|
||||||
";" return(tSEMI);
|
";" return(tSEMI);
|
||||||
"," return(tCOMMA);
|
"," return(tCOMMA);
|
||||||
|
|
||||||
{ID} return(tID);
|
{ID} {strncpy(yylval.str, yytext, NAME_MAX_LENGTH); return(tID);}
|
||||||
{INT_DEC} return(tNB);
|
{INT_DEC} {yylval.nbInt = atoi(yytext); return(tNB);}
|
||||||
{INT_HEX} return(tNB);
|
{INT_HEX} {yylval.nbInt = atoi(yytext); return(tNB);}
|
||||||
|
|
||||||
|
|
||||||
/*comments are ignored, same for spaces and lines*/
|
/*comments are ignored, same for spaces and lines*/
|
||||||
|
|
7
yacc.y
7
yacc.y
|
@ -1,5 +1,3 @@
|
||||||
%define parse.error detailed
|
|
||||||
|
|
||||||
%{
|
%{
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -11,8 +9,7 @@
|
||||||
void yyerror (const char *);
|
void yyerror (const char *);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO : PROBLEM DOES'NT COMPILE (enumVarType doesn't exist)
|
%union {char str[NAME_MAX_LENGTH]; int nbInt; enumVarType type; }
|
||||||
%union {int nbInt; /*enumVarType*/ int type; char* string;}
|
|
||||||
/*loops keywords*/
|
/*loops keywords*/
|
||||||
%token tWHILE tIF tELSE
|
%token tWHILE tIF tELSE
|
||||||
/*reserved keywords*/
|
/*reserved keywords*/
|
||||||
|
@ -31,7 +28,7 @@
|
||||||
%token tLBRACE tRBRACE tLPAR tRPAR tSEMI tCOMMA
|
%token tLBRACE tRBRACE tLPAR tRPAR tSEMI tCOMMA
|
||||||
|
|
||||||
/*nametags and values*/
|
/*nametags and values*/
|
||||||
%token <string> tID
|
%token <str> tID
|
||||||
%token <nbInt> tNB
|
%token <nbInt> tNB
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue