@@ -35,49 +35,61 @@ namespace TokenType
3535 Goto,
3636 GotoNoOrigin,
3737 Origin,
38- NewInstruction,
3938 End,
4039 ToggleExecution,
40+ StackSize,
41+ StackLeft,
42+ StackRight,
43+ CurrentStackPosition,
44+ CurrentSubStackPosition,
4145 Null
4246 };
4347
44- static std::map<std::string, std::pair<std::string, Type>> TypeDataK = {
45- {" (" , {" OpenInstruction" , OpenInstruction}},
46- {" )" , {" CloseInstruction" , CloseInstruction}},
47- {" [" , {" OpenStackAccess" , OpenStackAccess}},
48- {" ]" , {" CloseStackAccess" , CloseStackAccess}},
49- {" ?" , {" Condition" , Condition}},
50- {" $" , {" StackAt" , StackAt}},
51- {" @" , {" CurrentStackValue" , CurrentStackValue}},
52- {" #" , {" Flag" , Flag}},
53- {" &" , {" Goto" , Goto}},
54- {" *" , {" GotoNoOrigin" , GotoNoOrigin}},
55- {" ~" , {" Origin" , Origin}},
56- {" ;" , {" NewInstruction" , NewInstruction}},
57- {" !" , {" ToggleExecution" , ToggleExecution}},
48+ static std::map<std::string, std::pair<std::string, Type>> TypeDataK = {
49+ {" (" , {" OpenInstruction" , OpenInstruction}},
50+ {" )" , {" CloseInstruction" , CloseInstruction}},
51+ {" [" , {" OpenStackAccess" , OpenStackAccess}},
52+ {" ]" , {" CloseStackAccess" , CloseStackAccess}},
53+ {" ?" , {" Condition" , Condition}},
54+ {" $" , {" StackAt" , StackAt}},
55+ {" @" , {" CurrentStackValue" , CurrentStackValue}},
56+ {" #" , {" Flag" , Flag}},
57+ {" &" , {" Goto" , Goto}},
58+ {" *" , {" GotoNoOrigin" , GotoNoOrigin}},
59+ {" ~" , {" Origin" , Origin}},
60+ {" !" , {" ToggleExecution" , ToggleExecution}},
61+ {" ^" , {" StackSize" , StackSize}},
62+ {" <" , {" StackLeft" , StackLeft}},
63+ {" >" , {" StackRight" , StackRight}},
64+ {" :" , {" CurrentStackPosition" , CurrentStackPosition}},
65+ {" ;" , {" CurrentSubStackPosition" , CurrentSubStackPosition}},
5866 {" %" , {" End" , End}}
5967 };
60- static std::map<Type, std::pair<std::string, std::string>> TypeDataR = {
61- {OpenInstruction, {" OpenInstruction" , " (" }},
62- {CloseInstruction, {" CloseInstruction" , " )" }},
63- {OpenStackAccess, {" OpenStackAccess" , " [" }},
64- {CloseStackAccess, {" CloseStackAccess" , " ]" }},
65- {Condition, {" Condition" , " ?" }},
66- {StackAt, {" StackAt" , " $" }},
67- {CurrentStackValue, {" CurrentStackValue" , " @" }},
68- {Flag, {" Flag" , " #" }},
69- {DynamicFlag, {" DynamicFlag" , " " }},
70- {Goto, {" Goto" , " &" }},
71- {GotoNoOrigin, {" GotoNoOrigin" , " *" }},
72- {Origin, {" Origin" , " ~" }},
73- {NewInstruction, {" NewInstruction" , " ;" }},
74- {End, {" End" , " %" }},
75- {ToggleExecution, {" ToggleExecution" , " !" }},
76- {Function, {" Function" , " " }},
77- {String, {" String" , " " }},
78- {Number, {" Number" , " " }},
79- {Instruction, {" Instruction" , " " }},
80- {StackAccess, {" StackAccess" , " " }},
68+ static std::map<Type, std::pair<std::string, std::string>> TypeDataR = {
69+ {OpenInstruction, {" OpenInstruction" , " (" }},
70+ {CloseInstruction, {" CloseInstruction" , " )" }},
71+ {OpenStackAccess, {" OpenStackAccess" , " [" }},
72+ {CloseStackAccess, {" CloseStackAccess" , " ]" }},
73+ {Condition, {" Condition" , " ?" }},
74+ {StackAt, {" StackAt" , " $" }},
75+ {CurrentStackValue, {" CurrentStackValue" , " @" }},
76+ {Flag, {" Flag" , " #" }},
77+ {DynamicFlag, {" DynamicFlag" , " " }},
78+ {Goto, {" Goto" , " &" }},
79+ {GotoNoOrigin, {" GotoNoOrigin" , " *" }},
80+ {Origin, {" Origin" , " ~" }},
81+ {End, {" End" , " %" }},
82+ {ToggleExecution, {" ToggleExecution" , " !" }},
83+ {Function, {" Function" , " " }},
84+ {String, {" String" , " " }},
85+ {Number, {" Number" , " " }},
86+ {Instruction, {" Instruction" , " " }},
87+ {StackAccess, {" StackAccess" , " " }},
88+ {StackSize, {" StackSize" , " ^" }},
89+ {StackLeft, {" StackLeft" , " <" }},
90+ {StackRight, {" StackRight" , " >" }},
91+ {CurrentStackPosition, {" CurrentStackPosition" , " :" }},
92+ {CurrentSubStackPosition, {" CurrentSubStackPosition" , " ;" }},
8193 {Null, {" Null" , " " }}
8294 };
8395 static std::vector<std::vector<Type>> TypeParameters = {
@@ -294,6 +306,32 @@ namespace StdLib
294306 }
295307 return storeInstruction;
296308 }
309+ Token f_read (const std::vector<Token> tokens) {
310+ Token filenameToken = tokens[0 ];
311+ std::string filename = filenameToken.getValue ();
312+ Token stackPlace = tokens[1 ];
313+ Token storeInstruction (TokenType::Instruction);
314+ Token accessMemory = Token (TokenType::StackAt);
315+ accessMemory.addParameter (stackPlace);
316+ Token zeroPos = Token (TokenType::Number, " 0" );
317+ Token accessSubMem = Token (TokenType::StackAt);
318+ accessSubMem.addParameter (zeroPos);
319+ storeInstruction.addParameter (accessMemory);
320+ storeInstruction.addParameter (accessSubMem);
321+ std::ifstream infile (filename);
322+ std::string line;
323+ while (std::getline (infile, line))
324+ {
325+ Token stackAcc (TokenType::StackAccess);
326+ stackAcc.addParameter (Token (TokenType::String, line));
327+ storeInstruction.addParameter (stackAcc);
328+ storeInstruction.addParameter (Token (TokenType::StackRight));
329+ }
330+ return storeInstruction;
331+ }
332+ Token f_write (const std::vector<Token> tokens) {
333+ return Token (TokenType::Null);
334+ }
297335 Token fBuild (std::string funcname, int amount, std::function<Token(const std::vector<Token>)> func, std::vector<Token> parameters) {
298336 if (amount != parameters.size ()) {
299337 std::cout << " [Error] Number of parameters not correct in function : " << funcname << std::endl;
@@ -308,26 +346,28 @@ namespace StdLib
308346 std::pair<std::function<Token (const std::vector<Token>)>, int > rpart = fRightPart (name, func, amount);
309347 return std::pair<std::string, std::pair<std::function<Token (const std::vector<Token>)>, int >>(name, rpart);
310348 }
311- static std::map<std::string, std::pair<std::function<Token(const std::vector<Token>)>, int >> FunctionsName = {
312- f (" add" , f_add, 2 ),
313- f (" sub" , f_sub, 2 ),
314- f (" mul" , f_mul, 2 ),
315- f (" div" , f_div, 2 ),
349+ static std::map<std::string, std::pair<std::function<Token(const std::vector<Token>)>, int >> FunctionsName = {
350+ f (" add" , f_add, 2 ),
351+ f (" sub" , f_sub, 2 ),
352+ f (" mul" , f_mul, 2 ),
353+ f (" div" , f_div, 2 ),
316354 f (" mod" , f_mod, 2 ),
317355 f (" not" , f_not, 1 ),
318- f (" eq" , f_eq, 2 ),
319- f (" neq" , f_neq, 2 ),
320- f (" gt" , f_gt, 2 ),
321- f (" ge" , f_ge, 2 ),
322- f (" lt" , f_lt, 2 ),
323- f (" le" , f_le, 2 ),
324- f (" print" , f_print, 1 ),
325- f (" input" , f_input, 1 ),
326- f (" string" , f_string, 1 ),
327- f (" int" , f_int, 1 ),
328- f (" random" , f_random, 0 ),
356+ f (" eq" , f_eq, 2 ),
357+ f (" neq" , f_neq, 2 ),
358+ f (" gt" , f_gt, 2 ),
359+ f (" ge" , f_ge, 2 ),
360+ f (" lt" , f_lt, 2 ),
361+ f (" le" , f_le, 2 ),
362+ f (" print" , f_print, 1 ),
363+ f (" input" , f_input, 1 ),
364+ f (" string" , f_string, 1 ),
365+ f (" int" , f_int, 1 ),
366+ f (" random" , f_random, 0 ),
329367 f (" time" , f_time, 0 ),
330368 f (" split" , f_split, 3 ),
369+ f (" read" , f_read, 2 ),
370+ f (" write" , f_write, 2 )
331371 };
332372
333373 static std::map<std::string, Token*> customFunctions = {};
@@ -398,6 +438,7 @@ class Program
398438 void setDepth (int depth);
399439 void setStackPosition (std::string pos);
400440 void setStackPosition (int pos);
441+ int getStackSize ();
401442 Token getStackAt ();
402443 void storeInStack (Token token);
403444 void stopExecution (TokenType::Type cause);
0 commit comments