本文整理汇总了Python中scanner.Scanner.scanError方法的典型用法代码示例。如果您正苦于以下问题:Python Scanner.scanError方法的具体用法?Python Scanner.scanError怎么用?Python Scanner.scanError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scanner.Scanner
的用法示例。
在下文中一共展示了Scanner.scanError方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Parser
# 需要导入模块: from scanner import Scanner [as 别名]
# 或者: from scanner.Scanner import scanError [as 别名]
class Parser(object):
def __init__(self, program):
super(Parser, self).__init__()
self.scanner = Scanner(program)
self.symbol = ""
self.statementList = []
self.__nextSymbol()
self.relops = [SymType.eqop, SymType.ltop, SymType.leop, SymType.geop, SymType.gtop]
self.predefFigures = [SymType.circle, SymType.square, SymType.point, SymType.line]
self.colors = [SymType.black, SymType.notblack]
def __nextSymbol(self):
self.symbol = self.scanner.nextSymbol()
def __accept(self, atom):
if self.symbol == atom:
self.__nextSymbol()
return 1
else:
return 0
def __expect(self, atom):
if self.__accept(atom):
return 1
else:
self.__syntaxError(atom)
return 0
def __syntaxError(self, atom):
self.scanner.scanError(atom, "Spodziewany symbol: ", atom)
raise Exception
def __syntaxError1(self, atom):
self.scanner.scanError(atom, "Nieoczekiwany symbol: ", atom)
raise Exception
def program(self):
i = 0
while self.symbol != SymType.others:
self.statementList.extend([self.__statement()])
i = i + 1
if i > 1000:
raise Exception("Zbyt wiele instrukcji.")
def __statement(self):
r = self.__assignmentStmt()
if r != None:
return r
r = self.__incrementStmt()
if r != None:
return r
r = self.__decrementStmt()
if r != None:
return r
r = self.__whileStmt()
if r != None:
return r
r = self.__ifStmt()
if r != None:
return r
r = self.__drawStmt()
if r != None:
return r
r = self.__moveStmt()
if r != None:
return r
r = self.__printStmt()
if r != None:
return r
else:
self.__syntaxError1(self.symbol)
return r
def __assignmentStmt(self):
if self.symbol == SymType.ident :
varName = self.scanner.spell
self.__nextSymbol()
if self.__accept(SymType.becomes):
value = self.__number()
return stmts.AssignmentStmt(varName, value)
elif self.symbol == SymType.beginsy:
return self.__figureAssignmentStmt(varName)
else:
self.__syntaxError1(self.symbol)
else:
return None
def __figureAssignmentStmt(self, figureName):
statements = self.__block()
figure = typez.MyFigure(figureName, statements)
return stmts.FigureAssignmentStmt(figureName, figure)
def __incrementStmt(self):
if self.__accept(SymType.increment) :
if self.symbol == SymType.ident:
ident = self.scanner.spell
self.__nextSymbol()
else:
self.__syntaxError1(self.symbol)
return stmts.IncrementStmt(ident)
#.........这里部分代码省略.........