Beispiel #1
0
 private static Expression ParseAddExpression(Scanner scanner)
 {
     Expression left = ParseMultiplyExpression(scanner);
     while (true)
     {
         if (scanner.TryGetDelimiter("+"))
         {
             Expression right = ParseMultiplyExpression(scanner);
             left = new AddExpression(left,right);
         }
         else if (scanner.TryGetDelimiter("-"))
         {
             Expression right = ParseMultiplyExpression(scanner);
             left = new SubtractExpression(left,right);
         }
         else
         {
             return left;
         }
     }
 }
Beispiel #2
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;
     }
 }