TheVirtualBrain:

TheDocumentationwebsite.

Table Of Contents

Previous topic

model Package

Next topic

run Package

This Page

parser Package

@author: Gautham Ganapathy @organization: LEMS (http://neuroml.org/lems/, https://github.com/organizations/LEMS) @contact: gautham@lisphacker.org

LEMS

expr

Expression parser

@author: Gautham Ganapathy @organization: LEMS (http://neuroml.org/lems/, https://github.com/organizations/LEMS) @contact: gautham@lisphacker.org

MV: added pow(f,l) function for c translations

class tvb.dsl_cuda.lems.parser.expr.ExprNode(type)[source]

Bases: lems.base.base.LEMSBase

Base class for a node in the expression parse tree.

FUNC1 = 3
OP = 1
VALUE = 2
type = None

Node type. @type: enum(ExprNode.OP, ExprNode.VALUE)

class tvb.dsl_cuda.lems.parser.expr.ExprParser(parse_string)[source]

Bases: lems.base.base.LEMSBase

Parser class for parsing an expression and generating a parse tree.

cleanup_stacks()[source]
debug = False
depth = 0

Dictionary mapping operators to their priorities. @type: dict(string -> Integer)

is_func(str)[source]

Checks if a token string contains a function.

@param str: Token string to be checked. @type str: string

@return: True if the token string contains a function. @rtype: Boolean

is_op(str)[source]

Checks if a token string contains an operator.

@param str: Token string to be checked. @type str: string

@return: True if the token string contains an operator. @rtype: Boolean

is_sym(str)[source]

Checks if a token string contains a symbol.

@param str: Token string to be checked. @type str: string

@return: True if the token string contains a symbol. @rtype: Boolean

MV: Added the part to recognize ** for power

make_op_node(op, right)[source]
op_priority = {'$': -5, 'func': 8, '**': 6, '+': 5, '-': 5, '*': 6, '/': 6, '^': 7, '~': 8, 'exp': 8, '.and.': 1, '.or.': 1, '.gt.': 2, '.ge.': 2, '.geq.': 2, '.lt.': 2, '.le.': 2, '.eq.': 2, '.neq.': 2, '.ne.': 2}
parse()[source]

Tokenizes and parses an arithmetic expression into a parse tree.

@return: Returns a token string. @rtype: lems.parser.expr.ExprNode

parse2()[source]
parse_string = None

Expression to be parsed. @type: string

parse_token_list_rec(min_precedence)[source]

Parses a tokenized arithmetic expression into a parse tree. It calls itself recursively to handle bracketed subexpressions.

@return: Returns a token string. @rtype: lems.parser.expr.ExprNode

@attention: Does not handle unary minuses at the moment. Needs to be fixed.

priority(op)[source]
token_list = None

List of tokens from the expression to be parsed. @type: list(string)

tokenize()[source]

Tokenizes the string stored in the parser object into a list of tokens.

class tvb.dsl_cuda.lems.parser.expr.Func1Node(func, param)[source]

Bases: tvb.dsl_cuda.lems.parser.expr.ExprNode

Unary function node in an expression parse tree. This will always be a non-leaf node.

func = None

Funcion stored in this node. @type: string

param = None

Parameter. @type: lems.parser.expr.ExprNode

to_python_expr()[source]
class tvb.dsl_cuda.lems.parser.expr.OpNode(op, left, right)[source]

Bases: tvb.dsl_cuda.lems.parser.expr.ExprNode

Operation node in an expression parse tree. This will always be a non-leaf node.

left = None

Left operand. @type: lems.parser.expr.ExprNode

op = None

Operation stored in this node. @type: string

right = None

Right operand. @type: lems.parser.expr.ExprNode

to_python_expr()[source]
class tvb.dsl_cuda.lems.parser.expr.ValueNode(value)[source]

Bases: tvb.dsl_cuda.lems.parser.expr.ExprNode

Value node in an expression parse tree. This will always be a leaf node.

clean_up()[source]

To make sure an integer is returned as a float. No division by integers!!

to_python_expr()[source]
value = None

Value to be stored in this node. @type: string