@@ -0,0 +1,2039 @@
+import java.util.Collections;%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0Aimport java.util.Stack;%0A%0Apublic class RegExConverter %7B%0A%0A%09/** Operators precedence map. */%0A%09private static final Map%3CCharacter, Integer%3E precedenceMap;%0A%09static %7B%0A%09%09Map%3CCharacter, Integer%3E map = new HashMap%3CCharacter, Integer%3E();%0A%09%09map.put('(', 1);%0A%09%09map.put('%7C', 2);%0A%09%09map.put('&', 3); // explicit concatenation operator%0A%09%09map.put('?', 4);%0A%09%09map.put('*', 4);%0A%09%09map.put('+', 4);%0A%09%09map.put('%5E', 5);%0A%09%09precedenceMap = Collections.unmodifiableMap(map);%0A%09%7D;%0A%0A%09/**%0A%09 * Get character precedence.%0A%09 * %0A%09 * @param c character%0A%09 * @return corresponding precedence%0A%09 */%0A%09private static Integer getPrecedence(Character c) %7B%0A%09%09Integer precedence = precedenceMap.get(c);%0A%09%09return precedence == null ? 6 : precedence;%0A%09%7D%0A%0A%09/**%0A%09 * Transform regular expression by inserting a '&' as explicit concatenation%0A%09 * operator.%0A%09 */%0A%09public static String formatRegEx(String regex) %7B%0A%09%09// TODO%0A%09%09return null;%0A%09%7D%0A%0A%09/**%0A%09 * Convert regular expression from infix to postfix notation using%0A%09 * Shunting-yard algorithm.%0A%09 * %0A%09 * @param regex infix notation%0A%09 * @return postfix notation%0A%09 */%0A%09public static String infixToPostfix(String regex) %7B%0A%09%09String postfix = new String();%0A%0A%09%09Stack%3CCharacter%3E stack = new Stack%3CCharacter%3E();%0A%0A%09%09String formattedRegEx = formatRegEx(regex);%0A%0A%09%09for (Character c : formattedRegEx.toCharArray()) %7B%0A%09%09%09switch (c) %7B%0A%09%09%09%09case '(':%0A%09%09%09%09%09stack.push(c);%0A%09%09%09%09%09break;%0A%0A%09%09%09%09case ')':%0A%09%09%09%09%09while (!stack.peek().equals('(')) %7B%0A%09%09%09%09%09%09postfix += stack.pop();%0A%09%09%09%09%09%7D%0A%09%09%09%09%09stack.pop(); // pop '('%0A%09%09%09%09%09break;%0A%0A%09%09%09%09default:%0A%09%09%09%09%09while (stack.size() %3E 0) %7B%0A%09%09%09%09%09%09Character peekedChar = stack.peek();%0A%0A%09%09%09%09%09%09Integer peekedCharPrecedence = getPrecedence(peekedChar);%0A%09%09%09%09%09%09Integer currentCharPrecedence = getPrecedence(c);%0A%0A%09%09%09%09%09%09if (peekedCharPrecedence %3E= currentCharPrecedence) %7B%0A%09%09%09%09%09%09%09postfix += stack.pop();%0A%09%09%09%09%09%09%7D else %7B%0A%09%09%09%09%09%09%09break;%0A%09%09%09%09%09%09%7D%0A%09%09%09%09%09%7D%0A%09%09%09%09%09stack.push(c);%0A%09%09%09%09%09break;%0A%09%09%09%7D%0A%0A%09%09%7D%0A%0A%09%09while (stack.size() %3E 0)%0A%09%09%09postfix += stack.pop();%0A%0A%09%09return postfix;%0A%09%7D%0A%7D%0A

Add converter from infix to postfix notation.