private static Vector Parenthesize(Vector vec){
  if (NeedsParentheses(vec)) {
    vec.setElementAt("(" + ((String)vec.elementAt(0)),0);
    for (int i=1; i < vec.size(); i++) {
      vec.setElementAt(" " + ((String)vec.elementAt(i)),i);
    }
    ;
    int curLineNum=vec.size() - 1;
    vec.setElementAt(((String)vec.elementAt(curLineNum)) + ")",curLineNum);
  }
  ;
  return vec;
}

private static Vector Parenthesize ( Vector vec ) { if ( NeedsParentheses ( vec ) ) { vec . setElementAt ( "(" + ( ( String ) vec . elementAt ( 0 ) ) , 0 ) ; for ( int i = 1 ; i < vec . size ( ) ; i ++ ) { vec . setElementAt ( " " + ( ( String ) vec . elementAt ( i ) ) , i ) ; } ; int curLineNum = vec . size ( ) - 1 ; vec . setElementAt ( ( ( String ) vec . elementAt ( curLineNum ) ) + ")" , curLineNum ) ; } ; return vec ; }
if vec is a stringvector representing an expression , then this returns the stringvector obtained by parenthesizing the expression if it may need parenthesizing . this is used only to prevent parsing errors when the expression appears immediately to the right of an " = " in the spec . this is a rare situation , so it would be nice to add the parentheses only if really necessary . for now , the parentheses are added if one of the following tokens occur outside parentheses and not inside a string : * = # < not followed by < > not followed by > or preceded by = | preceded or followed by - \ not followed by " o " or " x " . / followed by " \ " * left parentheses are * ( [ { < < * the handling of " \ " is a simplifying hack . lots of operators beginning with " \ " like " \ / " , " \ gg " and " \ subseteq " have precedence greater than or equal to " = " . the only commonly used ones with precedence lower than " = " seem to be " \ o " and " \ x " . it doesn ' t seem to be worth the bother of checking for the others just to avoid unnecessarily adding the parentheses when those other rare operators are used . * perhaps the one improvement that might be worth making in this procedure is to have it not add parentheses because of " dangerous " operations in an if clause - - for example : * if x < 0 then . . . * this would require considering " if " to be a left parenthesis and " then " to be a right parenthesis . however , that ' s not trivial to implement because of unlikely things like * ifx : = 42 ; x : = ifx < thenx
