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
- Visitor Design Pattern https://sourcemaking.com/design_patterns/visitor
-
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 definedSee also
- Python’s Namespaces, Scope Resolution, and the LEGB Rule: http://spartanideas.msu.edu/2014/05/12/a-beginners-guide-to-pythons-namespaces-scope-resolution-and-the-legb-rule/
- Python Scopes and Namespaces: https://docs.python.org/2/tutorial/classes.html#python-scopes-and-namespaces
- Variables and scope: http://python-textbok.readthedocs.org/en/latest/Variables_and_Scope.html
- Gotcha: Python, scoping and closures: http://eev.ee/blog/2011/04/24/gotcha-python-scoping-closures/