working variables
This commit is contained in:
parent
838148dc8e
commit
9dd65d10b3
|
@ -0,0 +1 @@
|
|||
./a.out
|
|
@ -25,9 +25,9 @@ namespace builtin {
|
|||
|
||||
std::any a_exit(lexi l, state* s){
|
||||
int ex;
|
||||
if(l.args[0].type==NONE)
|
||||
ex = std::get<int>(s->names[l.args[0].ident].value);
|
||||
else
|
||||
//if(l.args[0].type==NONE)
|
||||
// ex = std::get<int>(s->names[l.args[0].ident].value);
|
||||
//else
|
||||
ex = std::get<int>(l.args[0].value);
|
||||
exit(ex);
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ namespace builtin {
|
|||
return 0;
|
||||
}
|
||||
std::any _def(lexi l,state *s){
|
||||
s->set(l.args[0].ident,l.args[1]);
|
||||
s->names[l.args[0].ident] =l.args[1];
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +1,29 @@
|
|||
#include "parser.hh"
|
||||
#define __builtins_hh
|
||||
|
||||
|
||||
#include <typeinfo>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <typeindex>
|
||||
#include <any>
|
||||
#include <functional>
|
||||
#include "stdarg.h"
|
||||
#include "interp.hh"
|
||||
#include "state.hh"
|
||||
|
||||
#ifndef __builtins_cc
|
||||
#define __builtins_cc
|
||||
namespace builtin{
|
||||
class builtin;
|
||||
}
|
||||
#ifndef __interp_hh
|
||||
#include "interp.hh"
|
||||
#endif
|
||||
|
||||
#ifndef __state_hh
|
||||
#include "state.hh"
|
||||
#endif
|
||||
|
||||
//#ifndef __builtins_hh
|
||||
//#define __builtins_hh
|
||||
|
||||
namespace builtin {
|
||||
|
||||
class builtin {
|
||||
public:
|
||||
std::string call = "";
|
||||
|
@ -51,4 +62,4 @@ static std::map<std::string, builtin::builtin*> builtins = {
|
|||
|
||||
void ttest(lexi);
|
||||
|
||||
#endif
|
||||
//#endif
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "files.hh"
|
||||
#include "pretty.hh"
|
||||
|
||||
std::string f_read(std::string path){
|
||||
std::stringstream r;
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include "pretty.hh"
|
||||
|
||||
#ifndef __files_hh
|
||||
#define __files_hh
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
#include "interp.hh"
|
||||
#include "pretty.hh"
|
||||
#include "builtins.hh"
|
||||
#include "state.hh"
|
||||
|
||||
void interp(std::vector<lexi> inp, state* s){
|
||||
//std::cout<<batch_format(inp, 0);
|
||||
|
@ -12,7 +9,7 @@ void interp(std::vector<lexi> inp, state* s){
|
|||
p_ferr("undefined refrence to "+l.oper+" on line:"+std::to_string(l.line)+":"+std::to_string(l._char),1);
|
||||
if(!builtins[l.oper]->check_args(l,s))
|
||||
p_ferr("incorrect usage on "+l.oper,1);
|
||||
builtins[l.oper]->exec(l,s);
|
||||
builtins[l.oper]->exec(s->gen_args(builtins[l.oper]->args,l),s);
|
||||
//std::cout<<s->names[l.args[0].ident].ident;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,19 @@
|
|||
#define __interp_hh
|
||||
#include "parser.hh"
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include "state.hh"
|
||||
|
||||
#ifndef __interp_cc
|
||||
#define __interp_cc
|
||||
void interp(std::vector<lexi>, state*);
|
||||
#ifndef __pretty_hh
|
||||
#include "pretty.hh"
|
||||
#endif
|
||||
|
||||
#ifndef __builtins_hh
|
||||
#include "builtins.hh"
|
||||
#endif
|
||||
|
||||
#ifndef __state_hh
|
||||
#include "state.hh"
|
||||
#endif
|
||||
|
||||
void interp(std::vector<lexi>, state*);
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include "parser.hh"
|
||||
|
||||
|
||||
|
||||
void object::clear(){
|
||||
ident="";
|
||||
value = NULL;
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
#define __parser_hh
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <algorithm>
|
||||
#include <variant>
|
||||
#include <any>
|
||||
#include "state.hh"
|
||||
#ifndef __parser_cc
|
||||
#define __parser_cc
|
||||
//#include "state.hh"
|
||||
|
||||
|
||||
#define INDENT_ITER 5
|
||||
|
||||
enum symbols {
|
||||
enum s_symbols {
|
||||
P_OPENING = '(',
|
||||
P_CLOSING = ')',
|
||||
};
|
||||
|
@ -42,15 +42,14 @@ class lexi {
|
|||
std::string oper;
|
||||
std::vector<object> args;
|
||||
std::string format(int);
|
||||
|
||||
lexi gen_args(state*);
|
||||
|
||||
void clear();
|
||||
};
|
||||
|
||||
static std::map<type, std::any> typemap = {
|
||||
{NONE,NULL}, {INT,(int)1}, {DOUBLE,(double)5.5}, {CHAR,(char)'5'},
|
||||
{STRING,(std::string)"a"},{STATEMENT,new lexi}};
|
||||
//static std::map<type, std::any> typemap = {
|
||||
// {NONE,NULL}, {INT,(int)1}, {DOUBLE,(double)5.5}, {CHAR,(char)'5'},
|
||||
// {STRING,(std::string)"a"},{STATEMENT,new lexi}};
|
||||
|
||||
std::string batch_format(std::vector<lexi>, int);
|
||||
std::vector<lexi> test(std::string);
|
||||
#endif
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#include <string>
|
||||
|
||||
#ifndef __pretty_cc
|
||||
#define __pretty_cc
|
||||
#define __pretty_hh
|
||||
|
||||
#define color_black "\e[30m"
|
||||
#define color_red "\e[31m"
|
||||
|
@ -33,4 +32,4 @@ void _p_err(std::string, int, std::string);
|
|||
#define p_ferr(X,Y) _p_ferr(X, Y, __LINE__, __FILE__);
|
||||
void _p_ferr(std::string, int, int, std::string);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
#include "state.hh"
|
||||
|
||||
lexi state::gen_args(std::vector<type> b, lexi i){
|
||||
if(b[0]==ANY) return i;
|
||||
for(int x = 0; x!=i.args.size();x++){
|
||||
if(i.args[x].type==NONE){
|
||||
if(!names.count(i.args[x].ident)) p_ferr("undefined refrence to "+i.args[x].ident,1);
|
||||
i.args[x] = names[i.args[x].ident];
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
void tttest(){
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
#define __state_hh
|
||||
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
|
||||
class state;
|
||||
void tttest();
|
||||
|
||||
#ifndef __builtins_hh
|
||||
#include "builtins.hh"
|
||||
#endif
|
||||
|
||||
#ifndef __parser_hh
|
||||
#include "parser.hh"
|
||||
#endif
|
||||
|
||||
class state {
|
||||
public:
|
||||
std::map<std::string, object> names;
|
||||
|
||||
lexi gen_args(std::vector<type>, lexi);
|
||||
};
|
||||
|
||||
|
|
@ -1,11 +1,7 @@
|
|||
#include <iostream>
|
||||
#include "parser.hh"
|
||||
#include "files.hh"
|
||||
#include "pretty.hh"
|
||||
#include "interp.hh"
|
||||
#include "builtins.hh"
|
||||
#include <string>
|
||||
#include "state.hh"
|
||||
|
||||
#include "test.hh"
|
||||
|
||||
int main(int argc, char* argv[]){
|
||||
//std::cout<<batch_format(test("(exit 5 22)(meow \"wharrrr\" (a 5 (aaa 5.5) ) 445)"),0);
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
#include "files.hh"
|
||||
#include "pretty.hh"
|
||||
|
||||
|
||||
#ifndef __interp_hh
|
||||
#include "interp.hh"
|
||||
#endif
|
||||
|
||||
#ifndef __parser_hh
|
||||
#include "parser.hh"
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef __state_hh
|
||||
#include "state.hh"
|
||||
#endif
|
||||
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
(def meow 5)
|
||||
(exit meow)
|
|
@ -1,3 +1,3 @@
|
|||
(what)
|
||||
(write "hi uwu")
|
||||
(def a "meowwwww")
|
||||
(write a)
|
||||
(exit 12)
|
||||
|
|
Loading…
Reference in New Issue