Beispiel #1
0
        public static List <Token> getFactor(object item)
        {
            List <Token> tokens = new List <Token>();

            try
            {
                Factor factor = (Factor)item;
                try
                {
                    tokens.Add((Token)factor.getTokensList()[0]);
                }
                catch
                {
                    VaribleStatment varibleStatment = (VaribleStatment)factor.getTokensList()[0];
                    tokens.AddRange(addFactor(varibleStatment));
                }
            }
            catch
            {
                try
                {
                    MathOperator mathOperator = (MathOperator)item;
                    tokens.Add((Token)mathOperator.getTokensList()[0]);
                }
                catch
                {
                    RelationalOperator relationalOperator = (RelationalOperator)item;
                    tokens.Add((Token)relationalOperator.getTokensList()[0]);
                }
            }
            return(tokens);
        }
        public MathExpression(TokensList tokensList)
        {
            children.Add(new Factor(tokensList));

            while (true)
            {
                Boolean      isOperator   = false;
                MathOperator mathOperator = new MathOperator(tokensList, ref isOperator);
                if (mathOperator.getTokensList().Count > 0)
                {
                    children.Add(mathOperator);
                }
                if (isOperator)
                {
                    children.Add(new Factor(tokensList));
                }
                else
                {
                    break;
                }
            }
            if (children.Count > 3)
            {
                Token token = tokensList.SeeToken();
                throw new System.Exception("Line " + token.lineNo.ToString() + " too long math expression ");
            }
        }
Beispiel #3
0
        public MathExpression(TokensList tokensList)
        {
            children.Add(new Factor(tokensList));

            while (true)
            {
                Boolean      isOperator   = false;
                MathOperator mathOperator = new MathOperator(tokensList, ref isOperator);
                if (mathOperator.getTokensList().Count > 0)
                {
                    children.Add(mathOperator);
                }
                if (isOperator)
                {
                    children.Add(new Factor(tokensList));
                }
                else
                {
                    break;
                }
            }
        }
Beispiel #4
0
 static public string visit(MathOperator mathOperator)
 {
     return(Constants.MATH_OPERATOR);
 }