v1.0
This commit is contained in:
commit
93d838f14c
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
ati.out
|
||||||
|
obj/*.o
|
35
Makefile
Executable file
35
Makefile
Executable file
@ -0,0 +1,35 @@
|
|||||||
|
CXX:=g++
|
||||||
|
CFLAGS:=-O0 -ggdb -std=c++17
|
||||||
|
CPPFLAGS:=-D DEBUG
|
||||||
|
LDLIBS:=
|
||||||
|
LDFLAGS:=
|
||||||
|
COMP:=$(CXX) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(LDLIBS)
|
||||||
|
|
||||||
|
OBJD:=obj/
|
||||||
|
SRCD:=src/
|
||||||
|
SRC:=main.cpp lexer.cpp algo.cpp
|
||||||
|
SRC:=$(addprefix ${SRCD},${SRC})
|
||||||
|
OBJ:=$(subst .cpp,.o,$(subst ${SRCD},${OBJD},${SRC}))
|
||||||
|
|
||||||
|
OUTPUT:=ati.out
|
||||||
|
|
||||||
|
.PHONY: main clean run
|
||||||
|
|
||||||
|
main: ${OBJ}
|
||||||
|
${COMP} ${OBJ} -o ${OUTPUT}
|
||||||
|
|
||||||
|
obj/%.o: src/%.cpp
|
||||||
|
${COMP} -c $< -o ${OBJD}/$*.o
|
||||||
|
|
||||||
|
clean:
|
||||||
|
-rm ${OBJD}/*
|
||||||
|
-rm ./${OUTPUT}
|
||||||
|
|
||||||
|
run:
|
||||||
|
./${OUTPUT}
|
||||||
|
|
||||||
|
gdb:
|
||||||
|
sudo gdb --directory=./src -p $(shell pgrep ${OUTPUT})
|
||||||
|
|
||||||
|
algo:
|
||||||
|
make -C debug/
|
0
NOTES.txt
Normal file
0
NOTES.txt
Normal file
3
TODO.list
Normal file
3
TODO.list
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
/*--------------------------------------------Todos------------------------------------------------\\
|
||||||
|
|
|
||||||
|
\\-------------------------------------------------------------------------------------------------*/
|
4
debug/Makefile
Normal file
4
debug/Makefile
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
m4:
|
||||||
|
for i in *.m4; do \
|
||||||
|
m4 $$i > $$(basename $$i .m4); \
|
||||||
|
done
|
2
debug/assignment.algo
Normal file
2
debug/assignment.algo
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
1;0;i;=;1;0;0
|
||||||
|
1;0;h;=;2;0;0
|
3
debug/eval.algo
Normal file
3
debug/eval.algo
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
1;0;i;=;1;0;0
|
||||||
|
1;0;h;=;2;0;0
|
||||||
|
1;0;k;=;3;*;h
|
47
debug/i.algo
Normal file
47
debug/i.algo
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
" Lehmer generator
|
||||||
|
0;lehmer;=;4;0;0
|
||||||
|
1;7;0;0;0;0
|
||||||
|
0;argv-1;=;argv-1;*;48271;
|
||||||
|
0;argv-1;=;argv-1;%;2147483647
|
||||||
|
1;return;0;0;0
|
||||||
|
" swap
|
||||||
|
0;swap;=;10;0;0
|
||||||
|
1;14;0;0;0;0
|
||||||
|
0;buf;=;argv-1;0;0
|
||||||
|
0;argv-1;=;argv-2;0;0
|
||||||
|
0;argv-2;=;buf;0;0
|
||||||
|
1;return;0;0;0
|
||||||
|
" call
|
||||||
|
0;i;=;0;0;0
|
||||||
|
0;argv-1;=;11;0;0
|
||||||
|
1;lehmer;1;0;0;0
|
||||||
|
0;argv-2-i;=;argv-1;0;0
|
||||||
|
0;i;=;i;+;1
|
||||||
|
3;17;0;i;=;10
|
||||||
|
0;argv-1;=;10;0;0
|
||||||
|
1;24;1;0;0;0
|
||||||
|
1;return;0;0;0
|
||||||
|
" selection sort
|
||||||
|
0;n;=;argv-1;0;0
|
||||||
|
0;i;=;0;0;0;
|
||||||
|
0;a-i;=;argv-2-i;0;0
|
||||||
|
0;i;=;i;+;1
|
||||||
|
3;27;0;i;=;10
|
||||||
|
" body
|
||||||
|
0;i;=;0;0;0;
|
||||||
|
3;return;0;i;<;n
|
||||||
|
0;min;=;i;0;0
|
||||||
|
0;j;=;i;+;1
|
||||||
|
3;40;0;j;<;n
|
||||||
|
3;38;0;a-j;<;a-min
|
||||||
|
0;min;=;j;0;0
|
||||||
|
0;j;=;1;+;j
|
||||||
|
1;35;0;0;0
|
||||||
|
2;46;0;min;=;i
|
||||||
|
0;argv-1;=;a-i;0;0
|
||||||
|
0;argv-2;=;a-min;0;0
|
||||||
|
1;swap;1;0;0;0
|
||||||
|
0;a-i;=;argv-1;0;0
|
||||||
|
0;a-min;=;argv-2;0;0
|
||||||
|
0;i;=;i;+;1
|
||||||
|
1;32;0;0;0
|
47
debug/i.algo.m4
Normal file
47
debug/i.algo.m4
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
" Lehmer generator
|
||||||
|
0;lehmer;=;eval(__line__+2);0;0
|
||||||
|
1;eval(__line__+4);0;0;0;0
|
||||||
|
0;argv-1;=;argv-1;*;48271;
|
||||||
|
0;argv-1;=;argv-1;%;2147483647
|
||||||
|
1;return;0;0;0
|
||||||
|
" swap
|
||||||
|
0;swap;=;eval(__line__+2);0;0
|
||||||
|
1;eval(__line__+5);0;0;0;0
|
||||||
|
0;buf;=;argv-1;0;0
|
||||||
|
0;argv-1;=;argv-2;0;0
|
||||||
|
0;argv-2;=;buf;0;0
|
||||||
|
1;return;0;0;0
|
||||||
|
" call
|
||||||
|
0;i;=;0;0;0
|
||||||
|
0;argv-1;=;11;0;0
|
||||||
|
1;lehmer;1;0;0;0
|
||||||
|
0;argv-2-i;=;argv-1;0;0
|
||||||
|
0;i;=;i;+;1
|
||||||
|
3;eval(__line__-3);0;i;=;10
|
||||||
|
0;argv-1;=;10;0;0
|
||||||
|
1;eval(__line__+2);1;0;0;0
|
||||||
|
1;return;0;0;0
|
||||||
|
" selection sort
|
||||||
|
0;n;=;argv-1;0;0
|
||||||
|
0;i;=;0;0;0;
|
||||||
|
0;a-i;=;argv-2-i;0;0
|
||||||
|
0;i;=;i;+;1
|
||||||
|
3;eval(__line__-2);0;i;=;10
|
||||||
|
" body
|
||||||
|
0;i;=;0;0;0;
|
||||||
|
3;return;0;i;<;n
|
||||||
|
0;min;=;i;0;0
|
||||||
|
0;j;=;i;+;1
|
||||||
|
3;eval(__line__+5);0;j;<;n
|
||||||
|
3;eval(__line__+2);0;a-j;<;a-min
|
||||||
|
0;min;=;j;0;0
|
||||||
|
0;j;=;1;+;j
|
||||||
|
1;eval(__line__-4);0;0;0
|
||||||
|
2;eval(__line__+6);0;min;=;i
|
||||||
|
0;argv-1;=;a-i;0;0
|
||||||
|
0;argv-2;=;a-min;0;0
|
||||||
|
1;swap;1;0;0;0
|
||||||
|
0;a-i;=;argv-1;0;0
|
||||||
|
0;a-min;=;argv-2;0;0
|
||||||
|
0;i;=;i;+;1
|
||||||
|
1;eval(__line__-15);0;0;0
|
152
docs/ALGO_DETAIL.txt
Normal file
152
docs/ALGO_DETAIL.txt
Normal file
@ -0,0 +1,152 @@
|
|||||||
|
{
|
||||||
|
int myArray[] = {34, 23, 78, 41, 7, 87, 52, 36, 29, 42};
|
||||||
|
//
|
||||||
|
void selectoinSort(int a[], const int &n){
|
||||||
|
int i = 0;
|
||||||
|
while(i < n){
|
||||||
|
int min = i;
|
||||||
|
int j = i + 1;
|
||||||
|
while(j < n){
|
||||||
|
if(a[j] < a[min]){
|
||||||
|
min = j;
|
||||||
|
}
|
||||||
|
j = j + 1;
|
||||||
|
}
|
||||||
|
if(min != i){
|
||||||
|
swap(a[i], a[min])
|
||||||
|
}
|
||||||
|
i = i + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//
|
||||||
|
selectionSort(myArray, 10);
|
||||||
|
}
|
||||||
|
| ID | PTR | INDEX | VALUE |
|
||||||
|
:------:-------:---------:-----------:
|
||||||
|
| x | seq | 0 |
|
||||||
|
// array
|
||||||
|
| 1 | int | 0 | 34 |
|
||||||
|
...
|
||||||
|
| 1 | int | 9 | 42 |
|
||||||
|
|
||||||
|
class fun{
|
||||||
|
WORD* argv[];
|
||||||
|
};
|
||||||
|
|
||||||
|
// | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|
||||||
|
// 1
|
||||||
|
// A
|
||||||
|
// |
|
||||||
|
//reserverd bit
|
||||||
|
//
|
||||||
|
// | typename | var-0 | var-1 | var-2 |
|
||||||
|
// byte-0 addr-1 addr-2 addr-3
|
||||||
|
Atom:
|
||||||
|
+-----atom-----+
|
||||||
|
| +--------+ |
|
||||||
|
| | sor id | |
|
||||||
|
| +--------+ |
|
||||||
|
+--------------+
|
||||||
|
>nem tudunk csak atomra ugrani
|
||||||
|
>az atomok eddig instrukció fajtától függően határoztuk meg, viszont kreatívabban is lehetne
|
||||||
|
|
||||||
|
### Original ###
|
||||||
|
Folyamatábra_elem : "Folyamatábra elem"; atom név
|
||||||
|
AD_ID : "AlgoDetail ID"; atom id ^ ^ ^ \_ elsődleges kulcs
|
||||||
|
Ssz : "?!"; sor id . . . . . . . . . /
|
||||||
|
V : "Változó"; cím
|
||||||
|
V_ndx : "Változó iNDeX"; cím offset // >>>NOTE1
|
||||||
|
VM : "Változó Művelet"
|
||||||
|
func : "FUNCió"; függvény hívás // >>>NOTE3
|
||||||
|
J id : "Jump ID"; ugrás célpont; egy atom id
|
||||||
|
// azt hiszem nyújt egy fajta biztonságot
|
||||||
|
( \
|
||||||
|
V1 : "Változó 1" \
|
||||||
|
V_ndx : "Változó iNDeX"; inkonzisztens módon nincs megszámozva /* >>>NOTE1 */\
|
||||||
|
C1 : "Constant 1" \
|
||||||
|
) \
|
||||||
|
AM : "Alg Művelet" } >>>NOTE2
|
||||||
|
( /
|
||||||
|
V2 /
|
||||||
|
V_ndx /
|
||||||
|
C2 /
|
||||||
|
) /
|
||||||
|
VB1 \
|
||||||
|
CB1 \
|
||||||
|
F1 \
|
||||||
|
VJ1 \
|
||||||
|
CJ1 \
|
||||||
|
LM : "?! Művelet" } >>>NOTE2
|
||||||
|
VB2 /
|
||||||
|
CB2 /
|
||||||
|
F2 /
|
||||||
|
VJ2 /
|
||||||
|
CJ2 /
|
||||||
|
|
||||||
|
NOTE:
|
||||||
|
>hunglish
|
||||||
|
>1*: a változónév alapból magasszintű absztraktció; csak az olvashatóság/parsibleness kedvéért van értelme külön kezelni
|
||||||
|
>3*: teljesen redundáns az ugrás mező miatt, hacsak nem a paramétereket is belekódoljuk.
|
||||||
|
ebben az esetben kell egy módszer amivel egy kifejezésben utalhatunk egy tömb N. elemére ami inkonzistens
|
||||||
|
a [Név] [Index] oszlop felépítéssel
|
||||||
|
>2*: ismétéls; a 2 igazán indokolatlan szám; logikusan vagy 1 feltételt mentek és tovább kezelem,
|
||||||
|
vagy végtelelen feltételt határozhatok meg egy sorban; az előbbi a logikus
|
||||||
|
az oszlop számok homogenitása miatt
|
||||||
|
|
||||||
|
30 oszlop
|
||||||
|
legalább 10 redundáns
|
||||||
|
|
||||||
|
### Revoked ###
|
||||||
|
enum JMP {
|
||||||
|
no,
|
||||||
|
always,
|
||||||
|
wt, //when true
|
||||||
|
wf //when false
|
||||||
|
}
|
||||||
|
(IN) (OUT)
|
||||||
|
| LN | JMP | DEST | ASSIGNEMT | OPR1 | OPERATOR | OPR2 | COMMENT |
|
||||||
|
1 0 i = 0 0 0
|
||||||
|
2 3 return 0 i < &argv[2]
|
||||||
|
3 0 min = i 0 0
|
||||||
|
4 0 j = i + 1
|
||||||
|
5 3 9 0 j < n
|
||||||
|
6 3 8 0 a[j] < a[min]
|
||||||
|
7 0 min = j 0 0
|
||||||
|
8 0 j += 1 0 0
|
||||||
|
9 2 13 0 min = i
|
||||||
|
10 0 call[0] = &a[i] 0 0
|
||||||
|
11 0 call[1] = &a[min] 0 0
|
||||||
|
12 1 &swap 0 call 0 0
|
||||||
|
13 0 i += 1
|
||||||
|
14 1 return 0 0 0 0
|
||||||
|
|
||||||
|
9 oszlop
|
||||||
|
0 redundancia
|
||||||
|
|
||||||
|
|
||||||
|
(IN) (OUT)
|
||||||
|
| Address | PK2 | JMP | DEST | ASSIGNEMT | OPR1 | OPERATOR | OPR2 | COMMENT |
|
||||||
|
1 1 0 i = 0 0 0
|
||||||
|
2 1 3 return 0 i < &argv[2]
|
||||||
|
3 1 0 min = i 0 0
|
||||||
|
3 2 0 j = i + 1
|
||||||
|
4 1 3 9 0 j < n
|
||||||
|
5 1 3 8 0 a[j] < a[min]
|
||||||
|
6 1 0 min = j 0 0
|
||||||
|
6 2 0 j += 1 0 0
|
||||||
|
7 1 2 13 0 min = i
|
||||||
|
8 1 0 call[0] = &a[i] 0 0
|
||||||
|
8 2 0 call[1] = &a[min] 0 0
|
||||||
|
8 3 1 &swap 0 call 0 0
|
||||||
|
9 1 0 i += 1
|
||||||
|
10 1 1 return 0 0 0 0
|
||||||
|
|
||||||
|
10 oszlop
|
||||||
|
az atom fogalma megmaradt -> mivel JT-ben nincs ilyen mekötés ezért értelmetlen megtartani
|
||||||
|
|
||||||
|
// can oracle/mysql fork?
|
||||||
|
// is varchar allocated inline?
|
||||||
|
|
||||||
|
since JT is ordered insertion is a nightmare
|
||||||
|
|
||||||
|
the deletion problem is actually self evident. an elems life time is as long as we have any data on it.
|
45
docs/fibonacci_algo.table
Normal file
45
docs/fibonacci_algo.table
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
+------------------------+-------+-----+------+--------------------------------------------------------------------------------+-----+--------------------------------------------------------------------------------------------+------------------------------------------------------------------------+------------------------------------------------------------------+----------------------------------------------------------+-----------------------------------------------------------------------------------------+------------------------------------------------+---+----+---+----+-------+----+---+-----+-----+----+-----+-----+----+-----+-----+----+-----+-----+--------------------------------------------------------------------------------+
|
||||||
|
| Folyamatábra_elem | AD_ID | Ssz | V | V_ndx | VM | func | J id | ( | V1 | V_ndx | C1 | ) | AM | ( | V2 | V_ndx | C2 | ) | VB1 | CB1 | F1 | VJ1 | CJ1 | LM | VB2 | CB2 | F2 | VJ2 | CJ2 | AD_ID=Alg._detail_table, V=változó+index., VM=Változó múvelete,J id =Jump |
|
||||||
|
+------------------------+-------+-----+------+--------------------------------------------------------------------------------+-----+--------------------------------------------------------------------------------------------+------------------------------------------------------------------------+------------------------------------------------------------------+----------------------------------------------------------+-----------------------------------------------------------------------------------------+------------------------------------------------+---+----+---+----+-------+----+---+-----+-----+----+-----+-----+----+-----+-----+----+-----+-----+--------------------------------------------------------------------------------+
|
||||||
|
| Start | 1 | 1 | 2 | Start :indul a projekt,ami az AD_ID=2 Dataimput ID-val kezdődik/folytatódik | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
+------------------------+-------+-----+------+--------------------------------------------------------------------------------+-----+--------------------------------------------------------------------------------------------+------------------------------------------------------------------------+------------------------------------------------------------------+----------------------------------------------------------+-----------------------------------------------------------------------------------------+------------------------------------------------+---+----+---+----+-------+----+---+-----+-----+----+-----+-----+----+-----+-----+----+-----+-----+--------------------------------------------------------------------------------+
|
||||||
|
| DataInput | 2 | 1 | a | =' | | | 1 | Definició+ default constans értékadás Fibonecci 1. elemének | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
+------------------------+-------+-----+------+--------------------------------------------------------------------------------+-----+--------------------------------------------------------------------------------------------+------------------------------------------------------------------------+------------------------------------------------------------------+----------------------------------------------------------+-----------------------------------------------------------------------------------------+------------------------------------------------+---+----+---+----+-------+----+---+-----+-----+----+-----+-----+----+-----+-----+----+-----+-----+--------------------------------------------------------------------------------+
|
||||||
|
| | 2 | 2 | b | =' | | | 2 | Definició+ default constans értékadás Fibonecci 2. elemének | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
+------------------------+-------+-----+------+--------------------------------------------------------------------------------+-----+--------------------------------------------------------------------------------------------+------------------------------------------------------------------------+------------------------------------------------------------------+----------------------------------------------------------+-----------------------------------------------------------------------------------------+------------------------------------------------+---+----+---+----+-------+----+---+-----+-----+----+-----+-----+----+-----+-----+----+-----+-----+--------------------------------------------------------------------------------+
|
||||||
|
| | 2 | 3 | f | =' | | 0 | Definició+ default constans értékadás aktuális Fibonacci számnak | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
+------------------------+-------+-----+------+--------------------------------------------------------------------------------+-----+--------------------------------------------------------------------------------------------+------------------------------------------------------------------------+------------------------------------------------------------------+----------------------------------------------------------+-----------------------------------------------------------------------------------------+------------------------------------------------+---+----+---+----+-------+----+---+-----+-----+----+-----+-----+----+-----+-----+----+-----+-----+--------------------------------------------------------------------------------+
|
||||||
|
| | 2 | 4 | ft | =' | 10 | Definiálom Fibonacci tömb max_tömbelemét | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
+------------------------+-------+-----+------+--------------------------------------------------------------------------------+-----+--------------------------------------------------------------------------------------------+------------------------------------------------------------------------+------------------------------------------------------------------+----------------------------------------------------------+-----------------------------------------------------------------------------------------+------------------------------------------------+---+----+---+----+-------+----+---+-----+-----+----+-----+-----+----+-----+-----+----+-----+-----+--------------------------------------------------------------------------------+
|
||||||
|
| | 2 | 5 | x | =' | | | 0 | Definiálom az "x" ciklus változót | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
+------------------------+-------+-----+------+--------------------------------------------------------------------------------+-----+--------------------------------------------------------------------------------------------+------------------------------------------------------------------------+------------------------------------------------------------------+----------------------------------------------------------+-----------------------------------------------------------------------------------------+------------------------------------------------+---+----+---+----+-------+----+---+-----+-----+----+-----+-----+----+-----+-----+----+-----+-----+--------------------------------------------------------------------------------+
|
||||||
|
| | 2 | 6 | 3 | AD_ID=3 ugrás objektum ciklus ini részére | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
+------------------------+-------+-----+------+--------------------------------------------------------------------------------+-----+--------------------------------------------------------------------------------------------+------------------------------------------------------------------------+------------------------------------------------------------------+----------------------------------------------------------+-----------------------------------------------------------------------------------------+------------------------------------------------+---+----+---+----+-------+----+---+-----+-----+----+-----+-----+----+-----+-----+----+-----+-----+--------------------------------------------------------------------------------+
|
||||||
|
| Ciklus Ini dönt. pont | 3 | 1 | 4 | | | x | < | 10 | Számítási ciklus, addig ugrik a AD_ID=4-re amíg x<10 | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
+------------------------+-------+-----+------+--------------------------------------------------------------------------------+-----+--------------------------------------------------------------------------------------------+------------------------------------------------------------------------+------------------------------------------------------------------+----------------------------------------------------------+-----------------------------------------------------------------------------------------+------------------------------------------------+---+----+---+----+-------+----+---+-----+-----+----+-----+-----+----+-----+-----+----+-----+-----+--------------------------------------------------------------------------------+
|
||||||
|
| | 3 | 2 | 5 | x | >= | 10 | Else ág (X>=10) az 5-re ugrik | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
+------------------------+-------+-----+------+--------------------------------------------------------------------------------+-----+--------------------------------------------------------------------------------------------+------------------------------------------------------------------------+------------------------------------------------------------------+----------------------------------------------------------+-----------------------------------------------------------------------------------------+------------------------------------------------+---+----+---+----+-------+----+---+-----+-----+----+-----+-----+----+-----+-----+----+-----+-----+--------------------------------------------------------------------------------+
|
||||||
|
| C_mag számítás | 4 | 1 | f | =' | | a | +' | | b | | Akt_Fibo = előző két elem összege (a+b) | | | | | | | | | | | | | | | | | | | |
|
||||||
|
+------------------------+-------+-----+------+--------------------------------------------------------------------------------+-----+--------------------------------------------------------------------------------------------+------------------------------------------------------------------------+------------------------------------------------------------------+----------------------------------------------------------+-----------------------------------------------------------------------------------------+------------------------------------------------+---+----+---+----+-------+----+---+-----+-----+----+-----+-----+----+-----+-----+----+-----+-----+--------------------------------------------------------------------------------+
|
||||||
|
| | 4 | 2 | ft | x | =' | f | | | | Fibonacci tömb x index oszlopába tesszük az előzőleg számolt Fibo_akt értékét! | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
+------------------------+-------+-----+------+--------------------------------------------------------------------------------+-----+--------------------------------------------------------------------------------------------+------------------------------------------------------------------------+------------------------------------------------------------------+----------------------------------------------------------+-----------------------------------------------------------------------------------------+------------------------------------------------+---+----+---+----+-------+----+---+-----+-----+----+-----+-----+----+-----+-----+----+-----+-----+--------------------------------------------------------------------------------+
|
||||||
|
| | 4 | 3 | a | =' | b | A kisebbik szám egyenlő lesz a nagyobbik számmal | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
+------------------------+-------+-----+------+--------------------------------------------------------------------------------+-----+--------------------------------------------------------------------------------------------+------------------------------------------------------------------------+------------------------------------------------------------------+----------------------------------------------------------+-----------------------------------------------------------------------------------------+------------------------------------------------+---+----+---+----+-------+----+---+-----+-----+----+-----+-----+----+-----+-----+----+-----+-----+--------------------------------------------------------------------------------+
|
||||||
|
| | 4 | 4 | b | =' | f | A nagyobbik szám egyenlő lesz a Fibo_szám-mal, ami a sorozat új eleme | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
+------------------------+-------+-----+------+--------------------------------------------------------------------------------+-----+--------------------------------------------------------------------------------------------+------------------------------------------------------------------------+------------------------------------------------------------------+----------------------------------------------------------+-----------------------------------------------------------------------------------------+------------------------------------------------+---+----+---+----+-------+----+---+-----+-----+----+-----+-----+----+-----+-----+----+-----+-----+--------------------------------------------------------------------------------+
|
||||||
|
| | 4 | 5 | x | =' | x | +' | 1 | Növelem a ciklusváltozót | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
+------------------------+-------+-----+------+--------------------------------------------------------------------------------+-----+--------------------------------------------------------------------------------------------+------------------------------------------------------------------------+------------------------------------------------------------------+----------------------------------------------------------+-----------------------------------------------------------------------------------------+------------------------------------------------+---+----+---+----+-------+----+---+-----+-----+----+-----+-----+----+-----+-----+----+-----+-----+--------------------------------------------------------------------------------+
|
||||||
|
| | 4 | 6 | 3 | Itt van vége a ciklus_magnak és a ciklus AD_ID=3 Dpontjára [4,5] | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
+------------------------+-------+-----+------+--------------------------------------------------------------------------------+-----+--------------------------------------------------------------------------------------------+------------------------------------------------------------------------+------------------------------------------------------------------+----------------------------------------------------------+-----------------------------------------------------------------------------------------+------------------------------------------------+---+----+---+----+-------+----+---+-----+-----+----+-----+-----+----+-----+-----+----+-----+-----+--------------------------------------------------------------------------------+
|
||||||
|
| Ciklus Ini dönt. pont | 5 | 1 | 6 | | | x | < | 10 | Adatkiíró ciklus ini ,addig ugrik a 6-re amíg x<10 | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
+------------------------+-------+-----+------+--------------------------------------------------------------------------------+-----+--------------------------------------------------------------------------------------------+------------------------------------------------------------------------+------------------------------------------------------------------+----------------------------------------------------------+-----------------------------------------------------------------------------------------+------------------------------------------------+---+----+---+----+-------+----+---+-----+-----+----+-----+-----+----+-----+-----+----+-----+-----+--------------------------------------------------------------------------------+
|
||||||
|
| | 5 | 2 | 7 | x | >= | 10 | else ág => a 7-re ugrik | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
+------------------------+-------+-----+------+--------------------------------------------------------------------------------+-----+--------------------------------------------------------------------------------------------+------------------------------------------------------------------------+------------------------------------------------------------------+----------------------------------------------------------+-----------------------------------------------------------------------------------------+------------------------------------------------+---+----+---+----+-------+----+---+-----+-----+----+-----+-----+----+-----+-----+----+-----+-----+--------------------------------------------------------------------------------+
|
||||||
|
| C_mag output | 6 | 1 | f | x | Out | Fibo_tomb x indexű értékét 1= képernyőre, 2=pdf file, 3=cvs file-be jelenítem meg | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
+------------------------+-------+-----+------+--------------------------------------------------------------------------------+-----+--------------------------------------------------------------------------------------------+------------------------------------------------------------------------+------------------------------------------------------------------+----------------------------------------------------------+-----------------------------------------------------------------------------------------+------------------------------------------------+---+----+---+----+-------+----+---+-----+-----+----+-----+-----+----+-----+-----+----+-----+-----+--------------------------------------------------------------------------------+
|
||||||
|
| | 6 | 2 | x | =' | x | +' | 1 | x ciklus változó értékének növelése | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
+------------------------+-------+-----+------+--------------------------------------------------------------------------------+-----+--------------------------------------------------------------------------------------------+------------------------------------------------------------------------+------------------------------------------------------------------+----------------------------------------------------------+-----------------------------------------------------------------------------------------+------------------------------------------------+---+----+---+----+-------+----+---+-----+-----+----+-----+-----+----+-----+-----+----+-----+-----+--------------------------------------------------------------------------------+
|
||||||
|
| | 6 | 3 | 5 | Itt van vége a ciklus_magnak és a ciklus AD_ID=5 döntéspontjára ugrik | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
+------------------------+-------+-----+------+--------------------------------------------------------------------------------+-----+--------------------------------------------------------------------------------------------+------------------------------------------------------------------------+------------------------------------------------------------------+----------------------------------------------------------+-----------------------------------------------------------------------------------------+------------------------------------------------+---+----+---+----+-------+----+---+-----+-----+----+-----+-----+----+-----+-----+----+-----+-----+--------------------------------------------------------------------------------+
|
||||||
|
| End | 7 | 1 | null | Vége a proginak | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
+------------------------+-------+-----+------+--------------------------------------------------------------------------------+-----+--------------------------------------------------------------------------------------------+------------------------------------------------------------------------+------------------------------------------------------------------+----------------------------------------------------------+-----------------------------------------------------------------------------------------+------------------------------------------------+---+----+---+----+-------+----+---+-----+-----+----+-----+-----+----+-----+-----+----+-----+-----+--------------------------------------------------------------------------------+
|
6
docs/problems.txt
Normal file
6
docs/problems.txt
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
### Where does jokertao.value end? ###
|
||||||
|
Surely its not a problem when using VARCHAR2, however i highly doubt there a formal definition for that thing.
|
||||||
|
Its not a trivial type. Meaning as is now JT cannot actually be stored everything. Its JT+VARCHAR2 that stores everything.
|
||||||
|
Now, we either fixate the value size, or normalize the struct. // perhaps it can somehow be stored as a JT, tho unmengling it for every entry doesnt sound very pleasant
|
||||||
|
¤ by normalizing we get more columns
|
||||||
|
¤ by fixing the size we get multi cell values
|
0
obj/.placeholder
Normal file
0
obj/.placeholder
Normal file
36
src/JokerTao.cpp
Normal file
36
src/JokerTao.cpp
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
#include "JokerTao.h"
|
||||||
|
|
||||||
|
unsigned int JokerTao::id_ = JOKERTAO::END;
|
||||||
|
|
||||||
|
namespace jt{
|
||||||
|
inline std::vector<JokerTao> table;
|
||||||
|
|
||||||
|
unsigned findf_relationship(int attr_, std::string value_){
|
||||||
|
unsigned last_id = JOKERTAO::END - 1;
|
||||||
|
for(auto &&i : table[i]){
|
||||||
|
if(i.id == last_id){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(i.attr == attr && i.value == value_){
|
||||||
|
return i.index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return JOKERTAO::INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned find_attribute(unsigned id_, JokerTao* attr_, unsigned index_ = 0){
|
||||||
|
for(auto &&i : table[i]){
|
||||||
|
if(i.id != id_){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(i.attr == attr){
|
||||||
|
return i.index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return JOKERTAO::INVALID;
|
||||||
|
}
|
||||||
|
}
|
33
src/JokerTao.h
Normal file
33
src/JokerTao.h
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
enum JOKERTAO{
|
||||||
|
INVALID,
|
||||||
|
NAME,
|
||||||
|
VALUE
|
||||||
|
END
|
||||||
|
};
|
||||||
|
|
||||||
|
struct JokerTao{
|
||||||
|
unsigned id;
|
||||||
|
JokerTao *attr;
|
||||||
|
unsigned index;
|
||||||
|
std::string value; //void* value = nullptr;
|
||||||
|
|
||||||
|
inline unsigned last_id(){ return id__; }
|
||||||
|
JokerTao(attr_ = nullptr, value_ = "", id_ = id__++, index_ = 0) :
|
||||||
|
id(id_), attr(attr_), index(index_), value(value_){
|
||||||
|
}
|
||||||
|
delete JokerTao();
|
||||||
|
|
||||||
|
private:
|
||||||
|
static unsigned id__;
|
||||||
|
};
|
||||||
|
|
||||||
|
namespace jt{
|
||||||
|
extern std::vector<JokerTao> table;
|
||||||
|
|
||||||
|
unsigned findf_relationship(unsigned attr_, std::string value_);
|
||||||
|
unsigned find_attribute(unsigned index_, JokerTao* attr_, unsigned index_ = 0);
|
||||||
|
}
|
240
src/algo.cpp
Normal file
240
src/algo.cpp
Normal file
@ -0,0 +1,240 @@
|
|||||||
|
#include "algo.h"
|
||||||
|
|
||||||
|
namespace algo{
|
||||||
|
/* VARS */
|
||||||
|
inline std::stack<struct frame> callstack;
|
||||||
|
inline std::unordered_map<std::string, std::string> vars;
|
||||||
|
/**/
|
||||||
|
|
||||||
|
bool init(){
|
||||||
|
const char *const *c = standard_vars-1;
|
||||||
|
while((c++, *c != NULL)){
|
||||||
|
vars[*c] = EMPTY_CELL;
|
||||||
|
}
|
||||||
|
callstack.emplace();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void assign(const std::string &name, const std::string& val){
|
||||||
|
vars[name] = val;
|
||||||
|
//unsigned index = findf_relationship(NAME, v[ALGO::DESTINATION]);
|
||||||
|
//if(index == JOKERTAO::INVALID){
|
||||||
|
// jt::table.emplace_back(JOKERTAO::NAME, v[ALGO::DESTINATION]);
|
||||||
|
// jt::table.emplace_back(JOKERTAO::VALUE, v[ALGO::VALUE], 0);
|
||||||
|
//}else{
|
||||||
|
// jt[index].find_attribute()
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
|
||||||
|
void pop(unsigned &head){
|
||||||
|
if(callstack.size() == 1){
|
||||||
|
#ifdef DEBUG
|
||||||
|
printf(YELLOW "Return on empty callstack: exiting.\n" NORMAL);
|
||||||
|
#endif
|
||||||
|
raise(SIGINT);
|
||||||
|
}
|
||||||
|
callstack.pop();
|
||||||
|
head = callstack.top().bp + 1;
|
||||||
|
}
|
||||||
|
void push(const unsigned &head){
|
||||||
|
callstack.top().bp = head;
|
||||||
|
callstack.emplace();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string arref(std::string s){
|
||||||
|
for(int i = s.size()-1, last = i; i >= 0; i--){
|
||||||
|
if(s[i] == '-'){
|
||||||
|
s.replace(i+1, last-i, deref(s.substr(i+1, last-i)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string deref(std::string s){
|
||||||
|
s = arref(s);
|
||||||
|
return (vars.find(s) != vars.end()) ? deref(vars[s]) : s;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool jump(unsigned &head, const jmp &do_jump, const std::string &dest, const char &push){
|
||||||
|
bool ret = false;
|
||||||
|
switch(do_jump){
|
||||||
|
case algo::jmp::nop:
|
||||||
|
break;
|
||||||
|
case algo::jmp::jmp:
|
||||||
|
algo::call(head, dest, (push != algo::EMPTY_CELL));
|
||||||
|
ret = true;
|
||||||
|
break;
|
||||||
|
case algo::jmp::je:
|
||||||
|
if(algo::vars["eval"] == algo::true_){
|
||||||
|
algo::call(head, dest, (push != algo::EMPTY_CELL));
|
||||||
|
ret = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case algo::jmp::jne:
|
||||||
|
if(algo::vars["eval"] == algo::false_){
|
||||||
|
algo::call(head, dest, (push != algo::EMPTY_CELL));
|
||||||
|
ret = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#ifdef DEBUG
|
||||||
|
if(ret){
|
||||||
|
printf(MAGENTA "Jumped to '%s' (%s). " NORMAL, dest.c_str(), algo::deref(dest).c_str());
|
||||||
|
}
|
||||||
|
printf(MAGENTA "Head at %d. " NORMAL, head);
|
||||||
|
#endif
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void call(unsigned &head, const std::string &dest, const bool &is_push){
|
||||||
|
#ifdef DEBUG
|
||||||
|
long debug_stacklen = algo::callstack.size();
|
||||||
|
#endif
|
||||||
|
if(dest == "return"){
|
||||||
|
pop(head);
|
||||||
|
goto RETURN;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(is_push){ push(head); }
|
||||||
|
|
||||||
|
try{
|
||||||
|
head = std::stoi(deref(dest));
|
||||||
|
}catch(...){
|
||||||
|
#ifdef DEBUG
|
||||||
|
printf("Invalid jump destination '%s'", dest.c_str());
|
||||||
|
#endif
|
||||||
|
goto RETURN;
|
||||||
|
}
|
||||||
|
|
||||||
|
RETURN:
|
||||||
|
#ifdef DEBUG
|
||||||
|
if(algo::callstack.size() != debug_stacklen){
|
||||||
|
printf(YELLOW "[Stack: %ld->%ld] " NORMAL, debug_stacklen, algo::callstack.size());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
int aint(std::string s){
|
||||||
|
static const char c[] = "0123456789";
|
||||||
|
int i = 0;
|
||||||
|
bool sign = true;
|
||||||
|
while(true){
|
||||||
|
switch(s[i]){
|
||||||
|
case '-':
|
||||||
|
sign = !(sign xor false);
|
||||||
|
++i;
|
||||||
|
continue;
|
||||||
|
case '+':
|
||||||
|
sign = !(sign xor true);
|
||||||
|
++i;
|
||||||
|
continue;
|
||||||
|
default:
|
||||||
|
goto BR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
BR:
|
||||||
|
s.erase(0, i);
|
||||||
|
|
||||||
|
for(i = 0; i < s.size(); i++){
|
||||||
|
bool is_any = false;
|
||||||
|
for(int h = 0, end2 = sizeof(c)-1; h < end2; h++){
|
||||||
|
if(s[i] == c[h]){
|
||||||
|
is_any = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(not is_any){
|
||||||
|
s.erase(i, 1);
|
||||||
|
--i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(s == ""){ s = '0'; }
|
||||||
|
|
||||||
|
return std::stoi(s) * (sign ? 1 : -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void do_eval(const std::string &opr1, char oper, const std::string &opr2){ // convert to use assign()
|
||||||
|
#define CASECHAR(c){ \
|
||||||
|
case (char)(*#c):\
|
||||||
|
vars["eval"] = std::to_string(aint(deref(opr1)) c aint(deref(opr2))); \
|
||||||
|
}
|
||||||
|
#define CASELCHAR(c){ \
|
||||||
|
case (char)(*#c):\
|
||||||
|
aint(deref(opr1)) c aint(deref(opr2)) ? (vars["eval"] = true_) : (vars["eval"] = false_); \
|
||||||
|
}
|
||||||
|
//is_cmp = (oper == EMPTY_CELL);
|
||||||
|
vars["eval"] = "";
|
||||||
|
switch(oper){
|
||||||
|
case EMPTY_CELL:
|
||||||
|
vars["eval"] = deref(opr1);
|
||||||
|
return;
|
||||||
|
case '.':
|
||||||
|
vars["eval"] = deref(opr1) + deref(opr2);
|
||||||
|
return;
|
||||||
|
case '\'':
|
||||||
|
vars["eval"] = deref(opr1).substr(0, opr1.size()-aint(deref(opr2)));
|
||||||
|
return;
|
||||||
|
CASECHAR(-)
|
||||||
|
return;
|
||||||
|
CASECHAR(+)
|
||||||
|
return;
|
||||||
|
CASECHAR(/)
|
||||||
|
return;
|
||||||
|
CASECHAR(*)
|
||||||
|
return;
|
||||||
|
CASECHAR(%)
|
||||||
|
return;
|
||||||
|
CASELCHAR(<)
|
||||||
|
return;
|
||||||
|
CASELCHAR(>)
|
||||||
|
return;
|
||||||
|
case '=':
|
||||||
|
aint(deref(opr1)) == aint(deref(opr2)) ? (vars["eval"] = true_) : (vars["eval"] = false_); \
|
||||||
|
return;
|
||||||
|
CASELCHAR(|)
|
||||||
|
return;
|
||||||
|
CASELCHAR(&)
|
||||||
|
return;
|
||||||
|
CASELCHAR(^)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//int aint(std::string s){
|
||||||
|
// static const char c[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; // ?!
|
||||||
|
// bool sign = true;
|
||||||
|
// int roof = 1;
|
||||||
|
//
|
||||||
|
// for(int i = 0, int end = s.size(); i < end; i++){
|
||||||
|
// int h = 0;
|
||||||
|
// for(int e = sizeof(c)-1; h < e; h++){
|
||||||
|
// if(c[h] == s[i]){
|
||||||
|
// while(pow(2, roof) < h){
|
||||||
|
// ++roof;
|
||||||
|
// }
|
||||||
|
// goto CONT;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// switch(s[i]){
|
||||||
|
// case '-':
|
||||||
|
// sign = !(sign xor false);
|
||||||
|
// s.rease(i, 1);
|
||||||
|
// --i;
|
||||||
|
// continue;
|
||||||
|
// case '+':
|
||||||
|
// sign = !(sign xor true);
|
||||||
|
// s.rease(i, 1);
|
||||||
|
// --i;
|
||||||
|
// continue;
|
||||||
|
// default:
|
||||||
|
// s[i] = '0';
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
// CONT:
|
||||||
|
// }
|
||||||
|
//}
|
76
src/algo.h
Normal file
76
src/algo.h
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
#include <math.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <string>
|
||||||
|
#include <stack>
|
||||||
|
#include <unordered_map>
|
||||||
|
#ifdef DEBUG
|
||||||
|
# include "debug.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace algo{
|
||||||
|
/* CONST */
|
||||||
|
enum{
|
||||||
|
// LINE,
|
||||||
|
JUMP,
|
||||||
|
DESTINATION,
|
||||||
|
ASSIGNMENT,
|
||||||
|
OPR1,
|
||||||
|
OPERATOR,
|
||||||
|
OPR2,
|
||||||
|
COMMENT
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class jmp{
|
||||||
|
nop,
|
||||||
|
jmp,
|
||||||
|
je,
|
||||||
|
jne
|
||||||
|
};
|
||||||
|
|
||||||
|
const char EMPTY_CELL = '0';
|
||||||
|
|
||||||
|
const char true_[] = "TRUE";
|
||||||
|
const char false_[] = "FALSE";
|
||||||
|
|
||||||
|
struct frame{
|
||||||
|
unsigned bp;
|
||||||
|
};
|
||||||
|
|
||||||
|
const char* const standard_vars[] = {
|
||||||
|
"eval",
|
||||||
|
"ret",
|
||||||
|
"argv-0",
|
||||||
|
"argv-1",
|
||||||
|
"argv-2",
|
||||||
|
"argv-3",
|
||||||
|
"argv-4",
|
||||||
|
"argv-5",
|
||||||
|
"argv-6",
|
||||||
|
"argv-7",
|
||||||
|
"argv-8",
|
||||||
|
"argv-9",
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
/**/
|
||||||
|
|
||||||
|
/* VARS */
|
||||||
|
extern std::stack<struct frame> callstack;
|
||||||
|
extern std::unordered_map<std::string, std::string> vars;
|
||||||
|
/**/
|
||||||
|
|
||||||
|
bool init();
|
||||||
|
|
||||||
|
std::string arref(std::string s);
|
||||||
|
std::string deref(std::string s);
|
||||||
|
int aint(std::string s);
|
||||||
|
|
||||||
|
void assign(const std::string &name, const std::string& val);
|
||||||
|
|
||||||
|
void do_eval(const std::string &opr1, char oper, const std::string &opr2);
|
||||||
|
|
||||||
|
void pop(unsigned &head);
|
||||||
|
void push(const unsigned &head);
|
||||||
|
|
||||||
|
bool jump(unsigned &head, const jmp &do_jump, const std::string &dest, const char &push);
|
||||||
|
void call(unsigned &head, const std::string &dest, const bool &is_push);
|
||||||
|
}
|
23
src/debug.h
Normal file
23
src/debug.h
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#define DEBUG_COLOR
|
||||||
|
|
||||||
|
#ifdef DEBUG_COLOR
|
||||||
|
# define NORMAL "\033[0m"
|
||||||
|
# define BOLD "\033[1m"
|
||||||
|
# define RED "\033[31m"
|
||||||
|
# define GREEN "\033[32m"
|
||||||
|
# define YELLOW "\033[33m"
|
||||||
|
# define BLUE "\033[34m"
|
||||||
|
# define MAGENTA "\033[35m"
|
||||||
|
# define CYAN "\033[36m"
|
||||||
|
# define WHITE "\033[37m"
|
||||||
|
#else
|
||||||
|
# define NORMAL ""
|
||||||
|
# define BOLD ""
|
||||||
|
# define RED ""
|
||||||
|
# define GREEN ""
|
||||||
|
# define YELLOW ""
|
||||||
|
# define BLUE ""
|
||||||
|
# define MAGENTA ""
|
||||||
|
# define CYAN ""
|
||||||
|
# define WHITE ""
|
||||||
|
#endif
|
87
src/lexer.cpp
Normal file
87
src/lexer.cpp
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
#include "lexer.h"
|
||||||
|
|
||||||
|
#include "rapidcsv.h"
|
||||||
|
#include "algo.h"
|
||||||
|
|
||||||
|
|
||||||
|
inline unsigned long long instruction_counter = 1;
|
||||||
|
|
||||||
|
void lex_file(const char* const f){
|
||||||
|
rapidcsv::Document doc(f, rapidcsv::LabelParams(-1, -1),
|
||||||
|
rapidcsv::SeparatorParams(';')
|
||||||
|
);
|
||||||
|
std::vector<std::string> buf;
|
||||||
|
|
||||||
|
for(unsigned head = 1, end = doc.GetRowCount()+1; head < end; head++){
|
||||||
|
#ifdef DEBUG
|
||||||
|
printf(BOLD BLUE "%0#6llx" NORMAL "|", instruction_counter++);
|
||||||
|
printf(BOLD "%s:%d: " NORMAL, f, head);
|
||||||
|
#endif
|
||||||
|
const std::string c = doc.GetCell<std::string>(0, head-1);
|
||||||
|
if(c[0] == '"'){ // skip comments
|
||||||
|
#ifdef DEBUG
|
||||||
|
printf(GREEN "Comment: %s\n" NORMAL, c.c_str());
|
||||||
|
#endif
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
buf = doc.GetRow<std::string>(head-1);
|
||||||
|
lex_row(buf, head);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void lex_row(std::vector<std::string> &v, unsigned &head){
|
||||||
|
/* --- MUST COMPUTE --- */
|
||||||
|
algo::do_eval(v[algo::OPR1], v[algo::OPERATOR][0], v[algo::OPR2]);
|
||||||
|
/* --- */
|
||||||
|
|
||||||
|
/* --- INSTRUCTION BREANCHING --- */
|
||||||
|
/* Is jump*/
|
||||||
|
if(v[algo::JUMP][0] != algo::EMPTY_CELL){
|
||||||
|
algo::jmp j;
|
||||||
|
try{
|
||||||
|
j = (algo::jmp)(stoi(v[algo::JUMP]));
|
||||||
|
}catch(...){
|
||||||
|
puts(RED "Non sensical jump condition." NORMAL);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#ifdef DEBUG
|
||||||
|
printf(MAGENTA "Jump condition %s (%s) %s %s (%s) with %d. " NORMAL,
|
||||||
|
v[algo::OPR1].c_str(),
|
||||||
|
algo::deref(v[algo::OPR1]).c_str(),
|
||||||
|
v[algo::OPERATOR].c_str(),
|
||||||
|
algo::deref(v[algo::OPR2]).c_str(),
|
||||||
|
v[algo::OPR2].c_str(),
|
||||||
|
(int)j
|
||||||
|
);
|
||||||
|
#endif
|
||||||
|
if(algo::jump(head, j, v[algo::DESTINATION], v[algo::ASSIGNMENT][0])){
|
||||||
|
--head;
|
||||||
|
#ifdef DEBUG
|
||||||
|
puts(MAGENTA "Continueing." NORMAL);
|
||||||
|
#endif
|
||||||
|
}else{
|
||||||
|
#ifdef DEBUG
|
||||||
|
puts(MAGENTA "Falling through." NORMAL);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
/* Is assignemt */
|
||||||
|
if(v[algo::ASSIGNMENT][0] != algo::EMPTY_CELL){
|
||||||
|
algo::assign(algo::arref(v[algo::DESTINATION]), algo::vars["eval"]);
|
||||||
|
#ifdef DEBUG
|
||||||
|
printf(CYAN "Assigned '%s' to '%s' (%s). (%s %s %s %c %s)\n" NORMAL,
|
||||||
|
algo::vars["eval"].c_str(),
|
||||||
|
v[algo::DESTINATION].c_str(),
|
||||||
|
algo::arref(v[algo::DESTINATION]).c_str(),
|
||||||
|
//
|
||||||
|
v[algo::DESTINATION].c_str(),
|
||||||
|
v[algo::ASSIGNMENT].c_str(),
|
||||||
|
v[algo::OPR1].c_str(),
|
||||||
|
v[algo::OPERATOR][0],
|
||||||
|
v[algo::OPR2].c_str());
|
||||||
|
#endif
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
/* --- */
|
||||||
|
}
|
8
src/lexer.h
Normal file
8
src/lexer.h
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
void lex_file(const char* const f);
|
||||||
|
void lex_row(std::vector<std::string> &v, unsigned &head);
|
||||||
|
|
||||||
|
extern unsigned long long instruction_counter;
|
68
src/main.cpp
Normal file
68
src/main.cpp
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
#include <string.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include <algorithm>
|
||||||
|
//#include "JokerTao.h"
|
||||||
|
#include <unordered_map>
|
||||||
|
//
|
||||||
|
#include "algo.h"
|
||||||
|
#include "lexer.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
char* f;
|
||||||
|
|
||||||
|
[[ noreturn ]] void end(int ignore = 0){
|
||||||
|
#ifdef DEBUG
|
||||||
|
printf(NORMAL);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
printf(GREEN "\" Standard variables\n" NORMAL);
|
||||||
|
const char *const *c = algo::standard_vars-1;
|
||||||
|
while((c++, *c != NULL)){
|
||||||
|
printf("%s: %s\n", *c, algo::vars[*c].c_str());
|
||||||
|
algo::vars.erase(*c);
|
||||||
|
}
|
||||||
|
|
||||||
|
printf(GREEN "\" User variables\n" NORMAL);
|
||||||
|
vector<char*> vpbuf;
|
||||||
|
for(auto &&i : algo::vars){
|
||||||
|
char *a;
|
||||||
|
asprintf(&a, "%s: %s\n", i.first.c_str(), i.second.c_str());
|
||||||
|
vpbuf.push_back(a);
|
||||||
|
}
|
||||||
|
std::sort(vpbuf.begin(), vpbuf.end(), [](char* a, char* b){ return (strcmp(a, b) < 1); });
|
||||||
|
for(auto &&i : vpbuf){
|
||||||
|
cout << i;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
exit(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool init(){
|
||||||
|
ios::sync_with_stdio(true);
|
||||||
|
setvbuf(stdout, NULL, _IONBF, 0);
|
||||||
|
setvbuf(stderr, NULL, _IONBF, 0);
|
||||||
|
signal(SIGINT, end);
|
||||||
|
|
||||||
|
printf("[init] ");
|
||||||
|
algo::init();
|
||||||
|
puts("");
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
signed main(int argc, char* argv[]){
|
||||||
|
if(argc < 2){ return 0; }
|
||||||
|
|
||||||
|
init();
|
||||||
|
|
||||||
|
f = argv[1];
|
||||||
|
lex_file(f);
|
||||||
|
|
||||||
|
end();
|
||||||
|
}
|
1821
src/rapidcsv.h
Normal file
1821
src/rapidcsv.h
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user