コード例 #1
0
ファイル: equations.py プロジェクト: mfkiwl/sfepy
def parse_definition(equation_def):
    """
    Parse equation definition string to create term description list.
    """
    from parseEq import create_bnf

    term_descs = []
    bnf = create_bnf(term_descs)
    try:
        bnf.parseString(equation_def)
    except:
        raise ValueError('cannot parse equation! (%s)' % equation_def)

    return term_descs
コード例 #2
0
ファイル: equations.py プロジェクト: certik/sfepy
def parse_terms(regions, desc, itps):
    """
    Parse equation given by 'desc' into terms. Assign each term its region.
    """
    # Parse.
    term_descs = []
    bnf = create_bnf(term_descs, itps)
    try:
        bnf.parseString(desc)
    except:
        print "cannot parse:\n", desc
        raise

    # Construct terms.
    terms = OneTypeList(Term)
    for td in term_descs:
        ##         print td
        ##         pause()
        try:
            constructor = term_table[td.name]
        except:
            msg = "term '%s' is not in %s" % (td.name, sorted(term_table.keys()))
            raise ValueError(msg)
        region = regions[td.region]
        arg_names = []
        arg_steps = {}
        arg_derivatives = {}
        for arg in td.args:
            if len(arg) == 2:
                name, step = arg
                derivative = None
            else:
                name, step = arg[1]
                derivative = arg[2]

            arg_names.append(name)
            arg_steps[name] = step
            arg_derivatives[name] = derivative

        term = constructor(region, td.name, td.sign)
        term.arg_names = arg_names
        term.arg_steps = arg_steps
        term.arg_derivatives = arg_derivatives
        term.integral_name = td.integral

        terms.append(term)

    return terms