From a3e36c1918e63761dfc4d2221cca3636b98e93aa Mon Sep 17 00:00:00 2001 From: Adam Branes Date: Sun, 2 May 2021 17:45:58 +0300 Subject: initial housekeeping done --- lexer.c | 25 ++++++++++++++++++++++++ lexer.h | 26 +++++++++++++++++++++++++ main.c | 9 +++++++++ makefile | 9 +++++++++ program.c | 5 +++++ program.h | 35 +++++++++++++++++++++++++++++++++ queue.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ queue.h | 23 ++++++++++++++++++++++ 8 files changed, 199 insertions(+) create mode 100644 lexer.c create mode 100644 lexer.h create mode 100644 main.c create mode 100644 makefile create mode 100644 program.c create mode 100644 program.h create mode 100644 queue.c create mode 100644 queue.h diff --git a/lexer.c b/lexer.c new file mode 100644 index 0000000..4ade447 --- /dev/null +++ b/lexer.c @@ -0,0 +1,25 @@ +#ifndef LEXER_C +#define LEXER_C +#include + +/* + * 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 diff --git a/lexer.h b/lexer.h new file mode 100644 index 0000000..27b69d5 --- /dev/null +++ b/lexer.h @@ -0,0 +1,26 @@ +#ifndef LEXER_H +#define LEXER_H +#include +#include + +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 diff --git a/main.c b/main.c new file mode 100644 index 0000000..79018d6 --- /dev/null +++ b/main.c @@ -0,0 +1,9 @@ +#include +#include + + + +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 diff --git a/queue.c b/queue.c new file mode 100644 index 0000000..187519a --- /dev/null +++ b/queue.c @@ -0,0 +1,67 @@ +#ifndef GQUEUE_C +#define GQUEUE_C GQUEUE_C +#include + + +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 diff --git a/queue.h b/queue.h new file mode 100644 index 0000000..651d4b0 --- /dev/null +++ b/queue.h @@ -0,0 +1,23 @@ +#ifndef GQUEUE_H +#define GQUEUE_H GQUEUE_H +#include + + +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 -- cgit v1.2.3