Skip to content

Zhiwei-Lii/Jack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Jack解释器

语法

程序结构

classFile
importDec* class+

importDec
'import' classPath ';'

class
'class' className '{' classVarDec* subroutineDec* '}'

classVarDec
'static' type varName (',' varName)* ';'
'field' type varName (',' varName)* ';'

type
'int' | 'char' | 'boolean' | className

suborutineDec
('constructor' | 'function' | 'method' ) ('void' | type) subroutineName '(' parameterList ')' subroutineBody

parameterList
((type varName) (',' type varName)*)?

subroutineBody
'{' statements '}'

语句

statements
statement*

statement
letStatement | ifStatement | whileStatement | doStatement | returnStatement

letStatement
'let' varName ('[' expression ']')? '=' expression ';'

ifStatement
'if' '(' expression ')' '{' statements '}'

varDecStatement
'var' type varName (',' varName)* ';'

whileStatement
'while' '(' expression ')' '{' statements '}'

doStatement
'do' subroutineCall ';'

returnStatement
'return' expression? ';'

表达式

expression
term (op term)*

term
integerConstant | stringConstant | keywordConstant | charConstant | varName | varName '[' expression ']' | subroutineCall | '(' expression ')' | unaryOp term

subroutineCall
subroutineName '(' expressionList ')' (className | varName) '.' subroutineName '(' expressionList ')'

expressionList
(expression (',' expression)*)?

op
'+' | '-' | '*' | '/' | '&' | '&&' | '|' | '||' | '<' | '<=' | '>' | '>=' | '==' | '!='

unaryOp
'-' | '~'

keywordConstant
'true' | 'false' | 'this' | 'null'

Native库函数

Array类

  • function Array new(int size);

String类

  • method char charAt(int index);
  • method int length();

Input类

  • function int readInt();
  • function String readLn();

Output类

  • function void printLn(JackObject object);

Example

基本的语法参见Example.jack

运行解释器的方法:

java Main Example.jack

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages