Ejemplo n.º 1
0
    def __parse_C(self, tokens, lineno):
        c_pat = r"^(c.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s*$"
        ret = re.match(c_pat, tokens, re.I)

        err_msg = "{}: Parse capacitor failed in line {} ..."\
                  .format(status.ERR_PARSE, lineno)
        if not ret:
            self.write(err_msg, 'fail')
            self.status_code = status.ERR_PARSE
            return

        ret_tuple = ret.groups()
        if len(ret_tuple) != 4:
            self.write(err_msg, 'fail')
            self.status_code = status.ERR_PARSE
            return

        error, value = utils.parse_value(ret_tuple[3])
        if error != status.OKAY:
            self.write(err_msg, 'fail')
            self.status_code = status.ERR_PARSE
            return

        name = ret_tuple[0]
        pos_node = self.__cktinst.get_add_node(ret_tuple[1])
        neg_node = self.__cktinst.get_add_node(ret_tuple[2])

        cap = Capacitor(name, pos_node, neg_node, value)

        self.status_code = self.__cktinst.add_device(cap)
Ejemplo n.º 2
0
    def __parse_ac(self, tokens, lineno):
        ac_pat = r"^\.ac\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s*$"
        ret = re.match(ac_pat, tokens)
        err_msg = "{}: Parse AC analysis failed in line {} ...".format(
            status.ERR_PARSE, lineno)
        if not ret:
            self.write(err_msg, 'fail')
            self.status_code = status.ERR_PARSE
            return

        ret_tuple = ret.groups()
        if len(ret_tuple) != 4:
            self.write(err_msg, 'fail')
            self.status_code = status.ERR_PARSE
            return

        vtype = ret_tuple[0]
        if vtype != "dec" and vtype != "oct" and vtype != "line":
            self.write(err_msg, 'fail')
            self.status_code = status.ERR_PARSE
            return

        ret, points = utils.parse_value(ret_tuple[1])
        if ret != status.OKAY:
            self.write(err_msg, 'fail')
            self.status_code = status.ERR_PARSE
            return

        ret, fstart = utils.parse_value(ret_tuple[2])
        if ret != status.OKAY:
            self.write(err_msg, 'fail')
            self.status_code = status.ERR_PARSE
            return

        ret, fstop = utils.parse_value(ret_tuple[3])
        if ret != status.OKAY:
            self.write(err_msg, 'fail')
            self.status_code = status.ERR_PARSE
            return

        ac = ACAnalysis(const.AC_ANA_TYPE)
        ac.set_arg(vtype, points, fstart, fstop)
        self.__analysis_task += [ac]
Ejemplo n.º 3
0
    def __parse_dc(self, tokens, lineno):
        dc_pat = r"^\.dc\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s*$"
        ret = re.match(dc_pat, tokens, re.I)
        err_msg = "{}: Parse DC analysis failed in line {} ...".format(
            status.ERR_PARSE, lineno)
        if not ret:
            self.write(err_msg, 'fail')
            self.status_code = status.ERR_PARSE
            return

        ret_tuple = ret.groups()
        if len(ret_tuple) != 4:
            self.write(err_msg, 'fail')
            self.status_code = status.ERR_PARSE
            return

        src1 = ret_tuple[0]
        ret, start1 = utils.parse_value(ret_tuple[1])
        if ret != status.OKAY:
            self.write(err_msg, 'fail')
            self.status_code = status.ERR_PARSE
            return
        ret, stop1 = utils.parse_value(ret_tuple[2])
        if ret != status.OKAY:
            self.write(err_msg, 'fail')
            self.status_code = status.ERR_PARSE
            return
        ret, incr1 = utils.parse_value(ret_tuple[3])
        if ret != status.OKAY:
            self.write(err_msg, 'fail')
            self.status_code = status.ERR_PARSE
            return

        dc = DCAnalysis(const.DC_ANA_TYPE)
        dc.set_arg1(src1, start1, stop1, incr1)
        self.__analysis_task += [dc]
Ejemplo n.º 4
0
    def __parse_I(self, tokens, lineno):
        i_pat = r"^(i.*?)\s+(.*?)\s+(.*?)\s+(dc\s+)?(.*?\s+)?(ac\s+)?(.*?\s+)?(tran\s+)?(.*?)?\s*$"
        ret = re.match(i_pat, tokens, re.I)

        err_msg = "{}: Parse current source failed in line {} ..."\
                  .format(status.ERR_PARSE, lineno)

        if not ret:
            self.write(err_msg, 'fail')
            self.status_code = status.ERR_PARSE
            return

        # if not matched, the value is None. filter None
        ret_tuple = ret.groups()
        fltr = list(filter(utils.filter_None, ret_tuple))

        if len(fltr) < 4:
            self.write(err_msg, 'fail')
            self.status_code = status.ERR_PARSE
            return

        name = fltr[0]
        pos_node = self.__cktinst.get_add_node(fltr[1])
        neg_node = self.__cktinst.get_add_node(fltr[2])

        dc_value = None
        ac_value = None
        tran_func = None
        pre_token = ''

        for i in range(3, len(fltr)):
            token = fltr[i].strip()
            if token == 'dc':
                pre_token = 'dc'
            elif token == 'ac':
                pre_token = 'ac'
            elif token == 'tran':
                pre_token = 'tran'
            else:
                if pre_token == '':
                    if dc_value == None:
                        self.status_code, dc_value = utils.parse_value(token)
                    elif ac_value == None:
                        self.status_code, ac_value = utils.parse_value(token)
                    elif tran_func == None:
                        self.status_code, tran_func = utils.parse_tran_func(
                            token)

                elif pre_token == 'dc':
                    self.status_code, dc_value = utils.parse_value(token)
                elif pre_token == 'ac':
                    self.status_code, ac_value = utils.parse_value(token)
                elif pre_token == 'tran':
                    self.status_code, tran_func = utils.parse_value(token)

                pre_token = ''

            if self.status_code != status.OKAY:
                self.write(err_msg, 'fail')
                self.status_code = status.ERR_PARSE
                return

        isrc = Isrc(name, pos_node, neg_node)
        isrc.set_dc_value(dc_value)
        isrc.set_ac_value(ac_value)
        isrc.set_tran_func(tran_func)

        self.status_code = self.__cktinst.add_device(isrc)