/// <summary> /// /// </summary> /// <param name="calculator"></param> /// <param name="el"></param> /// <param name="option"></param> /// <returns></returns> public static CalculatorToken CreateCalculatorToken(Calculator calculator, XmlNode el, SaveOption option) { CalculatorToken token; CalculatorTokenType type = (CalculatorTokenType)int.Parse(el.Attributes["type"].Value); switch (type) { case CalculatorTokenType.BinaryOperator: token = new CalculatorTokenBinaryOperator(calculator, el, option); break; case CalculatorTokenType.Keyword: token = new CalculatorTokenKeyword(calculator, el, option); break; /*case CalculatorTokenType.UnaryOperator: token = new CalculatorTokenUnaryOperator(el, option); break;*/ case CalculatorTokenType.Value: token = new CalculatorTokenValue(calculator, el, option); break; case CalculatorTokenType.Function: token = new CalculatorTokenFunction(calculator, el, option); break; default: throw new InvalidOperationException("unknown CalculatorTokenType"); } return token; }
public Parser() { _mapBinaryOperator.Add("+", CalculatorTokenBinaryOperator.BinaryOperator.Plus); _mapBinaryOperator.Add("-", CalculatorTokenBinaryOperator.BinaryOperator.Minus); _mapBinaryOperator.Add("/", CalculatorTokenBinaryOperator.BinaryOperator.Divide); _mapBinaryOperator.Add("*", CalculatorTokenBinaryOperator.BinaryOperator.Multiply); _mapBinaryOperator.Add("==", CalculatorTokenBinaryOperator.BinaryOperator.Equal); _mapBinaryOperator.Add("!=", CalculatorTokenBinaryOperator.BinaryOperator.Different); _mapBinaryOperator.Add(">=", CalculatorTokenBinaryOperator.BinaryOperator.SupEqual); _mapBinaryOperator.Add("<=", CalculatorTokenBinaryOperator.BinaryOperator.InfEqual); _mapBinaryOperator.Add(">", CalculatorTokenBinaryOperator.BinaryOperator.Superior); _mapBinaryOperator.Add("<", CalculatorTokenBinaryOperator.BinaryOperator.Inferior); _mapBinaryOperator.Add("||", CalculatorTokenBinaryOperator.BinaryOperator.Or); _mapBinaryOperator.Add("&&", CalculatorTokenBinaryOperator.BinaryOperator.And); AddParserToken(new ParserTokenSequence(this), 1); AddParserToken(new ParserTokenDelimiter(this, "(", ")"), 2); AddParserToken(new ParserTokenBinaryOperator(this, "*"), 4); AddParserToken(new ParserTokenBinaryOperator(this, "/"), 4); AddParserToken(new ParserTokenBinaryOperator(this, "+"), 5); AddParserToken(new ParserTokenBinaryOperator(this, "-"), 5); AddParserToken(new ParserTokenBinaryOperator(this, "<="), 6); AddParserToken(new ParserTokenBinaryOperator(this, ">="), 6); AddParserToken(new ParserTokenBinaryOperator(this, "<"), 6); AddParserToken(new ParserTokenBinaryOperator(this, ">"), 6); AddParserToken(new ParserTokenBinaryOperator(this, "=="), 7); AddParserToken(new ParserTokenBinaryOperator(this, "!="), 7); //AddToken(new ParserTokenOperator(this, "^"), 8); AddParserToken(new ParserTokenBinaryOperator(this, "&&"), 9); AddParserToken(new ParserTokenBinaryOperator(this, "||"), 9); //AddToken(new ParserTokenKeyword(this, ""), 10); AddParserToken(new ParserTokenValue(this), 12); _calculator = new Calculator(this); }
/// <summary> /// /// </summary> /// <param name="calculator"></param> /// <param name="br"></param> /// <param name="option"></param> public CalculatorTokenValue(Calculator calculator, BinaryReader br, SaveOption option) : base(calculator) { Load(br, option); }
/// <summary> /// /// </summary> /// <param name="calculator"></param> /// <param name="el"></param> /// <param name="option"></param> public CalculatorTokenValue(Calculator calculator, XmlNode el, SaveOption option) : base(calculator) { Load(el, option); }
/// <summary> /// /// </summary> /// <param name="calculator"></param> /// <param name="value"></param> public CalculatorTokenValue(Calculator calculator, string value) : base(calculator) { _string = value; _type = 1; }
/// <summary> /// /// </summary> /// <param name="calculator"></param> /// <param name="value"></param> public CalculatorTokenValue(Calculator calculator, float value) : base(calculator) { _value = value; _type = 0; }
/// <summary> /// /// </summary> /// <param name="calculator"></param> protected CalculatorToken(Calculator calculator) { _calculator = calculator; }
/// <summary> /// /// </summary> /// <param name="calculator"></param> /// <param name="el"></param> /// <param name="option"></param> public CalculatorTokenBinaryOperator(Calculator calculator, XmlNode el, SaveOption option) : base(calculator) { Load(el, option); }
/// <summary> /// /// </summary> /// <param name="calculator"></param> /// <param name="operator_"></param> public CalculatorTokenBinaryOperator(Calculator calculator, BinaryOperator operator_) : base(calculator) { _operator = operator_; }
/// <summary> /// /// </summary> /// <param name="calculator"></param> /// <param name="br"></param> /// <param name="option"></param> /// <returns></returns> public static CalculatorToken CreateCalculatorToken(Calculator calculator, BinaryReader br, SaveOption option) { CalculatorToken token; CalculatorTokenType type = (CalculatorTokenType)br.ReadInt32(); switch (type) { case CalculatorTokenType.BinaryOperator: token = new CalculatorTokenBinaryOperator(calculator, br, option); break; case CalculatorTokenType.Keyword: token = new CalculatorTokenKeyword(calculator, br, option); break; /*case CalculatorTokenType.UnaryOperator: token = new CalculatorTokenUnaryOperator(el, option); break;*/ case CalculatorTokenType.Value: token = new CalculatorTokenValue(calculator, br, option); break; case CalculatorTokenType.Function: token = new CalculatorTokenFunction(calculator, br, option); break; default: throw new InvalidOperationException("unknown CalculatorTokenType"); } return token; }
/// <summary> /// /// </summary> /// <param name="calculator"></param> /// <param name="functionName"></param> /// <param name="args"></param> public CalculatorTokenFunction(Calculator calculator, string functionName, string[] args) : base(calculator) { _functionName = functionName; _args = args; }
/// <summary> /// /// </summary> /// <param name="keyword"></param> public CalculatorTokenKeyword(Calculator calculator, string keyword) : base(calculator) { _keyword = keyword; }