From 2a20043edb282dff05c9832b1576bf8894dd6473 Mon Sep 17 00:00:00 2001 From: Alessandro Iezzi Date: Mon, 22 Jul 2024 17:19:33 +0200 Subject: Add a first draft of the parser --- .gitignore | 2 ++ Makefile | 11 +++++++++-- properties.l | 6 +----- properties.y | 22 ++++++++++++++++++++++ 4 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 properties.y diff --git a/.gitignore b/.gitignore index 6be102b..61cf493 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ properties *.core a.out *-lexer.c +y.* +*-parser.* \ No newline at end of file diff --git a/Makefile b/Makefile index 85e0bb8..de0f79f 100644 --- a/Makefile +++ b/Makefile @@ -3,10 +3,10 @@ LEX = lex YACC = yacc CC = cc -OBJ = properties-lexer.o +OBJ = properties-parser.o properties-lexer.o CFLAGS = -DVERSION=${VER} -LFLAGS = -ll +LFLAGS = -ll -ly all: properties @@ -17,6 +17,12 @@ properties-lexer.o: properties.l @mv lex.yy.c properties-lexer.c ${CC} ${CFLAGS} -c properties-lexer.c +properties-parser.o properties-parser.h: properties.y + ${YACC} -d properties.y + @mv y.tab.c properties-parser.c + @mv y.tab.h properties-parser.h + ${CC} ${CFLAGS} -c properties-parser.c + properties: ${OBJ} ${CC} ${OBJ} -o $@ ${LFLAGS} @@ -24,3 +30,4 @@ clean: @rm -f ${OBJ} *.core a.out @rm -f properties-lexer.c lex.* @rm -f properties + @rm -f properties-parser.* y.* diff --git a/properties.l b/properties.l index 653c358..73803fc 100644 --- a/properties.l +++ b/properties.l @@ -1,9 +1,5 @@ %{ -enum { - KEY = 1, - DIV, - VALUE -}; +#include "properties-parser.h" %} %% diff --git a/properties.y b/properties.y new file mode 100644 index 0000000..69d683d --- /dev/null +++ b/properties.y @@ -0,0 +1,22 @@ +%{ + +#include +#include + +%} + +%token KEY DIV VALUE + +%% + +value: VALUE + | VALUE value + ; + +%% + +void +yyerror(char *s) +{ + fprintf(stderr, "%s\n", s); +} -- cgit v1.2.3