title: Parsing a string, Grammar file
body: <p>How would I separate the below string into its parts. What I need to separate is each &lt; Word > including the angle brackets from the rest of the string. So in the below case I would end up with several strings 1. "I have to break up with you because " 2. "&lt; reason >" (without the spaces) 3. " . But Let's still " 4. "&lt; disclaimer >" 5. " ."</p>
  
  <pre><code>I have to break up with you because &lt;reason&gt; . But let's still &lt;disclaimer&gt; .
  </code></pre>
  
  <p>below is what I currently have (its ugly...)</p>
  
  <pre><code>boolean complete = false;
      int begin = 0;
      int end = 0;
          while (complete == false) {
          if (s.charAt(end) == '&lt;'){
              stack.add(new Terminal(s.substring(begin, end)));
              begin = end;
          } else if (s.charAt(end) == '&gt;') {
              stack.add(new NonTerminal(s.substring(begin, end)));
              begin = end;
              end++;
          } else if (end == s.length()){
              if (isTerminal(getSubstring(s, begin, end))){
                  stack.add(new Terminal(s.substring(begin, end)));
              } else {
                  stack.add(new NonTerminal(s.substring(begin, end)));
              }
              complete = true;
          }
          end++;
  </code></pre>