diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9912b62 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +build/ +*.c +*.cc +*.cpp diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1289f05 --- /dev/null +++ b/Makefile @@ -0,0 +1,21 @@ + +BUILDDIR = build +TARGET_SRC = main + +build: mkdir main +all: mkdir main run + +mkdir: # create build directory + mkdir -p $(BUILDDIR) + +run: # run binary + ./$(BUILDDIR)/main + +main: lex.yy.c # compile c file + cc $(BUILDDIR)/lex.yy.c -o $(BUILDDIR)/$(TARGET_SRC) -lfl + +lex.yy.c: main.lex # generate c file + flex -o $(BUILDDIR)/lex.yy.c $(TARGET_SRC).lex + +clean: # wipe the build directory + rm -f $(BUILDDIR)/* diff --git a/devbox.json b/devbox.json new file mode 100644 index 0000000..cd3a5a2 --- /dev/null +++ b/devbox.json @@ -0,0 +1,16 @@ +{ + "packages": [ + "bison", + "flex", + "clang" + ], + "env": { + "cc": "clang" + }, + "shell": { + "init_hook": null + }, + "nixpkgs": { + "commit": "f80ac848e3d6f0c12c52758c0f25c10c97ca3b62" + } +} diff --git a/main.lex b/main.lex new file mode 100644 index 0000000..6b3737b --- /dev/null +++ b/main.lex @@ -0,0 +1,29 @@ +%option noyywrap +%{ + #include + #define YYDEBUG 1 + int yyLineNumber = 1; +%} + +%% +[a-zA-Z]+ myprint("Identifier"); //matcht auch if und IF! +IF|if myprint("keyword"); +\n yyLineNumber++; +[ \t] //nix machen, "spaces und tabs überlesen" + +. myprint("unknown Symbol"); +%% + +int main() +{ + printf("Programm eingeben: \n"); + yylex(); + return 0; +} + +int myprint(char token[]) { + printf("\nZeile %d >>> ", yyLineNumber); + + printf("%s ", token); + printf("%s\n", yytext); // yytext: String, der gerade gelesen wurde +}