class SyntaxAnalyseCond extends SyntaxAnalyse {	public SyntaxAnalyseCond(String s) {		super(s);	}	/**	 *  prueft, ob naechstes Zeichen dem uebergebenen entspricht	 */	boolean nextIs(char c) {		if (next == c) {			scan();			return true;		} else			return false;	}		/**	 *  liefert aktuelle Position in expressionS	 */	int getPos() {		return pos;	}		/**	 *  setzt (zurueck) auf Position p	 */	void setPos(int p) {		pos = p-1;		scan();	}		/**	 *  prueft auf Condition	 */	boolean isCondition() {		int pos = getPos();		if (isExpression() && nextIs('=') && isExpression()) {			if(DEBUG)System.out.println(" Condition recognized!");			return true;		} else {			setPos(pos);			if (nextIs('(') && isCondition() && nextIs(')')) {				if(DEBUG)System.out.println(" '(' Condition ')' recognized!");				return true;			} else				return false;		}	}			/**	 *  prueft auf Term (mit Condition)	 */	public boolean isTerm() {		if ( next=='(' ) {			scan();			int pos = getPos(); 			if ( isExpression() && nextIs(')') ) {				if(DEBUG)System.out.println(" '(' Expression ')' recognized!");				return true;			} else {				setPos(pos);				return isCondition() && nextIs('/') && isExpression() 				                     && nextIs('/') && isExpression() 				                     && nextIs(')');			}		} else {			return isAtom();		}	}								   	public static void main(String[] argv) {		String inputString = "help";			java.io.BufferedReader keyboard =			new java.io.BufferedReader(new java.io.InputStreamReader(System.in));		while (!inputString.equals("exit")) {			if (inputString.equals("help")) {				System.out.println();							System.out.println(" Expression ::= Term                |");				System.out.println("                Term '+' Expression |");				System.out.println("                Term '-' Expression ");				System.out.println("       Term ::= Atom                |");				System.out.println("                '(' Expression ')'  |");				System.out.println("                '(' Condition '/' Expression '/' Expression ')'");				System.out.println("  Condition ::= Expression '=' Expression |");				System.out.println("                '(' Condition ')'");				System.out.println("       Atom ::= <a_number>");			}			System.out.print("\n\nType in your Expression, 'help' or 'exit': ");			// read line from keyboard			try {				inputString = keyboard.readLine();			}			catch (java.io.IOException ioe) {				System.out.println(" Error: "+ioe);							}			if (inputString.equals("exit")) break;			if (inputString.equals("help")) continue;			if (inputString.length() == 0) continue;			// syntax analyse 			SyntaxAnalyseCond sa = new SyntaxAnalyseCond(inputString);			if (sa.solve())				System.out.println("\n\n RESULT: This is a VALID expression!");			else				System.out.println("\n\n RESULT: SYNTAX ERROR!");		}		System.out.println("Bye!");	}}	
