package grammar; %% %{ String text; void append( char c ) { text += c; } %} %public %type Void %state STRING newline = \r|\n|\r\n %% { \" { yybegin( STRING ); text = ""; } {newline} { } . { } } { \" { yybegin( YYINITIAL ); System.out.println( text ); } {newline} { yybegin( YYINITIAL ); System.out.println( text + " <<< Incomplete string" ); } \\b { append( '\b' ); } \\t { append( '\t' ); } \\f { append( '\f' ); } \\r { append( '\r' ); } \\n { append( '\n' ); } \\[0-3][0-7][0-7] | \\[0-7][0-7] | \\[0-7] { append( ( char ) Integer.parseInt( yytext().substring( 1 ), 8 ) ); } \\x[0-9a-fA-F][0-9a-fA-F] | \\x[0-9a-fA-F] { append( ( char ) Integer.parseInt( yytext().substring( 2 ), 16 ) ); } \\. { append( yytext().charAt( 1 ) ); } . { append( yytext().charAt( 0 ) ); } }