diff --git a/SMILEBASIC/node.d b/SMILEBASIC/node.d index 30df341..cd3874f 100644 --- a/SMILEBASIC/node.d +++ b/SMILEBASIC/node.d @@ -35,6 +35,7 @@ enum NodeType ArrayAssign, DefineFunction, While, + Inc, } abstract class Node { @@ -420,3 +421,13 @@ class While : Statement this.statements = statements; } } +class Inc : Statement +{ + wstring name; + Expression expression; + this(wstring name, Expression expr) + { + this.name = name; + this.expression = expr; + } +} diff --git a/SMILEBASIC/parser.d b/SMILEBASIC/parser.d index c48a4cc..47e3673 100644 --- a/SMILEBASIC/parser.d +++ b/SMILEBASIC/parser.d @@ -62,6 +62,8 @@ class Lexical reserved["OUT"] = TokenType.Out; reserved["WHILE"] = TokenType.While; reserved["WEND"] = TokenType.WEnd; + reserved["INC"] = TokenType.Inc; + reserved["DEC"] = TokenType.Dec; reserved.rehash(); line = 1; } @@ -756,6 +758,9 @@ class Parser case TokenType.While: node = whileStatement(); break; + case TokenType.Inc: + case TokenType.Dec: + return incStatement(); default: syntaxError(); break; @@ -763,6 +768,42 @@ class Parser lex.popFront(); return node; } + Inc incStatement() + { + auto token = lex.front(); + bool dec = token.type == TokenType.Dec; + lex.popFront(); + token = lex.front(); + if(token.type != TokenType.Iden) + { + syntaxError(); + return null; + } + wstring var = token.value.stringValue; + //TODO:Array + lex.popFront(); + token = lex.front(); + Expression expr; + if(token.type == TokenType.Comma) + { + lex.popFront(); + expr = expression(); + if(!expr) + { + syntaxError(); + return null; + } + } + else + { + expr = new Constant(Value(1)); + } + if(dec) + { + expr = new BinaryOperator(new Constant(Value(0)), TokenType.Minus, expr); + } + return new Inc(var, expr); + } IndexExpressions indexExpressions() { IndexExpressions ie = new IndexExpressions(); diff --git a/SMILEBASIC/petitcomputer.d b/SMILEBASIC/petitcomputer.d index b7c3c6e..4b27afe 100644 --- a/SMILEBASIC/petitcomputer.d +++ b/SMILEBASIC/petitcomputer.d @@ -356,7 +356,7 @@ NEXT DEF FACT(N) IF N<=1 THEN RETURN 1 RETURN N*FACT(N-1) -END"*//* +END"*/ `CLS : CL=0 : Z=0 WHILE 1 INC Z : IF Z>200 THEN Z=0 @@ -365,7 +365,7 @@ WHILE 1 PRINT "★ 梅雨で雨が多い季節ですね ★" NEXT CL=(CL+1) MOD 16 : VSYNC 2 -WEND`*/ +WEND`/* `CLS : CL=0 WHILE 1 FOR I=0 TO 15 @@ -373,7 +373,7 @@ FOR I=0 TO 15 PRINT "Ё プチコン3ゴウ Ж" NEXT CL=(CL+1) MOD 16 : VSYNC 1 -WEND` +WEND`*/ /* `CLS : CL=0 @LOOP diff --git a/SMILEBASIC/token.d b/SMILEBASIC/token.d index db743f1..9cd38eb 100644 --- a/SMILEBASIC/token.d +++ b/SMILEBASIC/token.d @@ -56,6 +56,8 @@ enum TokenType Out, While, WEnd, + Inc, + Dec, } struct Token