aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Branes <adam@adam>2021-05-02 17:45:58 +0300
committerAdam Branes <adam@adam>2021-05-02 17:45:58 +0300
commita3e36c1918e63761dfc4d2221cca3636b98e93aa (patch)
tree143722876a02156b0b423de6248298b5cf8c0707
downloadMEGATRON-a3e36c1918e63761dfc4d2221cca3636b98e93aa.tar.gz
initial housekeeping done
-rw-r--r--lexer.c25
-rw-r--r--lexer.h26
-rw-r--r--main.c9
-rw-r--r--makefile9
-rw-r--r--program.c5
-rw-r--r--program.h35
-rw-r--r--queue.c67
-rw-r--r--queue.h23
8 files changed, 199 insertions, 0 deletions
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 <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
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 <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
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<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
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<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
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<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