diff --git a/jlc/Makefile b/jlc/Makefile new file mode 100644 index 0000000..2452652 --- /dev/null +++ b/jlc/Makefile @@ -0,0 +1,17 @@ + +FLEX := flex +BISON := bison + +all: jlc + +jlc: lex.yy.c jl.tab.c + $(CC) -o $@ $^ + +jl.tab.c jl.tab.h: jl.y + $(BISON) -d $< + +lex.yy.c: jl.lex + $(FLEX) $< + +clean: + -rm -f lex.yy.c jl.tab.c jl.tab.h *~ *.o jlc diff --git a/jlc/jl.lex b/jlc/jl.lex new file mode 100644 index 0000000..cd4d964 --- /dev/null +++ b/jlc/jl.lex @@ -0,0 +1,13 @@ + +%{ +#include "jl.tab.h" +%} + +%% +0b[01]+ return BIN_NUMBER; +0x[0-9A-Fa-f] return HEX_NUMBER; +0[0-9]* return OCT_NUMBER; +[1-9][0-9]* return DEC_NUMBER; +\n /* ignore newlines */ +[ \t\v] /* ignore whitespace */ +%% diff --git a/jlc/jl.y b/jlc/jl.y new file mode 100644 index 0000000..54ee106 --- /dev/null +++ b/jlc/jl.y @@ -0,0 +1,33 @@ + +%{ +#include + +void yyerror(const char * str) +{ + fprintf(stderr, "error: %s\n", str); +} + +int yywrap() +{ + return 1; +} + +main() +{ + yyparse(); +} + +%} + +%token BIN_NUMBER OCT_NUMBER DEC_NUMBER HEX_NUMBER + +%% + +number: BIN_NUMBER + | OCT_NUMBER + | DEC_NUMBER + | HEX_NUMBER + { + printf("Saw a number\n"); + } + ;