Example #1
0
import pyparsing

from psciclib import parseexpr
from psciclib.exceptions import Error
from psciclib.units import Q_
from psciclib import unitbridge
from psciclib.result import Mode

while True:
    try:
        expr = input("> ")
    except EOFError:
        print()
        break
    try:
        tree = parseexpr.parse(expr)
    except (Error, pyparsing.ParseException) as e:
        print(e)
        continue
    print(tree)
    try:
        val = tree.evaluate()
    except ValueError as e:
        print("ValueError:", e)
        continue
    # Solve numerically if needed. TODO: some way for the user to provide x0
    if val.is_unsolved:
        val_ = val.nsolve(1.0)  # TODO: x0 from user
        if val_ is not None:
            # We found a numerical solution.
            val = val_
Example #2
0
def pe(s, *args):
    print(s.format(*args))
    return parse(s.format(*args)).evaluate().n()
Example #3
0
import pyparsing

from psciclib import parseexpr
from psciclib.exceptions import Error
from psciclib.units import Q_
from psciclib import unitbridge
from psciclib.result import Mode

while True:
    try:
        expr = input("> ")
    except EOFError:
        print()
        break
    try:
        tree = parseexpr.parse(expr)
    except (Error, pyparsing.ParseException) as e:
        print(e)
        continue
    print(tree)
    try:
        val = tree.evaluate()
    except ValueError as e:
        print("ValueError:", e)
        continue
    # Solve numerically if needed. TODO: some way for the user to provide x0 
    if val.is_unsolved:
        val_ = val.nsolve(1.0) # TODO: x0 from user 
        if val_ is not None:
            # We found a numerical solution.
            val = val_
Example #4
0
def pe(s, *args):
    print(s.format(*args))
    return parse(s.format(*args)).evaluate().n()