Lots of changes and too much dragging my feet on this. But I think this is going in the right direction now.
This commit is contained in:
+4
-2
@@ -2,15 +2,17 @@
|
||||
#define ARRAY_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
typedef struct _array {
|
||||
int Capacity;
|
||||
int Size;
|
||||
size_t Capacity;
|
||||
size_t Size;
|
||||
void** Items;
|
||||
} Array;
|
||||
|
||||
Array* ArrayCreate(void);
|
||||
bool ArrayAdd(Array* array, void* item);
|
||||
void* ArrayPeek(Array* array);
|
||||
void* ArrayIndex(Array* array, size_t index);
|
||||
|
||||
#endif
|
||||
@@ -1,4 +0,0 @@
|
||||
#ifndef AST_H
|
||||
#define AST_H
|
||||
|
||||
#endif
|
||||
+4
-4
@@ -2,10 +2,10 @@
|
||||
#define KEYWORDS_H
|
||||
|
||||
typedef enum {
|
||||
FN, ORG, NAMESPACE, DB, CONST
|
||||
} Keyword;
|
||||
FUNCTION, NAMESPACE, ASCIIZ, ASCII, WORD, SHORT, BYTE
|
||||
} Keywords;
|
||||
|
||||
int IsKeyword(const char* text, Keyword* keyword);
|
||||
void GetKeywordText(Keyword keyword, char buffer[16]);
|
||||
int IsKeyword(const char* text, Keywords* keyword);
|
||||
void GetKeywordText(Keywords keyword, char buffer[16]);
|
||||
|
||||
#endif
|
||||
+6
-5
@@ -6,17 +6,18 @@
|
||||
#include <stdio.h>
|
||||
|
||||
typedef enum {
|
||||
R1 = 0, R2, R3, R4, R5, R6, R7, R8 = 7
|
||||
R1 = 1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, R13, R14, R15, R16, R17, R18, R19,
|
||||
R20, R21, R22, R23, R24, R25, R26, R27, R28, R29, R30, R31, R32, RBP, RSP, RIP
|
||||
} Registers;
|
||||
|
||||
typedef enum {
|
||||
ADD = 0x01, SUB, MUL, DIV, MOV, AND, OR, XOR, NOT, SHL, SHR, NOP, CMP, JMP, JZ, JG, JL,
|
||||
OUTB, INB, HLT, CLI, ENI, INT, LIVT, PUSHA, POPA, CALL, RET, PUSH, POP
|
||||
} Mnemonic;
|
||||
} Mnemonics;
|
||||
|
||||
int IsOpcode(const char*, Mnemonic*);
|
||||
int IsOpcode(const char*, Mnemonics*);
|
||||
int IsRegister(const char*, Registers*);
|
||||
void GetMnemonicText(Mnemonic mnemonic, char buffer[12]);
|
||||
void GetRegisterText(Registers reg, char buffer[4]);
|
||||
void GetMnemonicText(Mnemonics mnemonic, char buffer[12]);
|
||||
void GetRegisterText(Registers reg, char buffer[5]);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef PARSER_H
|
||||
#define PARSER_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "dictionary.h"
|
||||
#include "opcodes.h"
|
||||
#include "token.h"
|
||||
#include "array.h"
|
||||
#include "keywords.h"
|
||||
|
||||
typedef struct _instruction Instruction;
|
||||
typedef Array Instructions;
|
||||
|
||||
Instructions* ParseTokens(Array* tokens);
|
||||
|
||||
#endif
|
||||
@@ -5,12 +5,17 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include "opcodes.h"
|
||||
#include "keywords.h"
|
||||
|
||||
typedef enum {
|
||||
Empty,
|
||||
String,
|
||||
Number,
|
||||
Symbol,
|
||||
Register,
|
||||
Mnemonic,
|
||||
Keyword,
|
||||
LineEnd = '\n',
|
||||
Colon = ':',
|
||||
Comma = ',',
|
||||
@@ -32,6 +37,9 @@ typedef struct _token {
|
||||
char Operator[8];
|
||||
char* String;
|
||||
int Number;
|
||||
Mnemonics Mnemonic;
|
||||
Registers Register;
|
||||
Keywords Keyword;
|
||||
} Value;
|
||||
int LineNumber;
|
||||
int ColumnNumber;
|
||||
|
||||
Reference in New Issue
Block a user