11.1.12.6.2. Parser

This module implements a parser for Spice expressions.

class PySpice.Spice.Expression.Parser.Parser[source]

Bases: object

p_binary_operation(p)[source]

expression : expression POWER expression | expression MULTIPLY expression | expression DIVIDE expression | expression MODULO expression | expression INT_DIVIDE expression | expression PLUS expression | expression MINUS expression | expression EQUAL expression | expression NOT_EQUAL expression | expression LESS expression | expression GREATER expression | expression LESS_EQUAL expression | expression GREATER_EQUAL expression | expression AND expression | expression OR expression

p_error(p)[source]
p_float(p)[source]

constant : NUMBER

p_if(p)[source]

expression : expression IF expression COLON expression

p_statement(t)[source]

statement : expression

p_unnary_operation(p)[source]

expression : MINUS expression | NOT expression

p_value(p)[source]

expression : variable | constant

p_variable(p)[source]

variable : NAME

parse(text)[source]
precedence = (('left', 'IF'), ('left', 'OR'), ('left', 'AND'), ('left', 'GREATER', 'LESS', 'GREATER_EQUAL', 'LESS_EQUAL', 'NOT_EQUAL', 'EQUAL'), ('left', 'MINUS', 'PLUS'), ('left', 'INT_DIVIDE', 'MODULO', 'DIVIDE', 'MULTIPLY'), ('left', 'POWER'), ('left', 'NOT'))
reserved = {}
start = 'statement'
t_AND = '&&'
t_COLON = ':'
t_DIVIDE = '/'
t_EQUAL = '=='
t_GREATER = '>'
t_GREATER_EQUAL = '>='
t_IF = '\\?'
t_INT_DIVIDE = '\\/'
t_LEFT_PARENTHESIS = '\\('
t_LESS = '<'
t_LESS_EQUAL = '<='
t_MINUS = '-'
t_MODULO = '%'
t_MULTIPLY = '\\*'
t_NAME(t)[source]

[a-zA-Z_][a-zA-Z_0-9]*

t_NOT = '!'
t_NOT_EQUAL = '!='
t_NUMBER(t)[source]

d+.d+(e(+|-)?(d+))? | d+.(e(+|-)?(d+))? | .d+(e(+|-)?(d+))? | d+

t_OR = '\\|\\|'
t_PLUS = '\\+'
t_POWER = '\\*\\*'
t_RIGHT_PARENTHESIS = '\\)'
t_SEMICOLON = ';'
t_SET = '='
t_error(token)[source]
t_ignore = ' \t'
t_ignore_COMMENT = '\\#[^\\n]*'
t_newline(t)[source]

r?n+

test_lexer(text)[source]
tokens = ['NAME', 'NUMBER', 'SEMICOLON', 'LEFT_PARENTHESIS', 'RIGHT_PARENTHESIS', 'SET', 'NOT', 'POWER', 'MULTIPLY', 'DIVIDE', 'INT_DIVIDE', 'MODULO', 'PLUS', 'MINUS', 'EQUAL', 'NOT_EQUAL', 'LESS', 'GREATER', 'LESS_EQUAL', 'GREATER_EQUAL', 'AND', 'OR', 'IF', 'COLON']