Ejemplo n.º 1
0
        private static void showExpressions(List <AbstractExpression> expressions)
        {
            foreach (var expression in expressions)
            {
                if (expression is AssignmentExpression)
                {
                    Console.WriteLine($"type: {expression.type}");
                    AssignmentExpression assignmentExpression = (AssignmentExpression)expression;
                    Console.WriteLine("left: ");
                    if (assignmentExpression.identifier != null)
                    {
                        if (assignmentExpression.identifier != null)
                        {
                            Console.WriteLine($"\tidentifier: {assignmentExpression.identifier}");
                        }
                        else if (assignmentExpression.propertiesExpression != null)
                        {
                            Console.WriteLine($"\ttype - {assignmentExpression.propertiesExpression.type}");
                            Console.WriteLine($"\tkeyWord: {assignmentExpression.propertiesExpression.keyWord}");
                            Console.WriteLine($"\tidentifier: {assignmentExpression.propertiesExpression.identifier}");
                        }
                    }

                    Console.WriteLine("right: ");
                    Expression right = assignmentExpression.Right;
                    showExpression(right);
                }
                else if (expression is InitializationExpression)
                {
                    showInitialization(expression);
                }
                else if (expression is DeclarationExpression)
                {
                    DeclarationExpression declarationExpression = (DeclarationExpression)expression;
                    Console.WriteLine($"type - {declarationExpression.type}");
                    Console.WriteLine("left");
                    showInitialization(declarationExpression.initializationExpression, "\t");

                    Console.WriteLine("right: ");
                    showExpression(declarationExpression.expression);
                }
                else if (expression is OperationExpression)
                {
                    OperationExpression operationExpression = (OperationExpression)expression;
                    Console.WriteLine($"type - {operationExpression.type}");
                    Console.WriteLine($"identifier - {operationExpression.identifier}");
                    Console.WriteLine($"method name - {operationExpression.methodName}");


                    Console.WriteLine("attributes");
                    foreach (var attr in operationExpression.attributes)
                    {
                        Console.WriteLine($"\tattribute: {attr}");
                    }
                }
                Console.WriteLine();
            }
        }
Ejemplo n.º 2
0
 private void AnalyzeOpExpr(OperationExpression expr)
 {
     if (!InitializationVariables.ContainsKey(expr.identifier))
     {
         throw new Exception($"{expr.identifier} isn't initialized");
     }
     if (!checkPropForMethod(expr.methodName, InitializationVariables[expr.identifier]))
     {
         throw new Exception($"Method ${expr.methodName} isn't available for {InitializationVariables[expr.identifier]} data type");
     }
     checkMethodAttrs(expr.methodName, expr.attributes);
 }
        private AbstractExpression parseOperation(List <Token> currentTokens)
        {
            OperationExpression expression = new OperationExpression();

            if (currentTokens[0].Type != TokenType.Identifier)
            {
                throw new Exception($"Line {currentTokens[0].Line}: Need an identifier for calling method");
            }
            expression.identifier = currentTokens[0].Value;
            if (currentTokens[2].Type != TokenType.Operand)
            {
                throw new Exception($"Line {currentTokens[2].Line}: Incorrect type of method");
            }
            expression.methodName = currentTokens[2].Value;

            int startIndex = -1;
            int lastIndex  = -1;

            for (int i = 0; i < currentTokens.Count; i++)
            {
                if (currentTokens[i].Value == "(")
                {
                    startIndex = i;
                }
                if (currentTokens[i].Value == ")")
                {
                    lastIndex = i;
                }
            }

            if (startIndex != -1 && lastIndex == -1)
            {
                throw new Exception($"Line {currentTokens[0].Line}: Need a pair of '('");
            }


            expression.attributes = parseAttributes(currentTokens.GetRange(startIndex + 1, lastIndex - startIndex));

            expression.Line = currentTokens[0].Line;
            return(expression);
        }
Ejemplo n.º 4
0
 private void TranslateOpExpr(OperationExpression expression)
 {
     Data.CallMethod(expression.identifier, expression.methodName, expression.attributes);
 }