neurolang.frontend.ast module

Defines Abstract Syntax Tree base classes for text-parsed language code =========================================

1- defines an AST node 2- defines an AST walker, able to go through an AST to convert it to some other representation

class neurolang.frontend.ast.ASTNode(name, children)

Bases: dict

Class representing a Node in an Abstract Syntax Tree

Methods

clear()

copy()

fromkeys(iterable[, value])

Create a new dictionary with keys from iterable and values set to value.

get(key[, default])

Return the value for key if key is in the dictionary, else default.

items()

keys()

pop(k[,d])

If key is not found, d is returned if given, otherwise KeyError is raised

popitem(/)

Remove and return a (key, value) pair as a 2-tuple.

setdefault(key[, default])

Insert key with a value of default if key is not in the dictionary.

update([E, ]**F)

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values()

class neurolang.frontend.ast.ASTWalker

Bases: object

Base class for Abstract Syntax Tree walkers. Walke through an AST translating nodes to the corresponding Neurolang intermediate representation

Methods

evaluate(ast)

Converts input to intermediate representation: - if input is an ASTNode, calls -if it exists- the class method corresponding to the node type (methods are declared in child class) - if input is a list of ASTNode, recursively calls itself on every node - else, simply passes ast through

evaluate(ast: ASTNode | List[ASTNode] | Any) Expression | List[Expression] | Any

Converts input to intermediate representation: - if input is an ASTNode, calls -if it exists- the class method corresponding to the node type (methods are declared in child class) - if input is a list of ASTNode, recursively calls itself on every node - else, simply passes ast through

Parameters:
astUnion[ASTNode, List[ASTNode], Any]

input to convert to intermediate representation

Returns:
Union[ir.Expression, List[ir.Expression], Any]

intermediate representation of input