directions for use javacc token -
i want distinguish multiple tokens.
@ code.
token : { < loops : < beat > | < bass > | < melody > > | < #beat : "beat" > | < #bass : "bass" > | < #melody : "melody" > } void findtype(): {token loops;} { loops = < loops > { string type = loops.image; }
i want use findtype () function find type.
how can return correct output when input "beat"?
what want add return statement, this:
string findtype(): {token loops;} { loops = < loops > { string type = loops.image; return type; } }
have in mind have changed return value definition in method, void
string
.
then, main:
examplegrammar parser = new examplegrammar(system.in); while (true) { system.out.println("reading standard input..."); system.out.print("enter loop:"); try { string type = examplegrammar.findtype(); system.out.println("type is: " + type); } catch (exception e) { system.out.println("nok."); system.out.println(e.getmessage()); examplegrammar.reinit(system.in); } catch (error e) { system.out.println("oops."); system.out.println(e.getmessage()); break; } }
it generates output like:
reading standard input... enter loop:bass type is: bass reading standard input... enter loop:beat type is: beat
Comments
Post a Comment