public static ParenthesesBlockCCG getParenthesesBlocks(String s) {
        Stack<ParenthesesBlockCCG> stack = new Stack<ParenthesesBlockCCG>();
        ParenthesesBlockCCG currentBlock = new ParenthesesBlockCCG(0);
        stack.push(currentBlock);
        boolean insideHatParenthesis = false;
        for (int i = 1; i < s.length(); i++) {
        	char c = s.charAt(i);
            if (c == L_PAREN && !insideHatParenthesis)   {            	            	
            	ParenthesesBlockCCG newBlock = new ParenthesesBlockCCG(i);
            	currentBlock.subBlocks.add(newBlock);
            	stack.push(newBlock);           
            	currentBlock = newBlock;
            }
            else if (c == R_PAREN && !insideHatParenthesis) {      
            	currentBlock = stack.pop();
            	currentBlock.endIndex = i;
            	currentBlock.subBlocks.trimToSize();
            	currentBlock.label = currentBlock.label.trim();       
            	if (!stack.isEmpty()) currentBlock = stack.peek();
            }
            else {
            	if (c == L_HAT) insideHatParenthesis =  true;
            	else if (c == R_HAT) insideHatParenthesis =  false;
            	if (currentBlock.subBlocks.isEmpty()){
            		currentBlock.label += c;
            	}
            }
        }
        return currentBlock;
    }