From 05bf718e37efdc5201ad281e85da7850af31bd59 Mon Sep 17 00:00:00 2001 From: hachem Date: Sat, 19 Sep 2026 10:49:33 +0200 Subject: feat: basic lexer with flex --- Makefile | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 8d873b9..e1140cf 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ CC = cc -YACC = bison -CFLAGS = -std=c99 -Wall -Wextra -Werror -Wpedantic -O2 -Ibin -SOURCES = ast.c ast.h eval.c eval.h lexer.c lexer.h main.c -OBJECTS = bin/parser.o bin/lexer.o bin/ast.o bin/eval.o bin/main.o +LEX = flex +CFLAGS = -std=c17 -Wall -Wextra -Werror -Wpedantic -O2 +SOURCES = lexer.h main.c +OBJECTS = bin/lexer.o bin/main.o SANITIZE = -g -O0 -fsanitize=address,undefined .PHONY: all debug check format lint clean @@ -15,42 +15,31 @@ bin: sfinae: $(OBJECTS) $(CC) $(CFLAGS) -o $@ $(OBJECTS) -bin/parser.c bin/parser.h: sfinae.y | bin - $(YACC) -d -o bin/parser.c sfinae.y +bin/lexer.c: sfinae.l | bin + $(LEX) -o bin/lexer.c sfinae.l -bin/parser.o: bin/parser.c - $(CC) -std=c99 -w -I. -c -o $@ bin/parser.c +bin/lexer.o: bin/lexer.c lexer.h + $(CC) -std=c17 -w -I. -c -o $@ bin/lexer.c bin/%.o: %.c | bin $(CC) $(CFLAGS) -c -o $@ $< -bin/lexer.o: bin/parser.h ast.h lexer.h -bin/main.o: ast.h eval.h lexer.h -bin/ast.o: ast.h lexer.h -bin/eval.o: eval.h ast.h +bin/main.o: lexer.h debug: CFLAGS += $(SANITIZE) debug: clean sfinae check: sfinae @for example in examples/*.sfinae; do \ - expected="$${example%.sfinae}.expected"; \ - if ./sfinae "$$example" | diff -u "$$expected" - >/dev/null; then \ - echo "ok $$example"; \ - else \ - echo "FAIL $$example"; ./sfinae "$$example" | diff -u "$$expected" -; exit 1; \ - fi; \ + echo "== $$example"; \ + ./sfinae "$$example" || exit 1; \ done format: clang-format -i $(SOURCES) -LINT_FILTER = '[{"name":"parser.h","lines":[[1,1]]}, \ - {"name":"ast.c"},{"name":"eval.c"},{"name":"lexer.c"},{"name":"main.c"}, \ - {"name":"ast.h"},{"name":"eval.h"},{"name":"lexer.h"}]' - -lint: bin/parser.h - clang-tidy --line-filter=$(LINT_FILTER) ast.c eval.c lexer.c main.c -- -std=c99 -Ibin +lint: + clang-tidy main.c -- -std=c17 clean: rm -rf bin sfinae -- cgit v1.3