/// <summary>Reads a literal or sub-expression</summary> /// <param name="pos">Position of literal or first token of sub-expression</param> /// <returns>Expression tree</returns> /// <exception cref="Logic::AlgorithmException">Attempted to read incorrect type of Token</exception> /// <exception cref="Logic::ExpressionParserException">Syntax error</exception> /// <remarks>Advances the iterator to beyond the end of the literal or sub-expression</remarks> ExpressionParser::ExpressionTree ExpressionParser::ReadValue(TokenIterator& pos) { ExpressionTree expr = nullptr; // Rule: Value = Literal / '(' Expression ')' // Match: Literal if (MatchLiteral(pos)) return ExpressionTree( new LiteralValue(ReadLiteral(pos)) ); // Read: Bracket [nothrow] if (!MatchOperator(pos, L"(")) { // Failed: Unexpected EOF if (pos >= InputEnd) throw ExpressionParserException(HERE, --pos, L"Missing operand"); // Failed: Unexpected token throw ExpressionParserException(HERE, pos, VString(L"Unexpected '%s'", pos->Text.c_str())); } // Read: Expression (may throw) const ScriptToken& open = ReadOperator(pos); expr = ReadExpression(pos); // Adv. then match // Read: Bracket [nothrow] if (MatchOperator(pos, L")")) return ExpressionTree( new BracketedExpression(open, expr, ReadOperator(pos)) ); // Failure: Missing closing bracket if (pos >= InputEnd) throw ExpressionParserException(HERE, --pos, L"Missing closing bracket"); else throw ExpressionParserException(HERE, pos, L"Expected closing bracket"); }
/// <summary>Reads a binary expression, unary expression, sub-expression, or literal</summary> /// <param name="pos">Position of first token of expression</param> /// <returns>Expression tree</returns> /// <exception cref="Logic::AlgorithmException">Attempted to read incorrect type of Token</exception> /// <exception cref="Logic::ExpressionParserException">Syntax error</exception> /// <remarks>Advances the iterator to beyond the end of the expression</remarks> ExpressionParser::ExpressionTree ExpressionParser::ReadBinaryExpression(TokenIterator& pos, UINT precedence) { ExpressionTree expr = nullptr; // Rule: Expr = LogicalExpr // Rule: LogicalExpr = BitwiseExpr (AND/OR BitwiseExpr)* // Rule: BitwiseExpr = Comparison (&/|/^ Comparison)* // Rule: Comparison = SumExpr (==/!=/<=/>=/</> SumExpr)* // Rule: SumExpr = ProductExpr (+/- ProductExpr)* // Rule: ProductExpr = UnaryExpr (*/div UnaryExpr)* // Rule: UnaryExpr = (!/-/~)? Value // Rule: Value = literal / '(' expr ')' // Read: BinaryExpr := higher-precedence-expr (input-precedence-operator higher-precedence-expr)* expr = (precedence < MAX_PRECEDENCE ? ReadBinaryExpression(pos, precedence+1) : ReadUnaryExpression(pos)); // throws // Match: operator while (MatchOperator(pos, precedence)) { // Read: operator auto op = ReadOperator(pos); // Read: higher-precedence-expr / Value auto rhs = (precedence < MAX_PRECEDENCE ? ReadBinaryExpression(pos, precedence+1) : ReadUnaryExpression(pos)); // throws expr = ExpressionTree(new BinaryExpression(op, expr, rhs)); // throws } // Success: return expr; }
int CIFStaticFortuna::ReadData(QSettings& set) { ReadDev(set); ReadCompany(set); ReadOperator(set); ReadNetwork(set); ReadFtp(set); ReadLotbox(set); ReadPrize(set); ReadNotein(set); ReadNoteout(set); ReadCoiner(set); ReadTimer(set); ReadUps(set); ReadRedeembox(set); return 1; }
/// <summary>Reads a unary expression, sub-expression, or literal</summary> /// <param name="pos">Position of first token of expression</param> /// <returns>Expression tree</returns> /// <exception cref="Logic::AlgorithmException">Attempted to read incorrect type of Token</exception> /// <exception cref="Logic::ExpressionParserException">Syntax error</exception> /// <remarks>Advances the iterator to beyond the end of the expression</remarks> ExpressionParser::ExpressionTree ExpressionParser::ReadUnaryExpression(TokenIterator& pos) { // Rule: Unary = (! / - / ~)? Value // Match: Operator if (MatchOperator(pos, MAX_PRECEDENCE)) { // Read: operator (may throw) const ScriptToken& op = ReadOperator(pos); // Manually convert binary-substract to unary-minus ScriptToken unary = (op.Text != L"-" ? op : ScriptToken(TokenType::UnaryOp, op.Start, op.End, op.Text)); // Read: Value (may throw) return ExpressionTree(new UnaryExpression(unary, ReadValue(pos))); } // Read: Value (may throw) return ReadValue(pos); }
void Keys(unsigned char key, int x, int y) { if (stat.turnedON) { switch (key) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': ReadCharacter(key); break; case '.': if (stat.decimalOperation == 0) { if (stat.currentOperand == 0) { stat.operandLength++; if (stat.operandLength > 10) { return; } operand1Str[opr1Index++] = '.'; stat.decimalOperation = 1; } else if (stat.currentOperand == 1) { stat.operandLength++; if (stat.operandLength > 10) { return; } operand2Str[opr2Index++] = '.'; stat.decimalOperation = 1; } totalExp[expIndex++] = '.'; } else if (stat.decimalOperation == 1) return; break; case '+': ReadOperator('+'); break; case '-': ReadOperator('-'); break; case '*': ReadOperator('*'); break; case '/': ReadOperator('/'); break; case '=': case 13: //ASCII value of return key CalculateResult(); break; case 27: //ASCII value of Escape key ClearEverything(); break; default: printf("Invalid Character Chosen\n"); return; break; } glutPostRedisplay(); } else return; }
void Mouse(int btn, int state, int x, int y) { if (stat.turnedON) { if (btn == GLUT_LEFT_BUTTON && (x > 15 && x<70) && (y>455 && y<505) && state == GLUT_DOWN) { ReadCharacter('0'); glutPostRedisplay(); } else if (btn == GLUT_LEFT_BUTTON && (x>90 && x<145) && (y>455 && y<505) && state == GLUT_DOWN) { if (stat.decimalOperation == 0) { if (stat.currentOperand == 0) { stat.operandLength++; if (stat.operandLength > 10) { return; } operand1Str[opr1Index++] = '.'; stat.decimalOperation = 1; } else if (stat.currentOperand == 1) { stat.operandLength++; if (stat.operandLength > 10) { return; } operand2Str[opr2Index++] = '.'; stat.decimalOperation = 1; } totalExp[expIndex++] = '.'; } else if (stat.decimalOperation == 1) return; glutPostRedisplay(); } else if (btn == GLUT_LEFT_BUTTON && (x > 15 && x<70) && (y>380 && y<430) && state == GLUT_DOWN) { ReadCharacter('1'); glutPostRedisplay(); } else if (btn == GLUT_LEFT_BUTTON && (x>90 && x<145) && (y>380 && y<430) && state == GLUT_DOWN) { ReadCharacter('2'); glutPostRedisplay(); } else if (btn == GLUT_LEFT_BUTTON && (x>165 && x<220) && (y>380 && y<430) && state == GLUT_DOWN) { ReadCharacter('3'); glutPostRedisplay(); } else if (btn == GLUT_LEFT_BUTTON && (x>15 && x<70) && (y>305 && y<355) && state == GLUT_DOWN) { ReadCharacter('4'); glutPostRedisplay(); } else if (btn == GLUT_LEFT_BUTTON && (x>90 && x<145) && (y>305 && y<355) && state == GLUT_DOWN) { ReadCharacter('5'); glutPostRedisplay(); } else if (btn == GLUT_LEFT_BUTTON && (x>165 && x<220) && (y>305 && y<355) && state == GLUT_DOWN) { ReadCharacter('6'); glutPostRedisplay(); } else if (btn == GLUT_LEFT_BUTTON && (x>15 && x<70) && (y>230 && y<280) && state == GLUT_DOWN) { ReadCharacter('7'); glutPostRedisplay(); } else if (btn == GLUT_LEFT_BUTTON && (x>90 && x<145) && (y>230 && y<280) && state == GLUT_DOWN) { ReadCharacter('8'); glutPostRedisplay(); } else if (btn == GLUT_LEFT_BUTTON && (x>165 && x<220) && (y>230 && y<280) && state == GLUT_DOWN) { ReadCharacter('9'); glutPostRedisplay(); } else if (btn == GLUT_LEFT_BUTTON && (x>240 && x<295) && (y>455 && y<505) && state == GLUT_DOWN) { ReadOperator('+'); glutPostRedisplay(); } else if (btn == GLUT_LEFT_BUTTON && (x>240 && x<295) && (y>380 && y<430) && state == GLUT_DOWN) { ReadOperator('-'); glutPostRedisplay(); } else if (btn == GLUT_LEFT_BUTTON && (x>240 && x<295) && (y>305 && y<355) && state == GLUT_DOWN) { ReadOperator('*'); glutPostRedisplay(); } else if (btn == GLUT_LEFT_BUTTON && (x>240 && x<295) && (y>230 && y<280) && state == GLUT_DOWN) { ReadOperator('/'); glutPostRedisplay(); } else if (btn == GLUT_LEFT_BUTTON && (x > 165 && x<295) && (y>155 && y<205) && state == GLUT_DOWN) { //AC is clicked ClearEverything(); glutPostRedisplay(); } else if (btn == GLUT_LEFT_BUTTON && (x>165 && x<220) && (y>455 && y < 505) && state == GLUT_DOWN) { // = is clicked CalculateResult(); glutPostRedisplay(); } else if (btn == GLUT_LEFT_BUTTON && (x>90 && x<145) && (y>155 && y<205) && state == GLUT_DOWN) { exit(0); } } else if (btn == GLUT_LEFT_BUTTON && (x>15 && x<70) && (y>155 && y<205) && state == GLUT_DOWN) { stat.turnedON = 1; glutPostRedisplay(); } }