Changeset 533


Ignore:
Timestamp:
02/08/2012 04:16:37 PM (12 years ago)
Author:
marcus
Message:
  • finished IF command (without /forward support)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • SHX/trunk/SeismicHandler/modules/parse.py

    r531 r533  
    300300        except: 
    301301            # cannot open 
    302             raise ShxError("Input not readable!") 
     302            raise ShxError("Command or procedure not found!", status=1001) 
    303303 
    304304        # Cache self-handled commands. These methods begin with "command". 
     
    378378                print cmd 
    379379 
     380            logMessage("debug.parse", "executing '%s'" % cmd) 
     381 
    380382            cmd = Parse(cmd, switches=self.switches).parsed 
    381383 
     
    383385            _ = Translate(cmd, self, switches=self.switches) 
    384386            self.__recent = cmd.get("shx_translated", cmd["shx_input_conv"]) 
     387 
     388            logMessage("debug.parse", "converted '%s'" % self.__recent) 
    385389 
    386390            # Check for internal command ... 
     
    510514 
    511515    def commandIf(self, *args, **kwargs): 
    512         print args, kwargs 
    513         pass 
    514  
    515     def IfGoto(self, cmd): 
    516516        # cast format 
    517517        cast = { 
     
    521521                } 
    522522 
    523         cmp, check = cmd.p[2].value, cmd.p[2].value[:2] 
    524  
    525         var1 = cast[cmp[-1]](cmd.p[1].value) 
    526         var2 = cast[cmp[-1]](cmd.p[3].value) 
     523        try: 
     524            var1, cmp, var2, operation = args[:4] 
     525        except: 
     526            raise ShxError("invalid parameters", status=1701) 
     527 
     528        operation = operation.lower() 
     529        if operation not in ["goto", "return"]: 
     530            raise ShxError("illegal IF command %s" % operation, status=1712) 
     531 
     532        var1 = cast[cmp[-1].upper()](var1) 
     533        var2 = cast[cmp[-1].upper()](var2) 
    527534 
    528535        # comparison 
     
    548555 
    549556        # check condition 
    550         if comp[check](var2): 
    551             self.Goto(cmd.p[5].value) 
     557        if not comp[cmp[:2].upper()](var2): 
     558            logMessage("debug.parse.if", "statement is evaluated as false") 
     559            return 
     560 
     561        logMessage("debug.parse.if", "statement is evaluated as true") 
     562 
     563        if operation == "return": 
     564            self.commandReturn() 
     565        else: 
     566            # GOTO is left 
     567            try: 
     568                self.commandGoto(args[4]) 
     569            except IndexError: 
     570                raise ShxError("too less parameters passed", status=1712) 
    552571 
    553572 
     
    662681            cmd["shx_converted"] and cmd["shx_command"].upper() or \ 
    663682                                                             cmd["shx_command"], 
    664             " ".join(cmd["shx_parameter"]), 
     683            " ".join(map(str, cmd["shx_parameter"])), 
    665684            len(qual) and "/" + " /".join(qual) or "", 
    666685        ]) 
Note: See TracChangeset for help on using the changeset viewer.