diff options
author | Adam Branes <adam@adam> | 2021-05-02 17:45:58 +0300 |
---|---|---|
committer | Adam Branes <adam@adam> | 2021-05-02 17:45:58 +0300 |
commit | a3e36c1918e63761dfc4d2221cca3636b98e93aa (patch) | |
tree | 143722876a02156b0b423de6248298b5cf8c0707 | |
download | MEGATRON-a3e36c1918e63761dfc4d2221cca3636b98e93aa.tar.gz |
initial housekeeping done
-rw-r--r-- | lexer.c | 25 | ||||
-rw-r--r-- | lexer.h | 26 | ||||
-rw-r--r-- | main.c | 9 | ||||
-rw-r--r-- | makefile | 9 | ||||
-rw-r--r-- | program.c | 5 | ||||
-rw-r--r-- | program.h | 35 | ||||
-rw-r--r-- | queue.c | 67 | ||||
-rw-r--r-- | queue.h | 23 |
8 files changed, 199 insertions, 0 deletions
@@ -0,0 +1,25 @@ +#ifndef LEXER_C +#define LEXER_C +#include <lexer.h> + +/* + * placeholder very slow lexer that I will probabbly not replace + */ +void lex(struct Queue *token_destination,struct Source *src,struct Translation_Data *translation_data) +{ +} +struct token* get_token(char *data,size_t size) +{ + struct token *ret; + ret=malloc(sizeof(struct token)); + ret->data=data; + ret->size=size; + + return ret; +} +void delete_token(struct token *token) +{ + free(token); +} + +#endif @@ -0,0 +1,26 @@ +#ifndef LEXER_H +#define LEXER_H +#include <program.h> +#include <queue.h> + +enum Keyword +{ + KW_MACHINE, + KW_STATE, + KW_FROM, + KW_TO, + KW_ON, + KW_ID, +}; +struct token +{ + size_t size; + enum Keyword type; + char *data; +}; +void lex(struct Queue *token_destination,struct Source *src,struct Translation_Data *translation_data); +struct token* get_token(char *data,size_t size); +void delete_token(struct token *token); + + +#endif @@ -0,0 +1,9 @@ +#include<stdio.h> +#include<lexer.h> + + + +int main() +{ + return 0; +} diff --git a/makefile b/makefile new file mode 100644 index 0000000..23fd10a --- /dev/null +++ b/makefile @@ -0,0 +1,9 @@ +INCLUDE_DIRS=-I . +main.exe : main.c lexer.o queue.o + gcc main.c lexer.o queue.o -o main.exe ${INCLUDE_DIRS} +lexer.o : lexer.c lexer.h + gcc -c lexer.c -o lexer.o ${INCLUDE_DIRS} +queue.o : queue.c queue.h + gcc -c queue.c -o queue.o ${INCLUDE_DIRS} +clear: + rm -rf lexer.o main.exe queue.o diff --git a/program.c b/program.c new file mode 100644 index 0000000..6fe3a2f --- /dev/null +++ b/program.c @@ -0,0 +1,5 @@ +#ifndef PROGRAM_C +#define PROGRAM_C + + +#endif diff --git a/program.h b/program.h new file mode 100644 index 0000000..dfb5098 --- /dev/null +++ b/program.h @@ -0,0 +1,35 @@ +#ifndef PROGRAM_H +#define PROGRAM_H +#include "queue.h" + +struct Source +{ + char *src_name; + char *src; + size_t src_size; + +}; + +struct Options +{ + int print_tokens:1; +}; + +struct Translation_Data +{ + struct Queue *errors; + struct Queue *tokens; +}; + +struct Source* extract_source(char *src_name); +struct Translation_Data* get_translation_data(); +struct Source* get_source(); +struct Options* get_options(); + + +void destroy_translation_data(struct Translation_Data *data); +void destroy_source(struct Source *src); +void destroy_options(struct Options *options); + + +#endif @@ -0,0 +1,67 @@ +#ifndef GQUEUE_C +#define GQUEUE_C GQUEUE_C +#include<queue.h> + + +void Queue_Init(struct Queue *q) +{ + q->first=q->last=NULL; + q->size=0; +} +void Queue_Push(struct Queue *q,void *data) +{ + if(q==NULL)return; + if(q->first==NULL) + { + q->first=q->last=malloc(sizeof(struct Queue_Node)); + + q->first->data=data; + q->first->prev=NULL; + + ++q->size; + }else + { + struct Queue_Node *temp=malloc(sizeof(struct Queue_Node)); + q->last->prev=temp; + temp->data=data; + + q->last=temp; + ++q->size; + } + +} +void* Queue_Pop(struct Queue *q) +{ + if(q==NULL)return NULL; + if(q->size==0)return NULL; + + void *return_value=q->first->data; + + if(q->size==1) + { + free(q->last); + q->first=q->last=NULL; + q->size=0; + }else + { + struct Queue_Node *temp_first=q->first; + q->first=q->first->prev; + free(temp_first); + --q->size; + } + return return_value; +} +void Queue_Destroy(struct Queue *q) +{ + + struct Queue_Node *temp_first; + while(q->first!=NULL) + { + temp_first=q->first; + q->first=q->first->prev; + free(temp_first->data); + free(temp_first); + } + +} +#endif @@ -0,0 +1,23 @@ +#ifndef GQUEUE_H +#define GQUEUE_H GQUEUE_H +#include<stdlib.h> + + +struct Queue_Node +{ + void *data; + struct Queue_Node *prev; +}; + +struct Queue +{ + struct Queue_Node *first,*last; + size_t size; + +}; + +void Queue_Init(struct Queue *q); +void Queue_Push(struct Queue *q,void *data); +void* Queue_Pop(struct Queue *q); +void Queue_Destroy(struct Queue *q); +#endif |