options { UNICODE_INPUT = true; } PARSER_BEGIN(chaincalc) package javaKurs2.javacc; public class chaincalc { public static void main(String args[]) throws ParseException { chaincalc parser = new chaincalc(System.in); parser.Input(); } } PARSER_END(chaincalc) // Lexer definition SKIP : { " " | "\r" | "\t" } TOKEN : { | | | < NUM: ()+ ( "." ()+ )? > | < DIGIT : ["0"-"9"] > } // is predefined token for "end of file" void Input() : { double result = 0.0; //important: initialize because optional on RHS } { ([result=Expr()] { System.out.println("result: "+result); } )+ | { System.exit(-1); } } double Expr() : { Token tnumber; Token tnum = null; // important: initialize because optional on RHS double result; } { tnumber = { result = Double.parseDouble(tnumber.image); } ( ( tnum=) { result+=Double.parseDouble(tnum.image); } | ( tnum=) { result-=Double.parseDouble(tnum.image); })* { return result; } }