pycep.interpreter Module

pycep.interpreter.execfile(filename)

The interpreter takes a file path pointing to a python program and then executes its contents.

>>> import pycep.interpreter
>>> pycep.interpreter.execfile("pycep/tests/programs/helloworld.py")
Hello, world!
class pycep.interpreter.Interpreter

An AST-based interpreter

See also

visit_Name(node, scope)

Return the value or raise a NameError if not found.

visit(node, scope=None)

Visit a node.

bind(name, value, local_scope=None)

Bind a variable name to a value.

Parameters:
  • name (string) – The variable name to bind
  • value (ast.AST) – The value to store
  • local_scope (ast.AST) – The local scope to apply, None to store in globals
resolve(name, local_scope=None)

Find a variable name according to the LEGB rule.

A namespace maps names to objects, implemented as a dictionary.

A scope defines at which hierarchy level to search for a particular variable name, i.e. which namespace to apply.

Python uses the LEGB (Local, Enclosed, Global, Builtin) rule for scope lookups.

Parameters:
  • name (string) – The variable name to look up
  • local_scope (ast.AST) – The local scope to apply, None if there is no local scope to consider
Returns:

The object found in the hierarchy corresponding to name

Return type:

parser.st

Raises:

NameError – Name not defined

comments powered by Disqus