예제 #1
0
  def _eval( self, cPPAST ):
    if self.logger:
      for symbol, replacement in self.symbols.items():
        if isinstance(replacement, list):
          replacementList = '[%s]' % (', '.join([str(x) for x in replacement]))
        else:
          replacementList = str(replacement)

    if not cPPAST:
      return []

    if isinstance(cPPAST, Token):
      try:
        actionFunction = self.tokenActions[cPPAST.id]
      except KeyError:
        raise Exception('Bad AST Node')
      return actionFunction(cPPAST)

    elif isinstance(cPPAST, list):
      rtokens = TokenList()
      if cPPAST and len(cPPAST):
        for node in cPPAST:
          result = self._eval(node)
          if isinstance(result, list):
            rtokens.extend(result)
          elif result:
            rtokens.append(result)
      return rtokens

    elif isinstance(cPPAST, ppAst):
      try:
        actionFunction = self.astActions[cPPAST.name]
      except KeyError:
        raise Exception('Bad AST Node')
      return actionFunction(cPPAST)
    else:
      raise Exception('Bad AST Node')
예제 #2
0
 def eval_IfSection(self, cPPAST):
   rtokens = TokenList()
   self.line += 1
   value = self._eval(cPPAST.getAttr('if'))
   if value:
     rtokens.extend( value )
   for elseif in cPPAST.getAttr('elif'):
     self.line += 1
     if not value:
       value = self._eval(elseif)
       if value:
         rtokens.extend( value )
     else:
       self._eval(elseif) # Silent eval to count line numbers properly
   if cPPAST.getAttr('else'):
     elseEval = self._eval(cPPAST.getAttr('else'))
     self.line += 1
     if not value:
       value = elseEval
       rtokens.extend( value )
   self.line += 1
   return rtokens