Exemplo n.º 1
0
 private static Expression ParseAssigmentExpression(Scanner scanner)
 {
     Expression left = ParseLogicalOrExpression(scanner);
     if (scanner.TryGetDelimiter("="))
     {
         Expression right = ParseAssigmentExpression(scanner);
         return new AssignmentExpression(left,right);
     }
     else if (scanner.TryGetDelimiter("+="))
     {
         Expression right = ParseAssigmentExpression(scanner);
         right = new AddExpression(left,right);
         return new AssignmentExpression(left,right);
     }
     else if (scanner.TryGetDelimiter("-="))
     {
         Expression right = ParseAssigmentExpression(scanner);
         right = new SubtractExpression(left,right);
         return new AssignmentExpression(left,right);
     }
     else if (scanner.TryGetDelimiter("*="))
     {
         Expression right = ParseAssigmentExpression(scanner);
         right = new MultiplyExpression(left,right);
         return new AssignmentExpression(left,right);
     }
     else if (scanner.TryGetDelimiter("/="))
     {
         Expression right = ParseAssigmentExpression(scanner);
         right = new DivideExpression(left,right);
         return new AssignmentExpression(left,right);
     }
     else if (scanner.TryGetDelimiter("%="))
     {
         Expression right = ParseAssigmentExpression(scanner);
         right = new ModuloExpression(left,right);
         return new AssignmentExpression(left,right);
     }
     else if (scanner.TryGetDelimiter("<<="))
     {
         Expression right = ParseAssigmentExpression(scanner);
         right = new LeftShiftExpression(left,right);
         return new AssignmentExpression(left,right);
     }
     else if (scanner.TryGetDelimiter(">>="))
     {
         Expression right = ParseAssigmentExpression(scanner);
         right = new RightShiftExpression(left,right);
         return new AssignmentExpression(left,right);
     }
     else if (scanner.TryGetDelimiter("&="))
     {
         Expression right = ParseAssigmentExpression(scanner);
         right = new BitwiseAndExpression(left,right);
         return new AssignmentExpression(left,right);
     }
     else if (scanner.TryGetDelimiter("^="))
     {
         Expression right = ParseAssigmentExpression(scanner);
         right = new BitwiseXorExpression(left,right);
         return new AssignmentExpression(left,right);
     }
     else if (scanner.TryGetDelimiter("|="))
     {
         Expression right = ParseAssigmentExpression(scanner);
         right = new BitwiseOrExpression(left,right);
         return new AssignmentExpression(left,right);
     }
     else if (scanner.TryGetDelimiter("&&="))
     {
         Expression right = ParseAssigmentExpression(scanner);
         right = new LogicalAndExpression(left,right);
         return new AssignmentExpression(left,right);
     }
     else if (scanner.TryGetDelimiter("^^="))
     {
         Expression right = ParseAssigmentExpression(scanner);
         right = new LogicalXorExpression(left,right);
         return new AssignmentExpression(left,right);
     }
     else if (scanner.TryGetDelimiter("||="))
     {
         Expression right = ParseAssigmentExpression(scanner);
         right = new LogicalOrExpression(left,right);
         return new AssignmentExpression(left,right);
     }
     else
     {
         return left;
     }
 }
Exemplo n.º 2
0
 private static Expression ParseMultiplyExpression(Scanner scanner)
 {
     Expression left = ParsePrefixExpression(scanner);
     while (true)
     {
         if (scanner.TryGetDelimiter("*"))
         {
             Expression right = ParsePrefixExpression(scanner);
             left = new MultiplyExpression(left,right);
         }
         else if (scanner.TryGetDelimiter("/"))
         {
             Expression right = ParsePrefixExpression(scanner);
             left = new DivideExpression(left,right);
         }
         else if (scanner.TryGetDelimiter("%"))
         {
             Expression right = ParsePrefixExpression(scanner);
             left = new ModuloExpression(left,right);
         }
         else
         {
             return left;
         }
     }
 }
Exemplo n.º 3
0
        private static Expression ParseAssigmentExpression(Scanner scanner)
        {
            Expression left = ParseLogicalOrExpression(scanner);

            if (scanner.TryGetDelimiter("="))
            {
                Expression right = ParseAssigmentExpression(scanner);
                return(new AssignmentExpression(left, right));
            }
            else if (scanner.TryGetDelimiter("+="))
            {
                Expression right = ParseAssigmentExpression(scanner);
                right = new AddExpression(left, right);
                return(new AssignmentExpression(left, right));
            }
            else if (scanner.TryGetDelimiter("-="))
            {
                Expression right = ParseAssigmentExpression(scanner);
                right = new SubtractExpression(left, right);
                return(new AssignmentExpression(left, right));
            }
            else if (scanner.TryGetDelimiter("*="))
            {
                Expression right = ParseAssigmentExpression(scanner);
                right = new MultiplyExpression(left, right);
                return(new AssignmentExpression(left, right));
            }
            else if (scanner.TryGetDelimiter("/="))
            {
                Expression right = ParseAssigmentExpression(scanner);
                right = new DivideExpression(left, right);
                return(new AssignmentExpression(left, right));
            }
            else if (scanner.TryGetDelimiter("%="))
            {
                Expression right = ParseAssigmentExpression(scanner);
                right = new ModuloExpression(left, right);
                return(new AssignmentExpression(left, right));
            }
            else if (scanner.TryGetDelimiter("<<="))
            {
                Expression right = ParseAssigmentExpression(scanner);
                right = new LeftShiftExpression(left, right);
                return(new AssignmentExpression(left, right));
            }
            else if (scanner.TryGetDelimiter(">>="))
            {
                Expression right = ParseAssigmentExpression(scanner);
                right = new RightShiftExpression(left, right);
                return(new AssignmentExpression(left, right));
            }
            else if (scanner.TryGetDelimiter("&="))
            {
                Expression right = ParseAssigmentExpression(scanner);
                right = new BitwiseAndExpression(left, right);
                return(new AssignmentExpression(left, right));
            }
            else if (scanner.TryGetDelimiter("^="))
            {
                Expression right = ParseAssigmentExpression(scanner);
                right = new BitwiseXorExpression(left, right);
                return(new AssignmentExpression(left, right));
            }
            else if (scanner.TryGetDelimiter("|="))
            {
                Expression right = ParseAssigmentExpression(scanner);
                right = new BitwiseOrExpression(left, right);
                return(new AssignmentExpression(left, right));
            }
            else if (scanner.TryGetDelimiter("&&="))
            {
                Expression right = ParseAssigmentExpression(scanner);
                right = new LogicalAndExpression(left, right);
                return(new AssignmentExpression(left, right));
            }
            else if (scanner.TryGetDelimiter("^^="))
            {
                Expression right = ParseAssigmentExpression(scanner);
                right = new LogicalXorExpression(left, right);
                return(new AssignmentExpression(left, right));
            }
            else if (scanner.TryGetDelimiter("||="))
            {
                Expression right = ParseAssigmentExpression(scanner);
                right = new LogicalOrExpression(left, right);
                return(new AssignmentExpression(left, right));
            }
            else
            {
                return(left);
            }
        }