title: Would using this shortcut cause problems?
body: <p><strong>CONTEXT</strong>: I am making an infix calculator in Java, and am now on the point where I'm implementing unary plus and minus. An operator is unary if it comes in where a value is expected. This would be any of the following: at the start, after an operator or after an opening parenthesis.</p>
  <p><strong>Relevant information</strong>: (Assume what I say in this section works as intended...because it does.)</p>
  <p>I read in a line (which is checked to be an equation beforehand), and store it as an array of strings, delimited by spaces, called <code>readin[]</code>.</p>
  <p>When I encounter an &quot;operator&quot; (plus, minus, open paren, etc) in this equation, I push it to a stack called <code>ops</code>. Exceptions are for closing parenthesis, which forces a calculation to the last open parenthesis, and for these unary operators.</p>
  <p>When I encounter a &quot;value&quot; (ie. a known, initialized variable, or a number), I push it to the values stack. All variables must start with a letter.</p>
  <p>I cycle through each element in <code>readin[]</code>, keeping track with the value <code>i</code>, thus <code>i</code> is the current element, and <code>i-1</code> is the previous element in the array from what we are currently looking at.</p>
  <p>With few exceptions, all math is done after interpreting the full equation.</p>
  <p><strong>The Shortcut (Code)</strong>:</p>
  <pre><code>if(readIn[i].charAt(0) == '-'){
   
               if(ops.empty() &amp;&amp; values.empty()){
                      //is unary, set negative
               }
               else if( readIn[i-1].charAt(0) == ops.peek() ){
                      //is unary, set negative
               }
               //it isn't unary, continue onwards
  }
  </code></pre>
  <p><strong>What it's Doing (Plain English):</strong> It checks if we've encountered a minus sign, and if we did, it checks the following. If either of the following are true, then this minus sign is deemed &quot;unary&quot;.</p>
  <p>If the operator stack is empty, while the the values stack is also empty. If the previous element in the equation is on the operator stack, and thus is an operator.</p>
  <p><strong>Why's it doing that?</strong> Because if we didn't encounter a minus sign, then we definitely didn't encounter a unary minus sign.</p>
  <p>If we don't have anything on the stacks, then we have either catastrophically failed somewhere, or we're at the beginning of the equation. As mentioned, an operator at the start is indicative of a unary operator. (However, I don't think the operator stack is too useful in determining this, so it may be a superfluous check.)</p>
  <p>If the last element in the string array is an operator (including open parenthesis), then we are encountering this minus sign after an operator, which is also indicative of a unary operator.</p>
  <p>By the way, &quot;set negative&quot; just flips a boolean value which modifies the next incoming value, so 5 consecutive minus signs ought to &quot;add the negative&quot; of the next value coming in, the same way 1 minus sign does so.</p>
  <p><strong>The Question:</strong> Are there any inherent problems that would arise from this code, based on the information given? Maybe ones that wouldn't result from standard equations.</p>