Exemplo n.º 1
0
 def __init__(self, in_f, out_f):
     self._fd = out_f                            # output file handle
     self._tkn = JackTokenizer(in_f)             # tokenizer that parses the input into tokens
     self._symbol_table = SymbolTable()
     self._vmw = VmWriter(out_f)
     self._while_index = 0                       # keep track of nested whiles
     self._if_index = 0                          # keep track of nested ifs
     self._class_name = ""
     if not self._tkn.has_more_tokens():
         raise SyntaxError(self._tkn, "No tokens found in input file!")
     
     self._tkn.advance()                         # advance tokenizer once (to first token)
     # call the compile_class method
     self._compile_class()
     # make sure tokenizer has no more tokens. Raise exception if more tokens exist
     if (self._tkn.has_more_tokens()):
         raise SyntaxError(self._tkn, "Unexpected token found <{}>".format(self._tkn.token()))
Exemplo n.º 2
0
 def _string_syntax_error(self):
     raise SyntaxError(self._tkn, "Expected string constant, found <{}> instead".format(self._tkn.token()))
Exemplo n.º 3
0
 def _integer_syntax_error(self):
     raise SyntaxError(self._tkn, "Expected integer constant, found <{}> instead".format(self._tkn.token()))
Exemplo n.º 4
0
 def _expression_syntax_error(self):
     raise SyntaxError(self._tkn, "Unexpected token encountered in expression: <{}>".format(self._tkn.token()))
Exemplo n.º 5
0
 def _type_syntax_error(self, valid_types):
     raise SyntaxError(self._tkn, "Expected type {}, found <{}> instead".format(valid_types, self._tkn.token()))
Exemplo n.º 6
0
 def _identifier_syntax_error(self):
     raise SyntaxError(self._tkn, "Expected identifier, found <{}> instead".format(self._tkn.token()))
Exemplo n.º 7
0
 def _keyword_syntax_error(self, keyword):
     raise SyntaxError(self._tkn, "Expected keyword <{}>, found <{}> instead".format(keyword, self._tkn.token()))
Exemplo n.º 8
0
 def _symbol_syntax_error(self, symbol):
     raise SyntaxError(self._tkn, "Expected symbol <{}>, found <{}> instead".format(symbol, self._tkn.token()))