From a133079e7d76420e0e5f0f386ee714e29776a6fc Mon Sep 17 00:00:00 2001 From: Julian T Date: Wed, 16 Oct 2019 16:34:26 +0200 Subject: Some operating system work --- sem1/osc/mm10/Makefile | 19 ++++++++++++++++ sem1/osc/mm10/opg1.l | 22 ++++++++++++++++++ sem1/osc/mm10/opg3.l | 36 ++++++++++++++++++++++++++++++ sem1/osc/mm10/opgaver.md | 49 +++++++++++++++++++++++++++++++++++++++++ sem1/osc/mm10/stateMachine.png | Bin 0 -> 21881 bytes 5 files changed, 126 insertions(+) create mode 100644 sem1/osc/mm10/Makefile create mode 100644 sem1/osc/mm10/opg1.l create mode 100644 sem1/osc/mm10/opg3.l create mode 100644 sem1/osc/mm10/opgaver.md create mode 100644 sem1/osc/mm10/stateMachine.png diff --git a/sem1/osc/mm10/Makefile b/sem1/osc/mm10/Makefile new file mode 100644 index 0000000..3d4089e --- /dev/null +++ b/sem1/osc/mm10/Makefile @@ -0,0 +1,19 @@ +opgaver=opg1 opg3 + +LEX=flex +CC=gcc +LINKFLAG=-lfl +DEFAULT_TARGET=all + +%: %.yy.c + $(CC) -o $@ $^ $(LINKFLAG) + +%.yy.c: %.l + $(LEX) -o $@ $^ + +all: $(opgaver) + +phony: all clean + +clean: + rm $(opgaver) diff --git a/sem1/osc/mm10/opg1.l b/sem1/osc/mm10/opg1.l new file mode 100644 index 0000000..b5cb478 --- /dev/null +++ b/sem1/osc/mm10/opg1.l @@ -0,0 +1,22 @@ +%{ + +#include + +%} + +ting (a|b)abcd + +%% + +{ting} { printf("Fandt ting %s\n", yytext); return 1; } +. { printf("Meh"); } + +%% + +int main(void) { + + printf("yylex: %d\n", yylex()); + + return 0; + +} diff --git a/sem1/osc/mm10/opg3.l b/sem1/osc/mm10/opg3.l new file mode 100644 index 0000000..1c4b9c7 --- /dev/null +++ b/sem1/osc/mm10/opg3.l @@ -0,0 +1,36 @@ +%{ + +#include + +#define BEGIN_T 1 +#define END_T 2 +#define NUM_T 3 +#define VAR_T 4 + +%} + +VAR [a-zA-Z][a-zA-Z\_\-0-9]* +TAL [0-9]+ + +%% + +begin {printf("Found a BEGIN\n"); return BEGIN_T;} +end {printf("Found a END\n"); return END_T;} +{VAR} {printf("Found a variable %s\n", yytext); return VAR_T;} +{TAL} {printf("Found a number %d\n", strtol(yytext, NULL, 10)); return NUM_T;} + +%% + +int main(void) { + + for(;;) { + int t = yylex(); + printf("yylex: %d\n", t); + if( t == END_T ) { + break; + } + } + + return 0; + +} diff --git a/sem1/osc/mm10/opgaver.md b/sem1/osc/mm10/opgaver.md new file mode 100644 index 0000000..781ee13 --- /dev/null +++ b/sem1/osc/mm10/opgaver.md @@ -0,0 +1,49 @@ +# MM10 + +## Opgave 1 + +A) + + + +B) + +Kan ses i den tilhørende lex fil. +For at compile kør: + +``` +make opg1 +``` + +C) + +``` +aabcd + +Fandt ting aabcd +yylex: 1 +``` + +``` +afggfd + +MehMehMehMehMehMeh +``` + +## Opgave 2 + +Regulære udtryk for: + +``` +c kommentarer: \/\/.*\n +real konstant: [-+]?[0-9]*(\.[0-9]+)?(e\+[0-9]+)? +starter med store: [A-Z][a-zA-z]+ +``` + +## Opgave 3 + +Dette laver jeg i opg3.l filen. + + + + diff --git a/sem1/osc/mm10/stateMachine.png b/sem1/osc/mm10/stateMachine.png new file mode 100644 index 0000000..08c5bf2 Binary files /dev/null and b/sem1/osc/mm10/stateMachine.png differ -- cgit v1.2.3