import java.util.Arrays; public class main { public static void main(String[] args){ // 23, x, +, (,0, 5, x,), ^, 2, -, 1 String ausdruck = "230lkjhx +(2 5x) ^2,jhff 3−1gf "; String ausdruck2 = "0x +(2 5x) ^2−1f "; Lexer lexer = new Lexer(); // [23x] + [0,5x^2 - 1] //lexer.lex(ausdruck).forEach(token -> System.out.println(token.getTokenString())); Parser p = new Parser(); AstExpression result = p.parse(lexer.lex(ausdruck)); do { System.out.println( ((AstValue) result.astBinaryOp.binaryOp[0]).astNumber.astDigitWoz.astDigitWozContent ); System.out.println( ((AstOperator) result.astBinaryOp.binaryOp[1]).astOperator ); if(result.astBinaryOp.binaryOp[2].getClass() == AstValue.class) { System.out.println( ((AstValue) result.astBinaryOp.binaryOp[2]).astNumber.astDigitWoz.astDigitWozContent ); break; } else { result = (AstExpression) result.astBinaryOp.binaryOp[2]; } } while ( true ); /* System.out.println( ((AstValue) result.astBinaryOp.binaryOp[0]).astNumber.astDigitWoz.astDigitWozContent ); System.out.println( ((AstOperator) result.astBinaryOp.binaryOp[1]).astOperator ); //------------------- AstExpression root = (AstExpression) result.astBinaryOp.binaryOp[2]; System.out.println( ((AstValue) root.astBinaryOp.binaryOp[0]).astNumber.astDigitWoz.astDigitWozContent ); System.out.println( ((AstOperator) root.astBinaryOp.binaryOp[1]).astOperator ); //--------------------- AstExpression root2 = (AstExpression) root.astBinaryOp.binaryOp[2]; System.out.println( ((AstValue) root2.astBinaryOp.binaryOp[0]).astNumber.astDigitWoz.astDigitWozContent ); System.out.println( ((AstOperator) root2.astBinaryOp.binaryOp[1]).astOperator ); System.out.println( ((AstValue) root2.astBinaryOp.binaryOp[2]).astNumber.astDigitWoz.astDigitWozContent ); */ } }