Skip to content

Commit

Permalink
<feature> WIP add: DFA Func
Browse files Browse the repository at this point in the history
  • Loading branch information
jackutea committed Jan 10, 2024
1 parent b5833b9 commit d18e9ce
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 20 deletions.
10 changes: 9 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -41,4 +48,5 @@ DFA struct
= -> DFA assign stm
; -> DFA declare stm
fn -> DFA function
} -> END
} -> END
```
1 change: 1 addition & 0 deletions run.bat → run_samples.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@echo off
call build.bat
lingc.exe -i samples\import
lingc.exe -i samples\static_func
@echo on
12 changes: 12 additions & 0 deletions samples/static_func/static_func.ling
Original file line number Diff line number Diff line change
@@ -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;
}
12 changes: 6 additions & 6 deletions src/Business/B_Tokenize.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
14 changes: 9 additions & 5 deletions src/Business/D_DFA_Func.c
Original file line number Diff line number Diff line change
@@ -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) {
}
2 changes: 1 addition & 1 deletion src/Business/D_DFA_Func.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/Business/D_DFA_Import.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/Business/D_DFA_Struct.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 4 additions & 3 deletions src/Business/D_NFA_Top.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/Business/Util_Cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion src/Entities_Source/M_DFA_Func.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Entities_Source/M_DFA_Func.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d18e9ce

Please sign in to comment.