Example #1
0
        private bool CheckType(string type, PrimaryExpression primaryExpression)
        {
            if (primaryExpression is IdentifierPE)
            {
                IdentifierPE identifierPe = (IdentifierPE)primaryExpression;
                if (!table.ContainsKey(identifierPe.getName()))
                {
                    return(false);
                }
                if (table[identifierPe.getName()] == type)
                {
                    return(true);
                }

                string[] msg = { "expected: " + type, "given: " + table[identifierPe.getName()] };
                logCError(primaryExpression, msg);
                return(false);
            }

            if (primaryExpression is ConditionPE)
            {
                if (_compilerUtils.Types[type] == _boolean)
                {
                    return(true);
                }
                string[] msg = { "expected: " + type, "given: " + _compilerUtils.Syntax[_boolean] };
                logCError(primaryExpression, msg);
                return(false);
            }

            if (primaryExpression is LiteralString)
            {
                if (_compilerUtils.Types[type] == _string)
                {
                    return(true);
                }
                string[] msg = { "expected: " + type, "given: " + _compilerUtils.Syntax[_string] };
                logCError(primaryExpression, msg);
                return(false);
            }

            if (primaryExpression is LiteralInt)
            {
                if (_compilerUtils.Types[type] == _integer)
                {
                    return(true);
                }
                string[] msg = { "expected: " + type, "given: " + _compilerUtils.Syntax[_integer] };
                logCError(primaryExpression, msg);
                return(false);
            }
            logCError(primaryExpression, "Unknown error in CheckType");
            return(false);
        }
Example #2
0
        private void AnalyzeCondition(ConditionExpression conditionExpression)
        {
            AST       ast1 = conditionExpression.AST1;
            AST       ast2 = conditionExpression.AST2;
            Condition c    = conditionExpression.C1;

            IdentifierPE identifierPe = (IdentifierPE)getFirstPrimaryExpression(ast1);

            if (!variableExists(identifierPe))
            {
                return;
            }
            string type = table[identifierPe.getName()];

            if (type == "boolean")
            {
                switch (c.Name)
                {
                case "<":
                case ">":
                case ">=":
                case "<=":
                    logCError(conditionExpression, "Incorrect condition statement: \"" + c.Name + "\" for: \"" + type + "\"");
                    return;
                }
            }
            AnalyzeIfAST(ast1, type);
            AnalyzeIfAST(ast2, type);
        }