def _eat(self, t: TokenType, contains: list = []): # print("on eat " + str(t) + " cpmpare with current " + str(self._current_token)) assert self._current_token.kind == t if len(contains) > 0: if self._current_token.value not in contains: syntax_error(self._current_filename, "one of {content}".format( content=contains), self._current_token) self._get_token()
def pycode(self): if self.COMMON: if (not _in_pro) and (not _in_function): error.syntax_error('COMMON outside of PRO or FUNCTION', self.lineno) return '' return 'global ' + ', '.join([ pycode(id) for id in self.identifier_list.get_items()[1:] ]) if len(self) == 1: return Node.pycode(self) return pycomment(str(self))
def pycode(self): if self.GOTO: error.conversion_error('cannot convert GOTO statements; please ' + 'remove them and try again', self.lineno) return pycomment(str(self)) if not self.RETURN: return str(self[0]).lower() if _in_pro: return 'return _ret()' if _in_function: return 'return ' + pycode(self.expression) error.syntax_error('RETURN outside of PRO or FUNCTION', self.lineno) return ''
def _parse_variable_declaration(self) -> VariableExprAST: valid = ["static", "field"] if self._current_token.kind == TokenType.KEY_WORDS \ and self._current_token.value in valid: scope = self._current_token.value self._eat(TokenType.KEY_WORDS, valid) kind = self._current_token self._eat(TokenType.KEY_WORDS, ["int", "string", "boolean"]) name = self._current_token self._eat(TokenType.ID) value = None if self._current_token.kind == TokenType.SYMBOL\ and self._current_token.value == "=": self._eat(TokenType.SYMBOL, ["="]) value = self._current_token self._eat(value.kind) self._eat(TokenType.SYMBOL, [";"]) return VariableExprAST(scope, kind.value, name, value) else: syntax_error(self._current_filename, "identifier", self._current_token)
def t_error(t): error.syntax_error('illegal character: %s\n next: %s' \ % (repr(t.value[0]), repr(t.value[0:50])), t.lineno) t.skip(1)
def p_error(p): "Error function used by the parser" import pdb pdb.set_trace() error.syntax_error('invalid syntax at %s' % repr(str(p.value)), p.lineno)
def t_error(t): error.syntax_error('illegal character: %s' % repr(t.value[0]), t.lineno) t.skip(1)
def p_error(p): "Error function used by the parser" error.syntax_error('invalid syntax at %s' % repr(str(p.value)), p.lineno)
def p_error(p): "Error function used by the parser" import pdb; pdb.set_trace() error.syntax_error('invalid syntax at %s' % repr(str(p.value)), p.lineno)