SCPP
A simple scripting language in C++
|
Go to the documentation of this file.
63 SInt::SInt(
int value) : value(value)
73 SNot::SNot(
struct Expr expr) : expr(expr)
109 SBin::SBin(
struct Expr left,
struct Expr right,
enum Op op) : left(left), right(right), op(op)
116 list<struct Expr> exprs;
117 SSeq(list<struct Expr> exprs);
119 SSeq::SSeq(list<struct Expr> exprs) : exprs(exprs)
130 SAssign::SAssign(
string name,
struct Expr value) : name(name), value(value)
139 SIdent::SIdent(
string name) : name(name)
146 struct Expr condition;
147 struct Expr thenClause;
148 struct Expr elseClause;
149 SIf(
struct Expr condition,
struct Expr thenClause,
struct Expr elseClause);
151 SIf::SIf(
struct Expr condition,
struct Expr thenClause,
struct Expr elseClause) : condition(condition), thenClause(thenClause), elseClause(elseClause)
158 struct Expr condition;
162 SWhile::SWhile(
struct Expr condition,
struct Expr body) : condition(condition), body(body)
170 struct Expr condition;
175 SFor::SFor(
struct Expr init,
struct Expr condition,
struct Expr update,
struct Expr body) : init(init), condition(condition), update(update), body(body)
186 list<struct SFunction> functions;
187 list<struct Expr> bodies;
188 SProgram(list<struct SFunction> functions, list<struct Expr> bodies);
190 SProgram::SProgram(list<struct SFunction> functions, list<struct Expr> bodies) : functions(functions), bodies(bodies)
205 SFunction::SFunction(
string name, list<string> args,
struct Expr body) : name(name), args(args), body(body)
212 list<struct Expr> args;
213 SCall(
string name, list<struct Expr> args);
215 SCall::SCall(
string name, list<struct Expr> args) : name(name), args(args)
229 expr.type = ExprType::Int;
230 expr.u.i =
new SInt(value);
243 result.type = ExprType::Not;
244 result.u.n =
new SNot(expr);
258 expr.type = ExprType::Bin;
259 expr.u.b =
new SBin(left, right, Op::Add);
273 expr.type = ExprType::Bin;
274 expr.u.b =
new SBin(left, right, Op::Sub);
288 expr.type = ExprType::Bin;
289 expr.u.b =
new SBin(left, right, Op::Mul);
305 expr.type = ExprType::Bin;
306 expr.u.b =
new SBin(left, right, Op::Div);
320 expr.type = ExprType::Bin;
321 expr.u.b =
new SBin(left, right, Op::Mod);
337 expr.type = ExprType::Bin;
338 expr.u.b =
new SBin(left, right, Op::And);
354 expr.type = ExprType::Bin;
355 expr.u.b =
new SBin(left, right, Op::Or);
371 expr.type = ExprType::Bin;
372 expr.u.b =
new SBin(left, right, Op::Nor);
388 expr.type = ExprType::Bin;
389 expr.u.b =
new SBin(left, right, Op::Nand);
405 expr.type = ExprType::Bin;
406 expr.u.b =
new SBin(left, right, Op::Xor);
421 expr.type = ExprType::Bin;
422 expr.u.b =
new SBin(left, right, Op::Lt);
437 expr.type = ExprType::Bin;
438 expr.u.b =
new SBin(left, right, Op::Leq);
453 expr.type = ExprType::Bin;
454 expr.u.b =
new SBin(left, right, Op::Gt);
469 expr.type = ExprType::Bin;
470 expr.u.b =
new SBin(left, right, Op::Geq);
485 expr.type = ExprType::Bin;
486 expr.u.b =
new SBin(left, right, Op::Eq);
501 expr.type = ExprType::Bin;
502 expr.u.b =
new SBin(left, right, Op::Neq);
513 template <
class... Args>
516 list<struct Expr> exprs;
517 for (
struct Expr expr : std::initializer_list<struct Expr>{args...})
519 exprs.push_back(expr);
522 expr.type = ExprType::Seq;
523 expr.u.s =
new SSeq(exprs);
539 expr.type = ExprType::Assign;
540 expr.u.a =
new SAssign(name, value);
554 expr.type = ExprType::Ident;
555 expr.u.id =
new SIdent(name);
571 expr.type = ExprType::If;
572 expr.u.if_ =
new SIf(condition, thenClause, elseClause);
587 expr.type = ExprType::While;
588 expr.u.w =
new SWhile(condition, body);
605 expr.type = ExprType::For;
606 expr.u.f =
new SFor(init, condition, update, body);
621 template <
class... Args>
624 list<struct Expr> exprs;
625 for (
struct Expr expr : std::initializer_list<struct Expr>{bodies...})
627 exprs.push_back(expr);
640 template <
class... Args>
643 list<struct SFunction> funcList;
644 for (
struct SFunction func : std::initializer_list<struct SFunction>{functions...})
646 funcList.push_back(func);
659 template <
class... Args>
673 template <
class... Args>
676 list<string> argList;
677 for (
string arg : std::initializer_list<string>{args...})
679 argList.push_back(arg);
692 template <
class... Args>
695 list<struct Expr> exprs;
696 for (
struct Expr expr : std::initializer_list<struct Expr>{args...})
698 exprs.push_back(expr);
701 expr.type = ExprType::Call;
702 expr.u.c =
new SCall(name, exprs);
struct Expr tFor(struct Expr init, struct Expr condition, struct Expr update, struct Expr body)
for式を作成する
Definition: scpp_ast.hpp:602
struct Expr tAssign(string name, struct Expr value)
変数代入式を作成する
Definition: scpp_ast.hpp:536
struct SFunction tFunction(string name, list< string > args, Args... bodies)
関数定義を作成する
Definition: scpp_ast.hpp:660
プログラムを表す構造体
Definition: scpp_ast.hpp:184
Definition: scpp_ast.hpp:102
ExprType
式の種別を表す列挙体
Definition: scpp_ast.hpp:20
list< string > ParamList(Args... args)
引数のリストを作成する
Definition: scpp_ast.hpp:674
struct Expr tCall(string name, Args... args)
関数呼び出し式を作成する
Definition: scpp_ast.hpp:693
struct Expr tEq(struct Expr left, struct Expr right)
比較演算(等しい)の式を作成する
Definition: scpp_ast.hpp:482
Definition: scpp_ast.hpp:58
struct Expr tNor(struct Expr left, struct Expr right)
論理NORの式を作成する
Definition: scpp_ast.hpp:368
Definition: scpp_ast.hpp:144
関数を表す構造体
Definition: scpp_ast.hpp:198
struct Expr tXor(struct Expr left, struct Expr right)
論理XORの式を作成する
Definition: scpp_ast.hpp:402
list< struct SFunction > FunctionList(Args... functions)
関数リストを作成する
Definition: scpp_ast.hpp:641
struct SProgram tProgram(list< struct SFunction > functions, Args... bodies)
一つのプログラムを表す構造体を作成する
Definition: scpp_ast.hpp:622
struct Expr tOr(struct Expr left, struct Expr right)
論理ORの式を作成する
Definition: scpp_ast.hpp:351
struct Expr tNeq(struct Expr left, struct Expr right)
比較演算(等しくない)の式を作成する
Definition: scpp_ast.hpp:498
struct Expr tWhile(struct Expr condition, struct Expr body)
while式を作成する
Definition: scpp_ast.hpp:584
struct Expr tSeq(Args... args)
連接式を作成する
Definition: scpp_ast.hpp:514
struct Expr tLt(struct Expr left, struct Expr right)
比較演算(未満)の式を作成する
Definition: scpp_ast.hpp:418
Definition: scpp_ast.hpp:167
struct Expr tNot(struct Expr expr)
論理否定の式を作成する
Definition: scpp_ast.hpp:240
struct Expr tDiv(struct Expr left, struct Expr right)
除算の式を作成する
Definition: scpp_ast.hpp:302
struct Expr tInt(int value)
整数型の式を作成する
Definition: scpp_ast.hpp:226
struct Expr tGeq(struct Expr left, struct Expr right)
比較演算(以上)の式を作成する
Definition: scpp_ast.hpp:466
struct Expr tNand(struct Expr left, struct Expr right)
論理NANDの式を作成する
Definition: scpp_ast.hpp:385
struct Expr tLeq(struct Expr left, struct Expr right)
比較演算(以下)の式を作成する
Definition: scpp_ast.hpp:434
struct Expr tSub(struct Expr left, struct Expr right)
減算の式を作成する
Definition: scpp_ast.hpp:270
Definition: scpp_ast.hpp:68
struct Expr tIf(struct Expr condition, struct Expr thenClause, struct Expr elseClause=tInt(0))
if式を作成する
Definition: scpp_ast.hpp:568
struct Expr tGt(struct Expr left, struct Expr right)
比較演算(より大きい)の式を作成する
Definition: scpp_ast.hpp:450
Definition: scpp_ast.hpp:209
Op
二項演算の演算子を表す列挙体
Definition: scpp_ast.hpp:82
struct Expr tAdd(struct Expr left, struct Expr right)
加算の式を作成する
Definition: scpp_ast.hpp:255
Definition: scpp_ast.hpp:114
Definition: scpp_ast.hpp:156
struct Expr tMul(struct Expr left, struct Expr right)
乗算の式を作成する
Definition: scpp_ast.hpp:285
struct Expr tAnd(struct Expr left, struct Expr right)
論理ANDの式を作成する
Definition: scpp_ast.hpp:334
struct Expr tIdent(string name)
変数参照式を作成する
Definition: scpp_ast.hpp:551
Definition: scpp_ast.hpp:134
Definition: scpp_ast.hpp:124
式を表す構造体
Definition: scpp_ast.hpp:38
struct Expr tMod(struct Expr left, struct Expr right)
剰余の式を作成する
Definition: scpp_ast.hpp:317