diff options
Diffstat (limited to 'sem1/osc/mm10')
-rw-r--r-- | sem1/osc/mm10/Makefile | 25 | ||||
-rw-r--r-- | sem1/osc/mm10/opg1.l | 22 | ||||
-rw-r--r-- | sem1/osc/mm10/opg3.l | 36 | ||||
-rw-r--r-- | sem1/osc/mm10/opg4.l | 101 | ||||
-rw-r--r-- | sem1/osc/mm10/opgaver.md | 55 | ||||
-rw-r--r-- | sem1/osc/mm10/stateMachine.png | bin | 21881 -> 0 bytes |
6 files changed, 0 insertions, 239 deletions
diff --git a/sem1/osc/mm10/Makefile b/sem1/osc/mm10/Makefile deleted file mode 100644 index 99bd635..0000000 --- a/sem1/osc/mm10/Makefile +++ /dev/null @@ -1,25 +0,0 @@ -opgaver=opg1 opg3 opg4 - -LEX=flex -CC=gcc -LINKFLAG=-lfl -DEFAULT_TARGET=all - -%: %.yy.c - $(CC) -o $@ $^ $(LINKFLAG) - -%.o: %.c - $(CC) -c -o $@ $^ - -%.yy.c: %.l - $(LEX) -o $@ $^ - -all: $(opgaver) - -phony: all clean run - -run: $(BIN) - ./$(BIN) - -clean: - rm -f $(opgaver) diff --git a/sem1/osc/mm10/opg1.l b/sem1/osc/mm10/opg1.l deleted file mode 100644 index b5cb478..0000000 --- a/sem1/osc/mm10/opg1.l +++ /dev/null @@ -1,22 +0,0 @@ -%{ - -#include <stdio.h> - -%} - -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 deleted file mode 100644 index 1c4b9c7..0000000 --- a/sem1/osc/mm10/opg3.l +++ /dev/null @@ -1,36 +0,0 @@ -%{ - -#include <stdio.h> - -#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/opg4.l b/sem1/osc/mm10/opg4.l deleted file mode 100644 index aeb73b1..0000000 --- a/sem1/osc/mm10/opg4.l +++ /dev/null @@ -1,101 +0,0 @@ -%{ - -#include <stdio.h> -#include <stdint.h> - -#define BEGIN_T 1 -#define END_T 2 -#define NUM_T 3 -#define VAR_T 4 -#define HASHSIZE 100 - -typedef struct symnode_struct { - struct symnode_struct *next; - char *name; -} symnode_t; - -symnode_t *sym_insert(char *var); -symnode_t *sym_lookup(char *var); - -%} - -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); - if( !sym_lookup(yytext) ) { - printf("Not found inserting\n"); - sym_insert(yytext); - } - return VAR_T;} -{TAL} {printf("Found a number %d\n", strtol(yytext, NULL, 10)); return NUM_T;} - -%% - -symnode_t *symlist[HASHSIZE]; - -unsigned int hash(char *s) { - uint32_t hv = 0; - for( int i = 0; s[i] != '\0'; i++ ) { - // take MSB 6 bits of hv and xors with LSB of s[i] - uint32_t v = ( hv >> 26 ) ^ (s[i] & 0x3f); - - // Push those back on hv - hv = (hv << 4) | v; - } - // Return appropriate size - return hv % HASHSIZE; -} - - -symnode_t *sym_insert(char *var) { - unsigned int index = hash(var); - - // Save old value - symnode_t *oldSym = symlist[index]; - - // Make new - symlist[index] = malloc(sizeof(symnode_t)); - if( symlist[index] == NULL ) { - // If malloc failed - symlist[index] = oldSym; - return NULL; - } - - // Link old one - symlist[index]->next = oldSym; - symlist[index]->name = var; - - return symlist[index]; -} - -symnode_t *sym_lookup(char *var) { - unsigned int index = hash(var); - symnode_t *n = symlist[index]; - - // Look trough list - while(n != NULL && strcmp(n->name, var) != 0) { - n = n->next; - } - - return n; -} - - -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 deleted file mode 100644 index b8c8186..0000000 --- a/sem1/osc/mm10/opgaver.md +++ /dev/null @@ -1,55 +0,0 @@ -# MM10 - -## Opgave 1 - -A) - -<img src="./stateMachine.png"></img> - -B) - -Kan ses i den tilhørende opg1.l fil. -For at compile kør: - -``` -make run BIN=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. - -## Opgave 4 - -Se opg4.l fil og kør med. - -``` -make run BIN=opg4 -``` - - diff --git a/sem1/osc/mm10/stateMachine.png b/sem1/osc/mm10/stateMachine.png Binary files differdeleted file mode 100644 index 08c5bf2..0000000 --- a/sem1/osc/mm10/stateMachine.png +++ /dev/null |