MEGATRON



LOG | FILES | OVERVIEW


F diff --git a/lexer.c b/lexer.c new file mode 100644 --- /dev/null +++ b/lexer.c
+ #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
F diff --git a/lexer.h b/lexer.h new file mode 100644 --- /dev/null +++ b/lexer.h
+ #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
F diff --git a/main.c b/main.c new file mode 100644 --- /dev/null +++ b/main.c
+ #include<stdio.h>
+ #include<lexer.h>
+
+
+
+ int main()
+ {
+ return 0;
+ }
F diff --git a/makefile b/makefile new file mode 100644 --- /dev/null +++ b/makefile
+ 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
F diff --git a/program.c b/program.c new file mode 100644 --- /dev/null +++ b/program.c
+ #ifndef PROGRAM_C
+ #define PROGRAM_C
+
+
+ #endif
F diff --git a/program.h b/program.h new file mode 100644 --- /dev/null +++ b/program.h
+ #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
F diff --git a/queue.c b/queue.c new file mode 100644 --- /dev/null +++ b/queue.c
+ #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
F diff --git a/queue.h b/queue.h new file mode 100644 --- /dev/null +++ b/queue.h
+ #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