From a538f3c16d6feba6c9d1fbcadedde0ceaf99c8d5 Mon Sep 17 00:00:00 2001 From: otya128 Date: Wed, 3 Jun 2015 21:21:30 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=91=E3=83=BC=E3=82=B5=E3=83=BC=E3=81=AE?= =?UTF-8?q?=E5=8D=98=E4=BD=93=E3=83=86=E3=82=B9=E3=83=88=E3=81=AE=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SMILEBASIC/parser.d | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/SMILEBASIC/parser.d b/SMILEBASIC/parser.d index 7763e2a..cf4c00a 100644 --- a/SMILEBASIC/parser.d +++ b/SMILEBASIC/parser.d @@ -251,6 +251,41 @@ void Test(const char[] V)() } unittest { + struct Eval + { + wstring val; + this(wstring val) + { + this.val = val; + } + bool opAssign(int result) + { + auto parser = new Parser(val); + try + { + assert(parser.calc() == result); + } + catch(Exception e) + { + assert(false, e.toString()); + } + return false; + } + } + Test!"2+(3+4)*5"(); Test!"2+20/5*3"(); Test!"2-3*4-5"(); + test("1+1", 2);//1+1は2 + test("2*3+2", 8);//2*3+2は8 + test("2*3+2+1", 9);//2*3+2+1は9 + Eval("2+3*4+2") = 2+3*4+2; + Eval("2+3*4*5+6*7+8") = 2+3*4*5+6*7+8; + Eval("2+3*4*5") = 2+3*4*5; + Eval("(2+3)*4*5") = (2+3)*4*5; + Eval("(1)+(2)") = (1)+(2); + Test!"2+(3+4)*5"(); + Test!"2+20/5*3"(); + //Eval("test(2+5)") = 2+5; + //Eval("test(2+5, test(2, 3+5))") = 3+5; + Test!"2-3*4-5"(); }