#include #include #include "ast.h" using namespace std; ParseError::ParseError(const string &what_arg) :runtime_error(what_arg){} ParseError::ParseError(const char *what_arg) :runtime_error(what_arg){} Lambda::Lambda(){} Lambda::Lambda(const Name &arg,const AST &ast) :arg(arg),body(ast){} AST::AST() :type(Type::tuple){} AST AST::makeNumber(Number numval){ AST ast; ast.type=AST::Type::number; ast.numval=numval; return ast; } AST AST::makeString(String strval){ AST ast; ast.type=AST::Type::string; ast.strval=strval; return ast; } AST AST::makeName(Name nameval){ AST ast; ast.type=AST::Type::name; ast.nameval=nameval; return ast; } AST AST::makeIndex(Index indexval){ AST ast; ast.type=AST::Type::index; ast.indexval=indexval; return ast; } AST AST::makeTuple(Terms terms){ AST ast; ast.type=AST::Type::tuple; ast.terms=terms; return ast; } AST AST::makeLambda(Lambda lambdaval){ AST ast; ast.type=AST::Type::lambda; ast.lambdaval=lambdaval; return ast; } AST AST::makeLambda(const Name &arg,const AST &body){ AST ast; ast.type=AST::Type::lambda; ast.lambdaval.arg=arg; ast.lambdaval.body=body; return ast; } AST AST::makeNative(const Native &native){ AST ast; ast.type=AST::Type::native; ast.nativeval=native; return ast; } bool iswordchar(char c){ return isalpha(c)||isdigit(c)||strchr("!$%&*+,-./:;<=>?@^_|~",c)!=nullptr; } class AST::Tokeniser{ const string source; const i64 size; i64 index=0,nextat=0; public: Tokeniser(const string &source) :source(source),size(source.size()){ // cerr<<"Tokeniser: initialised with <<"<>"<>"<>"<>"<1&&token[0]=='-'&&isdigit(token[1]))){ // cerr<<"AST::parse: type = number"<=32&&c<=126){ os<