Exemple #1
0
def loadFile(fName):
    global curWorld

    if "." not in fName:
        fName = fName + ".n"
    f = open(fName)
    p = nparser.Parser(f)
    prog = p.parseTop(curWorld)
    f.close()
    if p.errs:
        print "Parsing errors:\n"
        for e in p.errs:
            print e.longMsg()
            print
        print "\nTotal: " + str(len(p.errs)) + " errors\n"
        curWorld.err = True
        return

    print "Parsing succeeded (" + fName + ")\n"
    addAst(prog)
    ch = Checker(curWorld)
    ch.check()
    if ch.errs:
        print "Checking errors:\n"
        for e in ch.errs:
            print e.longMsg()
            print
        print "\nTotal: " + str(len(ch.errs)) + " errors\n"
        curWorld.err = True
        return

    print "Checking succeeded (" + fName + ")\n"
    if ch.log:
        print ch.log
Exemple #2
0
Fichier : n.py Projet : nrc/N
def loadFile(fName):
  global curWorld
  
  if "." not in fName:
    fName = fName+".n"
  f = open(fName)
  p = nparser.Parser(f)
  prog = p.parseTop(curWorld)
  f.close()
  if p.errs:
    print "Parsing errors:\n"
    for e in p.errs:
      print e.longMsg()
      print
    print "\nTotal: " + str(len(p.errs)) + " errors\n" 
    curWorld.err = True
    return

  print "Parsing succeeded (" + fName + ")\n"
  addAst(prog)
  ch = Checker(curWorld)
  ch.check()
  if ch.errs:
    print "Checking errors:\n"
    for e in ch.errs:
      print e.longMsg()
      print
    print "\nTotal: " + str(len(ch.errs)) + " errors\n" 
    curWorld.err = True
    return
    
  print "Checking succeeded (" + fName + ")\n"
  if ch.log:
    print ch.log
Exemple #3
0
  def parseSynExp(self, s):    
    parse = Parser(util.StringFileAdapter(s))
    parse.recurLimit = 50
    ast = parse.parseSubSeq()
    if parse.errs:
      result = "Parsing errors:\n"
      for e in parse.errs:
        result +=  e.longMsg() + "\n"
      result +=  "\nTotal: " + str(len(parse.errs)) + " errors\n" 
      raise AnimError(result)

    check = Checker(self.world)
    sem = check.handleExp(ast)
    if check.errs:
      result = "Checking errors:\n"
      for e in check.errs:
        result +=  e.longMsg() + "\n"
      result +=  "\nTotal: " + str(len(check.errs)) + " errors\n" 
      raise AnimError(result)

    return sem    
Exemple #4
0
  def parsePremise(self, s):
    parse = Parser(util.StringFileAdapter(s))
    parse.recurLimit = 50
    try:
      ast = parse.parsePremise()
      if parse.errs:
        result = "Parsing errors:\n"
        for e in parse.errs:
          result +=  e.longMsg() + "\n"
        result +=  "\nTotal: " + str(len(parse.errs)) + " errors\n" 
        raise AnimError(result)

      check = Checker(self.world)
      sem = check.checkPremise(ast)
      if check.errs:
        result = "Checking errors:\n"
        for e in check.errs:
          result +=  e.longMsg() + "\n"
        result +=  "\nTotal: " + str(len(check.errs)) + " errors\n" 
        raise AnimError(result)

      return sem    
    except Exception as e:
      raise AnimError(str(e))