当前位置: 首页>>代码示例>>Python>>正文


Python Scanner.scanError方法代码示例

本文整理汇总了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)
#.........这里部分代码省略.........
开发者ID:kawazaki0,项目名称:tkom,代码行数:103,代码来源:parser.py


注:本文中的scanner.Scanner.scanError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。