5
This commit is contained in:
parent
3665fa8d9d
commit
a2962a360e
13
.gitignore
vendored
Normal file
13
.gitignore
vendored
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# Build results
|
||||||
|
bin/
|
||||||
|
obj/
|
||||||
|
|
||||||
|
# user files
|
||||||
|
.old*/
|
||||||
|
.vs/
|
||||||
|
.vscode/
|
||||||
|
.vshistory/
|
||||||
|
.editorconfig
|
||||||
|
*.user
|
||||||
|
*.vcxproj.filters
|
||||||
|
.config
|
||||||
16
commands.h
16
commands.h
@ -1,16 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include "../kerep/Autoarr/Autoarr.h"
|
|
||||||
|
|
||||||
typedef enum CommandId{
|
|
||||||
|
|
||||||
} __attribute__((__packed__)) CommandId;
|
|
||||||
|
|
||||||
struct CommandStruct;
|
|
||||||
typedef CommandStruct Command;
|
|
||||||
struct CommandStruct{
|
|
||||||
Command* next;
|
|
||||||
Command* prev;
|
|
||||||
CommandId id;
|
|
||||||
}
|
|
||||||
|
|
||||||
Autoarr_declare(Comand);
|
|
||||||
12
src/copler/Assembly.h
Normal file
12
src/copler/Assembly.h
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "../../../kerep/src/base/base.h"
|
||||||
|
|
||||||
|
typedef struct AssemblyStruct {
|
||||||
|
|
||||||
|
} Assembly;
|
||||||
|
|
||||||
|
typedef struct AssemblyParamsStruct
|
||||||
|
{
|
||||||
|
/* data */
|
||||||
|
} AssemblyParams;
|
||||||
@ -1,10 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "../../../kerep/src/Autoarr/Autoarr.h"
|
||||||
#include "commands.h"
|
#include "commands.h"
|
||||||
|
|
||||||
struct ContextStruct;
|
typedef struct ContextStruct Context;
|
||||||
typedef ContextStruct Context;
|
|
||||||
|
|
||||||
Autoarr_declare(Context);
|
Autoarr_declare(Context)
|
||||||
|
|
||||||
struct ContextStruct{
|
struct ContextStruct{
|
||||||
Context* parent;
|
Context* parent;
|
||||||
@ -12,4 +12,4 @@ struct ContextStruct{
|
|||||||
Autoarr(Command) commandChain;
|
Autoarr(Command) commandChain;
|
||||||
Autoarr(Constant) constantStack;
|
Autoarr(Constant) constantStack;
|
||||||
bool isPartial; // if true, not-defined members won't throw NotDefinedError before linkage
|
bool isPartial; // if true, not-defined members won't throw NotDefinedError before linkage
|
||||||
}
|
};
|
||||||
22
src/copler/commands.h
Normal file
22
src/copler/commands.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "../../../kerep/src/String/string.h"
|
||||||
|
#include "../../../kerep/src/Autoarr/Autoarr.h"
|
||||||
|
|
||||||
|
typedef enum CommandId{
|
||||||
|
CommandVoid
|
||||||
|
} __attribute__((__packed__)) CommandId;
|
||||||
|
|
||||||
|
typedef struct CommandStruct Command;
|
||||||
|
struct CommandStruct{
|
||||||
|
Command* next;
|
||||||
|
Command* prev;
|
||||||
|
CommandId id;
|
||||||
|
};
|
||||||
|
|
||||||
|
Autoarr_declare(Command)
|
||||||
|
|
||||||
|
typedef struct ConstantStruct {
|
||||||
|
|
||||||
|
} Constant;
|
||||||
|
|
||||||
|
Autoarr_declare(Constant)
|
||||||
@ -1,10 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "tokens.h"
|
|
||||||
#include "context.h"
|
|
||||||
|
|
||||||
Autoarr_declare(Token);
|
#include "../../../kerep/src/String/StringBuilder.h"
|
||||||
|
#include "../lexer/lexer.h"
|
||||||
Autoarr(Token)* lexan(char* source, char* filename);
|
#include "Assembly.h"
|
||||||
|
#include "Context.h"
|
||||||
|
|
||||||
Context* parse(Autoarr(Token)* tokens);
|
Context* parse(Autoarr(Token)* tokens);
|
||||||
|
|
||||||
6
src/copler/main.c
Normal file
6
src/copler/main.c
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#include "copler.h"
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@ -1,9 +1,36 @@
|
|||||||
#include "cobek_compiler.h"
|
#include "lexer.h"
|
||||||
|
|
||||||
Autoarr_define(Token);
|
Autoarr_define(Token);
|
||||||
|
|
||||||
|
typedef struct SourceFileInfo{
|
||||||
|
char* _source;
|
||||||
|
char* _filename;
|
||||||
|
Autoarr(Token)* _tokens;
|
||||||
|
string _context;
|
||||||
|
string _line;
|
||||||
|
string _label;
|
||||||
|
uint32 _linenum;
|
||||||
|
uint32 _charnum;
|
||||||
|
} SourceFileInfo;
|
||||||
|
|
||||||
char charFromEscapeStr(string estr){
|
#define source sfi->_source
|
||||||
|
#define filename sfi->_filename
|
||||||
|
#define tokens sfi->_tokens
|
||||||
|
#define context sfi->_context
|
||||||
|
#define line sfi->_line
|
||||||
|
#define label sfi->_label
|
||||||
|
#define linenum sfi->_linenum
|
||||||
|
#define charnum sfi->_charnum
|
||||||
|
|
||||||
|
Maybe _throw_wrongchar(SourceFileInfo* sfi){
|
||||||
|
char* errline=string_extract(line);
|
||||||
|
printf("\n\e[91mwrong char <%c> at [%s:%u:%u %s]\n >>> %s\n",
|
||||||
|
source[charnum], filename,linenum,charnum,context, errline);
|
||||||
|
exit(96);
|
||||||
|
}
|
||||||
|
#define throw_wrongchar(freeMem) { freeMem; _throw_wrongchar(sfi); }
|
||||||
|
|
||||||
|
char _charFromEscapeStr(string estr, SourceFileInfo* sfi){
|
||||||
if(*estr.ptr!='\\') throw("first char is not \\");
|
if(*estr.ptr!='\\') throw("first char is not \\");
|
||||||
switch(*(++estr.ptr)){
|
switch(*(++estr.ptr)){
|
||||||
case 'n': return '\n';
|
case 'n': return '\n';
|
||||||
@ -13,27 +40,25 @@ char charFromEscapeStr(string estr){
|
|||||||
case '\\': return '\\';
|
case '\\': return '\\';
|
||||||
case '"': return '"';
|
case '"': return '"';
|
||||||
case '\'': return '\'';
|
case '\'': return '\'';
|
||||||
default: throw(ERR_WRONGCHAR);
|
default: throw_wrongchar(;);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#define charFromEscapeStr(estr) _charFromEscapeStr(estr, sfi)
|
||||||
|
|
||||||
|
Autoarr(Token)* lexan(char* _source, char* _filename){
|
||||||
Autoarr(Token)* lexan(char* source, char* filename){
|
SourceFileInfo sfi={
|
||||||
Autoarr(Token)* tokens=malloc(sizeof(Autoarr(Token)));
|
._source=_source,
|
||||||
*tokens=Autoarr_create(Token,64,1024);
|
._filename=_filename,
|
||||||
char c;
|
._tokens=Autoarr_create(Token,64,1024),
|
||||||
string label={source,0};
|
._label={_source,0},
|
||||||
string line={source,0};
|
._line={_source,0},
|
||||||
uint32 linenum;
|
._linenum=0,
|
||||||
uint32 cnum;
|
._charnum=0
|
||||||
|
|
||||||
|
|
||||||
void throw_wrongchar(){
|
|
||||||
char* errline=string_cpToCharPtr(line);
|
|
||||||
printf("\n\e[91mwrong char <%c> at [%s:%u:%u %s]\n >>> %s\n" ,filename,linenum,cnum,c,errline);
|
|
||||||
exit(96);
|
|
||||||
};
|
};
|
||||||
|
return _lexan(&sfi);
|
||||||
|
}
|
||||||
|
|
||||||
|
Autoarr(Token)* _lexan(SourceFileInfo* sfi){
|
||||||
|
|
||||||
void addlabel(){
|
void addlabel(){
|
||||||
if(label.length==0) return;
|
if(label.length==0) return;
|
||||||
9
src/lexer/lexer.h
Normal file
9
src/lexer/lexer.h
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "../../../kerep/src/Autoarr/Autoarr.h"
|
||||||
|
#include "../../../kerep/src/String/string.h"
|
||||||
|
#include "tokens.h"
|
||||||
|
|
||||||
|
Autoarr_declare(Token)
|
||||||
|
|
||||||
|
Autoarr(Token)* lexan(char* source, char* filename);
|
||||||
@ -1,23 +1,24 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "../kerep/base/std.h"
|
|
||||||
|
#include "../../../kerep/src/base/base.h"
|
||||||
|
|
||||||
typedef enum TokenId{
|
typedef enum TokenId{
|
||||||
// base types
|
// base types
|
||||||
tok_void,
|
tok_void_t,
|
||||||
tok_int8,
|
tok_int8_t,
|
||||||
tok_uint8,
|
tok_uint8_t,
|
||||||
tok_int16,
|
tok_int16_t,
|
||||||
tok_uint16,
|
tok_uint16_t,
|
||||||
tok_int32,
|
tok_int32_t,
|
||||||
tok_uint32,
|
tok_uint32_t,
|
||||||
tok_int64,
|
tok_int64_t,
|
||||||
tok_uint64,
|
tok_uint64_t,
|
||||||
tok_char, //ascii
|
tok_char_t, //ascii
|
||||||
tok_char8, //utf8
|
tok_char8_t, //utf8
|
||||||
tok_char16, //utf16
|
tok_char16_t, //utf16
|
||||||
tok_bool,
|
tok_bool_t,
|
||||||
tok_float32,
|
tok_float32_t,
|
||||||
tok_float64,
|
tok_float64_t,
|
||||||
// constant
|
// constant
|
||||||
tok_null,
|
tok_null,
|
||||||
tok_true,
|
tok_true,
|
||||||
@ -58,7 +59,7 @@ typedef enum TokenId{
|
|||||||
// user-defined
|
// user-defined
|
||||||
tok_label,
|
tok_label,
|
||||||
tok_number,
|
tok_number,
|
||||||
tok_char,
|
tok_character,
|
||||||
tok_string,
|
tok_string,
|
||||||
tok_comment,
|
tok_comment,
|
||||||
// special characters
|
// special characters
|
||||||
@ -103,3 +104,4 @@ typedef struct Token{
|
|||||||
char* value;
|
char* value;
|
||||||
TokenId id;
|
TokenId id;
|
||||||
} Token;
|
} Token;
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user