/* MiniJava Lexer Specification */ %% %public %class Lexer %unicode %standalone %line %column %{ /* JAVA code, such as global variable declarations, goes here */ %} %eof{ /* JAVA code on what to do when EOF is reached */ %eof} LineTerminator = \r|\n|\r\n InputCharacter = [^\r\n] WhiteSpace = {LineTerminator} | [ \t\f] EndOfLineComment = "//" {InputCharacter}* {LineTerminator} Identifier = [:jletter:] [:jletterdigit:]* DecIntegerLiteral = 0 | [1-9][0-9]* /* Make sure your state names are more descriptive ones than this one */ %state SOME_STATE %% "sample_token" { System.out.println("SAMPLE_TOKEN"); } { "another_token" { System.out.println("ANOTHER_TOKEN"); } "token_with_semantic_value" { System.out.println("TOKEN_WITH_SEMANTIC_VALUE(" + yytext() + ")"); } /* comments */ {EndOfLineComment} { /* ignore */ } "/*" { yybegin(SOME_STATE); } /* whitespace */ {WhiteSpace} { /* ignore */ } } { . { } } /* error fallback */ .|\n { System.out.println("Error: Illegal character <" + yytext() + "> at line " + yyline + " column " + yycolumn ); System.exit(1); }