Exemplo n.º 1
0
        /// <summary>Parses an input line containing an intermediate expression term .</summary>
        private InpErrorCodes ParseTerm(string[] tok)
        {
            string s = "";

            // --- get term's name

            if (tok.Length < 2)
            {
                return(0);
            }
            int i = _project.MSXproj_findObject(ObjectTypes.TERM, tok[0]);

            // --- reconstruct the expression string from its tokens

            for (int j = 1; j < tok.Length; j++)
            {
                s += tok[j];
            }

            // --- convert expression into a postfix stack of op codes

            //expr = mathexpr_create(s, getVariableCode);
            MathExpr expr = MathExpr.Create(s, GetVariableCode);

            if (expr == null)
            {
                return(InpErrorCodes.ERR_MATH_EXPR);
            }

            // --- assign the expression to a Term object

            _msx.Term[i].Expr = expr;
            return(0);
        }
Exemplo n.º 2
0
        /// <summary>Parses an input line containing a math expression.</summary>
        private InpErrorCodes ParseExpression(ObjectTypes classType, string[] tok)
        {
            string s = "";

            // --- determine expression type

            if (tok.Length < 3)
            {
                return(InpErrorCodes.ERR_ITEMS);
            }
            int k = Utilities.MSXutils_findmatch(tok[0], Constants.ExprTypeWords);

            if (k < 0)
            {
                return(InpErrorCodes.ERR_KEYWORD);
            }

            // --- determine species associated with expression

            int i = _project.MSXproj_findObject(ObjectTypes.SPECIES, tok[1]);

            if (i < 1)
            {
                return(InpErrorCodes.ERR_NAME);
            }

            // --- check that species does not already have an expression

            if (classType == ObjectTypes.LINK)
            {
                if (_msx.Species[i].PipeExprType != ExpressionType.NO_EXPR)
                {
                    return(InpErrorCodes.ERR_DUP_EXPR);
                }
            }

            if (classType == ObjectTypes.TANK)
            {
                if (_msx.Species[i].TankExprType != ExpressionType.NO_EXPR)
                {
                    return(InpErrorCodes.ERR_DUP_EXPR);
                }
            }

            // --- reconstruct the expression string from its tokens

            for (int j = 2; j < tok.Length; j++)
            {
                s += tok[j];
            }

            // --- convert expression into a postfix stack of op codes

            //expr = mathexpr_create(s, getVariableCode);
            MathExpr expr = MathExpr.Create(s, GetVariableCode);

            if (expr == null)
            {
                return(InpErrorCodes.ERR_MATH_EXPR);
            }

            // --- assign the expression to the species

            switch (classType)
            {
            case ObjectTypes.LINK:
                _msx.Species[i].PipeExpr     = expr;
                _msx.Species[i].PipeExprType = (ExpressionType)k;
                break;

            case ObjectTypes.TANK:
                _msx.Species[i].TankExpr     = expr;
                _msx.Species[i].TankExprType = (ExpressionType)k;
                break;
            }
            return(0);
        }