summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Isom <kyle@tyrfingr.is>2014-07-06 02:42:00 -0700
committerKyle Isom <kyle@tyrfingr.is>2014-07-06 02:42:00 -0700
commit153c300edc80cac92c55a2e17e571f980c36e14b (patch)
treefbcbb50aae000634652a456b858359b6f2375522
parentf024e7ff0f966811a88439e4965b73e555d56687 (diff)
downloadkram-153c300edc80cac92c55a2e17e571f980c36e14b.tar.gz
kram-153c300edc80cac92c55a2e17e571f980c36e14b.tar.bz2
kram-153c300edc80cac92c55a2e17e571f980c36e14b.zip
Start lexer, update Makefile to build
-rw-r--r--Makefile10
-rw-r--r--scanner.l27
2 files changed, 36 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 059a89d..225db07 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,7 @@
TARGETS = kramvm
VM := vm.c vm.h
CC = clang
+GARBAGE := scanner.c
CFLAGS += -Wall -Wextra -pedantic -Wshadow -Wpointer-arith -Wcast-align
CFLAGS += -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations
CFLAGS += -Wnested-externs -Winline -Wno-long-long -Wunused-variable
@@ -22,4 +23,11 @@ test: vmtest
.PHONY: clean
clean:
- rm -f *.o $(TARGETS) core
+ rm -f *.o $(TARGETS) core $(GARBAGE)
+
+
+scanner.c: scanner.l
+ flex -o $@ scanner.l
+
+parser.c: parser.y
+ bison -o $@ parser.y
diff --git a/scanner.l b/scanner.l
new file mode 100644
index 0000000..a48912e
--- /dev/null
+++ b/scanner.l
@@ -0,0 +1,27 @@
+%{
+enum yytokentype {
+ SYM = 258,
+ REG = 259,
+ IMM = 260,
+ LBL = 271,
+ EOL = 262
+};
+%}
+
+%%
+
+^[a-zA-Z][a-zA-Z0-9]*: { return LBL; }
+[$][a-zA-Z]+ { return REG; }
+[#][0-9a-f]+ { return IMM; }
+[a-zA-Z]+ { return SYM; }
+\n { return EOL; }
+
+%%
+
+main(int argc, char **argv)
+{
+ int tok;
+ while(tok = yylex()) {
+ printf("%d", tok);
+ }
+}