In this document: Terms in angle brackets are non-terminals. Terms by themselves are tokens (i.e., terminals). Terms in single quotes are lexemes. LEXICAL ELEMENTS (Sec 10.2, p208) keyword: 'class' | 'constructor' | 'function' | 'method' | 'field' | 'static' | 'var' | 'int' | 'char' | 'boolean' | 'void' | 'true' | 'false' |'null' | 'this' | 'let' | 'do' | 'if' | 'else' | 'while' | 'return' symbol: '{' | '}' | '(' | ')' | '[' | ']' | '.' | ',' | ';' | '+' | '-' | '*' | '/' | '&' | '|' | '<' | '>' | '=' | '~' integerConstant: decimal integer in range 0...32767 stringConstant: Sequence of Unicode characters surrounded by double quotes (cannot contain newline or double quote characters) identifier: Sequence of letters, digits, underscores NOT starting with a digit. NOTE: The comment is NOT a lexical element and is simply skipped comment: EOL - '//' ... '\n' BLK - '/*' ... '*/' GRAMMAR (Sec 10.2, pp208-9) => 'class' '{' * * '}' => ('static' | 'field') (',' )* ';' => 'int' | 'char' | 'boolean' | => ('constructor' | 'function' | 'method') ('void' | ) '(' ')' => ( (',' )* )? => '{' * '}' => 'var' (',' )* ';' => identifier => identifier => identifier => * => | | | | => 'let' ('[' ']')? '=' ';' => 'if' '(' ')' '{' statements> '}' ('else' '{' statements> '}')? => 'while' '(' ')' '{' statements> '}' ('else' '{' statements> '}')? => 'do' ';' => 'return' ? ';' => ( )* => integerConstant | stringConstant | keywordConstant | | '[' ']' | | '(' ')' | unaryOp => '(' ')' | (|) '.' '(' ')' => ( (',' )* )? => '+' | '-' | '*' | '/' | '&' | '|' | '<' | '>' | '=' => '-' | '~' => 'true' | 'false' | 'null' | 'this' JACK COMPILER GRAMMAR (as indicated by the XML output in Sec. 10.2.4) GRAMMAR NON-TERMINALS THAT ARE "ABSORBED": GRAMMAR after absorbing non-essential non-terminals. => 'class' identifier '{' * * '}' => ('static' | 'field') ('int' | 'char' | 'boolean' | identifier) identifier (',' identifier)* ';' => ('constructor' | 'function' | 'method') ('void' | 'int' | 'char' | 'boolean' | identifier) identifier '(' ')' => ( identifier (',' identifier)* )? => '{' * '}' => 'var' ('int' | 'char' | 'boolean' | identifier) identifier (',' identifier)* ';' => ( | | | | )* => 'let' identifier ('[' ']')? '=' ';' => 'if' '(' ')' '{' statements> '}' ('else' '{' statements> '}')? => 'while' '(' ')' '{' statements> '}' ('else' '{' statements> '}')? => 'do' (identifier '.')? identifier '(' ')' ';' => 'return' ? ';' => (('+' | '-' | '*' | '/' | '&' | '|' | '<' | '>' | '=') )* => integerConstant | stringConstant | 'true' | 'false' | 'null' | 'this' | | '[' ']' | | '(' ')' | '-' | '~' => ( (',' )* )?