// // mjava.grammar // To build: // java -jar sablecc.jar mjava.grammar // javac Main.java // Helpers digit = ['0'..'9']; let = ['a'..'z'] | ['A'..'Z']; space = ' ' | 9; newline = 10 | 11 | 12; carriage_return = 13; not_star = [0..41] | [43..127]; not_slash = [0..46] | [48..127]; not_slashstar = [0..41] | [43..46] | [48..127]; not_newline = [0..9] | [11..127]; Tokens // TODO: add missing tokens - see the appendix for the different tokens boolean = 'boolean'; class_token = 'class'; // must not be "class" - that conflicts with Java keywords else = 'else'; extends = 'extends'; false = 'false'; if = 'if'; int = 'int'; length = 'length'; main = 'main'; new = 'new'; println = 'System.out.println'; lbracket = '['; rbracket = ']'; semi = ';'; equal = '='; dot = '.'; bang = '!'; comma = ','; plus = '+'; and = '&&'; less = '<'; minus = '-'; star = '*'; // TODO: complete the following to define tokens for identifiers, numbers, // whitespace, single-line comments starting with '//', and multi-line // comments starting with /* and ending with */ id = let; number = digit; whitespace = (carriage_return)*; line_comment = '//' newline ; slashstar_comment = '/*' ; Ignored Tokens whitespace, line_comment, slashstar_comment;