Пример #1
0
        private void AnalysePrimaryExpression(PrimaryExpression expression, string type)
        {
            if (expression is IdentifierPE)
            {
                IdentifierPE identifierPe = (IdentifierPE)expression;
                variableExists(identifierPe);
                CheckType(type, identifierPe);
                return;
            }

            if (expression is BracketsPE)
            {
                BracketsPE bracketsPe = (BracketsPE)expression;
                AnalysePrimaryExpression(bracketsPe.GetExpression.getP1, type);
                AnalysePrimaryExpression(bracketsPe.GetExpression.getP2, type);
                AnalyzeOperator(bracketsPe.GetExpression.GetOperator(), type);
                return;
            }

            if (expression is ConditionPE)
            {
                ConditionPE conditionPe = (ConditionPE)expression;
                variableExists(conditionPe);
                if (type != "boolean")
                {
                    logCError(expression, "Boolean illegal in: " + type + "");
                }
            }
        }
Пример #2
0
        private PrimaryExpression parsePrimary()
        {
            PrimaryExpression PE;

            if (CurrentToken == null)
            {
                return(null);
            }
            switch (CurrentToken.getType())
            {
//                case _condition:
            case _identifier:
                var Id = parseIdentifier();
                PE = new IdentifierPE(prevLine, Id);
                break;

            case _lPar:
                nextToken();
                PE = new BracketsPE(prevLine, parseExpression());
                accept(_rPar);
                break;

            case _condition:
                var C = parseCondition();
                PE = new ConditionPE(prevLine, C);
                break;

            case _literalString:
                var S = parseLiteral();
                PE = new LiteralString(prevLine, S);
                break;

            case _literalInt:
                var I = parseLiteral();
                PE = new LiteralString(prevLine, I);
                break;

            default:
                logError(CurrentToken, "Syntax Error in Primary");
                PE = null;
                break;
            }
            return(PE);
        }