From d18e9ce67572153e44b8bac9649b75f49e5ceeac Mon Sep 17 00:00:00 2001 From: Jackutea Date: Wed, 10 Jan 2024 16:54:20 +0800 Subject: [PATCH] WIP add: DFA Func --- Readme.md | 10 +++++++++- run.bat => run_samples.bat | 1 + samples/static_func/static_func.ling | 12 ++++++++++++ src/Business/B_Tokenize.c | 12 ++++++------ src/Business/D_DFA_Func.c | 14 +++++++++----- src/Business/D_DFA_Func.h | 2 +- src/Business/D_DFA_Import.c | 2 +- src/Business/D_DFA_Struct.c | 2 +- src/Business/D_NFA_Top.c | 7 ++++--- src/Business/Util_Cursor.c | 1 + src/Entities_Source/M_DFA_Func.c | 2 +- src/Entities_Source/M_DFA_Func.h | 2 +- 12 files changed, 47 insertions(+), 20 deletions(-) rename run.bat => run_samples.bat (64%) create mode 100644 samples/static_func/static_func.ling diff --git a/Readme.md b/Readme.md index fd926b7..d995df0 100644 --- a/Readme.md +++ b/Readme.md @@ -1,8 +1,15 @@ +### LingLang +C with o.f() +- No inherit +- No complicated syntax +- For spartan-programmers + #### Dependancies utf8.h - https://github.com/sheredom/utf8.h raylib - https://github.com/raysan5/raylib #### FA +``` NFA Top = -> DFA assign stm ; -> DFA field @@ -41,4 +48,5 @@ DFA struct = -> DFA assign stm ; -> DFA declare stm fn -> DFA function - } -> END \ No newline at end of file + } -> END +``` \ No newline at end of file diff --git a/run.bat b/run_samples.bat similarity index 64% rename from run.bat rename to run_samples.bat index b6ea28c..4c6363d 100644 --- a/run.bat +++ b/run_samples.bat @@ -1,4 +1,5 @@ @echo off call build.bat lingc.exe -i samples\import +lingc.exe -i samples\static_func @echo on \ No newline at end of file diff --git a/samples/static_func/static_func.ling b/samples/static_func/static_func.ling new file mode 100644 index 0000000..5283cc8 --- /dev/null +++ b/samples/static_func/static_func.ling @@ -0,0 +1,12 @@ +public static fn Main() { + +} + +public static i8 Ret1(i8 a) { + return a; +} + +public static i8, i32 Ret2(i8 a, i32 b) { + i32 c = a + b; + return a, c; +} \ No newline at end of file diff --git a/src/Business/B_Tokenize.c b/src/Business/B_Tokenize.c index f78ee08..4807ab5 100644 --- a/src/Business/B_Tokenize.c +++ b/src/Business/B_Tokenize.c @@ -66,12 +66,12 @@ void B_Tokenize_SeqMove(E_Doc *doc, const string filename, const string code, lo // D_NFA_Top_Enter(nfa_top); // } } else if (top_status == NFA_Top_Status_Func) { - // M_DFA_Func *fsm_func = nfa_top->dfa_func; - // end_index = D_DFA_Func_Process(fsm_func, filename, line, isSplit, word, end_index, code, size); - // if (fsm_func->is_done) { - // E_Doc_StaticFunc_Add(doc, fsm_func->function); - // D_NFA_Top_Enter(nfa_top); - // } + M_DFA_Func *dfa_func = nfa_top->dfa_func; + D_DFA_Func_Process(dfa_func, code, word, &cursor); + if (dfa_func->is_done) { + E_Doc_StaticFunc_Add(doc, dfa_func->function); + D_NFA_Top_Enter(nfa_top); + } } if (c == KW_NEWLINE) { diff --git a/src/Business/D_DFA_Func.c b/src/Business/D_DFA_Func.c index dab3d49..a66eed4 100644 --- a/src/Business/D_DFA_Func.c +++ b/src/Business/D_DFA_Func.c @@ -1,14 +1,18 @@ #include "D_DFA_Func.h" void D_DFA_Func_Free(M_DFA_Func *dfa_func) { - PLogNA("free top func\r\n"); } void D_DFA_Func_Enter(M_DFA_Func *dfa_func, E_Guess *guess) { - M_DFA_Func_Enter(dfa_func, guess); - PLogNA("enter top func\r\n"); + // already: + // public static fn + M_DFA_Func_Init(dfa_func, guess); + PLogNA("Enter DFA Func\r\n"); } -int D_DFA_Func_Process(M_DFA_Func *dfa_func, const string file, int line, bool is_split, const string word, int index, const string code, long size) { - return index; +void NamePhase_Process(M_DFA_Func *dfa_func, const string code, const string word, M_Cursor *cursor) { + // ( +} + +void D_DFA_Func_Process(M_DFA_Func *dfa_func, const string code, const string word, M_Cursor *cursor) { } \ No newline at end of file diff --git a/src/Business/D_DFA_Func.h b/src/Business/D_DFA_Func.h index 35ba606..6e09b6a 100644 --- a/src/Business/D_DFA_Func.h +++ b/src/Business/D_DFA_Func.h @@ -5,6 +5,6 @@ void D_DFA_Func_Free(M_DFA_Func *dfa_func); void D_DFA_Func_Enter(M_DFA_Func *dfa_func, E_Guess *guess); -int D_DFA_Func_Process(M_DFA_Func *dfa_func, const string file, int line, bool is_split, const string word, int index, const string code, long size); +void D_DFA_Func_Process(M_DFA_Func *dfa_func, const string code, const string word, M_Cursor *cursor); #endif \ No newline at end of file diff --git a/src/Business/D_DFA_Import.c b/src/Business/D_DFA_Import.c index 4b4b2be..2f3d622 100644 --- a/src/Business/D_DFA_Import.c +++ b/src/Business/D_DFA_Import.c @@ -8,7 +8,7 @@ void D_DFA_Import_Free(M_DFA_Import *fsm) { void D_DFA_Import_Enter(M_DFA_Import *fsm) { memset(fsm, 0, sizeof(M_DFA_Import)); - PLogNA("enter top import\r\n"); + PLogNA("Enter DFA Import\r\n"); } void D_DFA_Import_Process(M_DFA_Import *fsm, const string code, const string word, M_Cursor *cursor) { diff --git a/src/Business/D_DFA_Struct.c b/src/Business/D_DFA_Struct.c index 86408b4..a89462d 100644 --- a/src/Business/D_DFA_Struct.c +++ b/src/Business/D_DFA_Struct.c @@ -2,12 +2,12 @@ #include "D_NFA_Top.h" void D_DFA_Struct_Free(M_DFA_Struct *dfa_struct) { - PLogNA("free top struct\r\n"); } void Guess_Enter(M_DFA_Struct *dfa_struct) { dfa_struct->phase = StructPhase_Guess; E_Guess_Init(&dfa_struct->guess); + PLogNA("Enter DFA Struct\r\n"); } int Phase_Name_Process(M_DFA_Struct *dfa_struct, const string file, int line, bool isSplit, const string word, int index, const string code, long size) { diff --git a/src/Business/D_NFA_Top.c b/src/Business/D_NFA_Top.c index 22ff100..b0d8257 100644 --- a/src/Business/D_NFA_Top.c +++ b/src/Business/D_NFA_Top.c @@ -11,6 +11,7 @@ void D_NFA_Top_Free(M_NFA_Top *nfa_top) { void D_NFA_Top_Enter(M_NFA_Top *nfa_top) { nfa_top->status = NFA_Top_Status_Guess; E_Guess_Init(&nfa_top->guess); + PLogNA("Enter NFA Top\r\n"); } void D_NFA_Top_Process(M_NFA_Top *nfa_top, const string code, const string word, M_Cursor *cursor) { @@ -27,9 +28,9 @@ void D_NFA_Top_Process(M_NFA_Top *nfa_top, const string code, const string word, D_DFA_Import_Enter(dfa_import); } else if (strcmp(word, KW_FUNC) == 0) { // fn - // nfa_top->status = NFA_Top_Status_Func; - // M_DFA_Func *dfa_func = nfa_top->dfa_func; - // D_DFA_Func_Enter(dfa_func, guess); + nfa_top->status = NFA_Top_Status_Func; + M_DFA_Func *dfa_func = nfa_top->dfa_func; + D_DFA_Func_Enter(dfa_func, guess); } else if (strcmp(word, KW_STRUCT) == 0) { // struct // nfa_top->status = NFA_Top_Status_Struct; diff --git a/src/Business/Util_Cursor.c b/src/Business/Util_Cursor.c index 0f3c482..cfc212d 100644 --- a/src/Business/Util_Cursor.c +++ b/src/Business/Util_Cursor.c @@ -21,6 +21,7 @@ void Util_Cursor_DealEmpty(M_Cursor *cursor, const string code, const string wor ++cursor->index; ++cursor->line; } else { + printf("err word:%s\r\n", word); PFailed(cursor->file, cursor->line, ERR_UNDIFINDED_ERR); } } \ No newline at end of file diff --git a/src/Entities_Source/M_DFA_Func.c b/src/Entities_Source/M_DFA_Func.c index d89df0a..0f38e62 100644 --- a/src/Entities_Source/M_DFA_Func.c +++ b/src/Entities_Source/M_DFA_Func.c @@ -73,7 +73,7 @@ int BodyPhase_Process(M_DFA_Func *fsm, const string file, int line, bool is_spli } // public -void M_DFA_Func_Enter(M_DFA_Func *fsm, E_Guess *guess) { +void M_DFA_Func_Init(M_DFA_Func *fsm, E_Guess *guess) { memset(fsm, 0, sizeof(M_DFA_Func)); String_CopyAccess(fsm->guess.access, guess->access); fsm->guess.is_const = guess->is_const; diff --git a/src/Entities_Source/M_DFA_Func.h b/src/Entities_Source/M_DFA_Func.h index 8e0bea2..c3e42b7 100644 --- a/src/Entities_Source/M_DFA_Func.h +++ b/src/Entities_Source/M_DFA_Func.h @@ -28,7 +28,7 @@ typedef struct M_DFA_Func { } M_DFA_Func; +void M_DFA_Func_Init(M_DFA_Func *fsm, E_Guess *guess); void M_DFA_Func_Free(M_DFA_Func *fsm); -void M_DFA_Func_Enter(M_DFA_Func *fsm, E_Guess *guess); int M_DFA_Func_Process(M_DFA_Func *fsm, const string file, int line, bool is_split, const string word, int index, const string code, long size); #endif \ No newline at end of file