This commit is contained in:
timerix 2022-08-01 01:27:09 +06:00
parent cd81de9216
commit 3018020201
5 changed files with 86 additions and 0 deletions

25
src/cb2c/cb2c.c Normal file
View File

@ -0,0 +1,25 @@
#include "cb2c.h"
#include "../../../kerep/src/String/StringBuilder.h"
void namespaceToC(NamespaceContext* context, StringBuilder* b){
}
void functionToC(FunctionContext* context, StringBuilder* b){
}
void classToC(ClassContext* context, StringBuilder* b){
}
char* contextToC(void* context){
StringBuilder* b=StringBuilder_create();
switch(((Context*)context)->type){
case CT_Namespace: namespaceToC(context, b); break;
case CT_Function: functionToC(context, b); break;
case CT_Class: classToC(context, b); break;
default: throw(ERR_WRONGTYPE);
}
return StringBuilder_build(b).ptr;
}

5
src/cb2c/cb2c.h Normal file
View File

@ -0,0 +1,5 @@
#pragma once
#include "../lexer/lexer.h"
char* contextToC(void* context);

8
src/cb2c/main.c Normal file
View File

@ -0,0 +1,8 @@
#include "cb2c.h"
int main(){
init_keywordsSearchTree();
STNode_free(keywordsSearchTree);
return 0;
}

46
src/lexer/context.h Normal file
View File

@ -0,0 +1,46 @@
#pragma once
#include "../../../kerep/src/base/base.h"
#include "tokens.h"
typedef struct ContextStruct Context;
typedef enum ContextType{
CT_Namespace,
CT_Function,
CT_Class
} __attribute__((__packed__)) ContextType;
struct ContextStruct {
char* name;
Context* parent;
Autoarr(Token)* tokens;
ContextType type;
};
typedef struct NamespaceContext{
union {
Context base;
Context;
};
} NamespaceContext;
typedef struct FunctionContext {
union {
Context base;
Context;
};
Autoarr(Token)* arguments;
Autoarr(Token)* attributes;
Token accessModifier;
Token returnType;
} FunctionContext;
typedef struct ClassContext {
union {
Context base;
Context;
};
Autoarr(Token)* attributes;
Token accessModifier;
} ClassContext;

View File

@ -1,6 +1,8 @@
#pragma once #pragma once
#include "tokens.h" #include "tokens.h"
#include "context.h"
#include "my_type_ext.h"
//Autoarr(Token)* //Autoarr(Token)*
Maybe lexan(char* source, char* filename); Maybe lexan(char* source, char* filename);