pyccel.parser.syntactic module#

class pyccel.parser.syntactic.SyntaxParser(inputs, **kwargs)[source]#

Bases: BasicParser

Class which handles the syntactic stage as described in the developer docs.

This class is described in detail in developer_docs/syntactic_stage.md. It extracts all necessary information from the Python AST in order to create a representation complete enough for the semantic stage to determine types, etc as described in developer_docs/semantic_stage.md.

Parameters:
  • inputs (str) – A string containing code or containing the name of a file whose code should be read.

  • **kwargs (dict) – Additional keyword arguments for BasicParser.

create_new_function_scope(name, **kwargs)[source]#

Create a new Scope object for a Python function.

Create a new Scope object for a Python function with the given name, and attach any decorators’ information to the scope. The new scope is a child of the current one, and can be accessed from the dictionary of its children using the function name as key.

Before returning control to the caller, the current scope (stored in self._scope) is changed to the one just created, and the function’s name is stored in self._current_function_name.

Parameters:
  • name (str) – Function’s name, used as a key to retrieve the new scope.

  • **kwargs (dict) – Keyword arguments passed through to the new scope.

Returns:

The new scope for the function.

Return type:

Scope

insert_import(expr)[source]#

Insert an import into the scope.

Insert an import into the scope along with the targets that are needed.

Parameters:

expr (Import) – The import to be inserted.

parse()[source]#

Convert Python’s AST to Pyccel’s AST object.

Convert Python’s AST to Pyccel’s AST object and raise errors for any unsupported objects.

Returns:

The Pyccel AST object.

Return type:

pyccel.ast.basic.PyccelAstNode

pyccel.parser.syntactic.get_name(a)[source]#

get the name of variable or an argument of the AST node.