Exemplo n.º 1
0
        public NonTerninalExp CreateCommand(List <Token> tokens)
        {
            var closeParenthesisIndex = TokenHelper.GetIndexPairParanthesis(tokens, 1);

            var exp     = TerminalExpressionAnalyser.Analyse(tokens.GetRange(2, closeParenthesisIndex - 2));
            var command = new ConditionCommand(exp);

            var closeBracketIndex = TokenHelper.GetIndexPairBracket(tokens, closeParenthesisIndex + 1);

            command.SetPositiveNext(SyntaxAnalyser.Analyse(tokens.GetRange(closeParenthesisIndex + 1,
                                                                           tokens.Count - closeParenthesisIndex - 1)));
            if (tokens[closeBracketIndex + 1].TokenType == TokenType.Else)
            {
                if (tokens[closeBracketIndex + 2].TokenType != TokenType.If)
                {
                    ConditionCommand com = new ConditionCommand(new StringConstExp("true"));
                    com.SetPositiveNext(SyntaxAnalyser.Analyse(tokens.GetRange(closeBracketIndex + 2,
                                                                               tokens.Count - closeBracketIndex - 2)));
                    com.SetNegativeNext(com.GetPositiveNext().GetNext());
                    command.SetNegativeNext(com);
                }
                else
                {
                    command.SetNegativeNext(SyntaxAnalyser.Analyse(tokens.GetRange(closeBracketIndex + 2,
                                                                                   tokens.Count - closeBracketIndex - 2)));
                }
            }
            else
            {
                command.SetNegativeNext(SyntaxAnalyser.Analyse(tokens.GetRange(closeBracketIndex + 1,
                                                                               tokens.Count - closeBracketIndex - 1)));
            }
            return(command);
        }
Exemplo n.º 2
0
        public NonTerninalExp CreateCommand(List <Token> tokens)
        {
            var closeParenthesisIndex = TokenHelper.GetIndexPairParanthesis(tokens, 1);

            var exp     = TerminalExpressionAnalyser.Analyse(tokens.GetRange(2, closeParenthesisIndex - 2));
            var command = new ConditionCommand(exp);

            var             closeBracketsIndex = TokenHelper.GetIndexPairBracket(tokens, closeParenthesisIndex + 1);
            BracketsCommand insideCom          = (BracketsCommand)SyntaxAnalyser.Analyse(tokens.GetRange(
                                                                                             closeParenthesisIndex + 1, tokens.Count - closeParenthesisIndex - 1));

            insideCom.SetNext(command);

            command.SetPositiveNext(insideCom);
            command.SetNegativeNext(SyntaxAnalyser.Analyse(tokens.GetRange(
                                                               closeBracketsIndex + 1, tokens.Count - closeBracketsIndex - 1)));

            return(command);
        }
Exemplo n.º 3
0
 public NonTerninalExp CreateCommand(List <Token> tokens)
 {
     if (tokens[1].TokenType == TokenType.If)
     {
         NonTerninalExp com = new ConditionCommandPattern().CreateCommand(tokens.GetRange(
                                                                              1, tokens.Count - 1));
         while (com is ConditionCommand)
         {
             com = ((ConditionCommand)com).GetNegativeNext();
         }
         return(com);
     }
     else
     {
         ConditionCommand com = new ConditionCommand(new StringConstExp("false"));
         com.SetPositiveNext(SyntaxAnalyser.Analyse(tokens.GetRange(1,
                                                                    tokens.Count - 1)));
         com.SetNegativeNext(com.GetPositiveNext().GetNext());
         return(com);
     }
 }