Example #1
0
 State SawUntil(Token t)
 {
     if (t.type == TokenType.Expression) {
         var exp = mExpParser.Parse(t.data);
         if (exp == null) { return null; }
         exp = new UnaryOperationExpression(UnaryOperation.Complement, exp);
         mBlock.Push(new WhileBlock(exp, mScratchpad));
         return Idle;
     }
     return null;
 }
Example #2
0
 bool ParseTokenSlice(List<Token> tokens, int start, int len, out Expression result)
 {
     result = null;
     if (len == 0) {
         return false;
     }
     if (len == 1) {
         switch(tokens[start].type) {
             case TokenType.SubExpression: return ParseSubExpression(tokens[start].expr, out result);
             case TokenType.Element: return ParseElement(tokens[start].expr, out result);
             default: return false;
         }
     }
     int opIndex;
     if (FindHighestPriorityOperator(tokens, start, len, out opIndex)) {
         if (opIndex == start) {
             Expression right;
             if (!ParseTokenSlice(tokens, start+1, len-1, out right)) { return false; }
             result = new UnaryOperationExpression(mUnaryOpTable[mOps[tokens[opIndex].opId]], right);
             return true;
         } else {
             Expression left, right;
             if (!ParseTokenSlice(tokens, start, opIndex-start, out left)) { return false; }
             if (!ParseTokenSlice(tokens, opIndex+1, start + len - opIndex - 1, out right)) { return false; }
             result = new BinaryOperationExpression(mBinaryOpTable[mOps[tokens[opIndex].opId]], left, right);
             return true;
         }
     } else {
         return false;
     }
 }
Example #3
0
 State ExpectingBackwardMove(Token t)
 {
     if (t.type == TokenType.Expression) {
         var exp = mExpParser.Parse(t.data);
         if (exp == null) { return null; }
         exp = new UnaryOperationExpression(UnaryOperation.Negate, exp);
         mScratchpad.Add(new ActionInstruction(moveAction, exp));
         return Idle;
     }
     return null;
 }