added starter files
This commit is contained in:
parent
dd6392138b
commit
326d148d9f
|
@ -0,0 +1,4 @@
|
|||
build/
|
||||
*.c
|
||||
*.cc
|
||||
*.cpp
|
|
@ -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)/*
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"packages": [
|
||||
"bison",
|
||||
"flex",
|
||||
"clang"
|
||||
],
|
||||
"env": {
|
||||
"cc": "clang"
|
||||
},
|
||||
"shell": {
|
||||
"init_hook": null
|
||||
},
|
||||
"nixpkgs": {
|
||||
"commit": "f80ac848e3d6f0c12c52758c0f25c10c97ca3b62"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
%option noyywrap
|
||||
%{
|
||||
#include<stdio.h>
|
||||
#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
|
||||
}
|
Loading…
Reference in New Issue