11.1.10.8. Parser

This module implements a partial SPICE netlist parser.

See the cir2py tool for an example of usage of the parser.

It would be difficult to implement a full parser for Ngspice since the syntax is mainly contextual.

class PySpice.Spice.Parser.Comment(line, statement=None)[source]

Bases: PySpice.Spice.Parser.Statement

class PySpice.Spice.Parser.Element(line)[source]

Bases: PySpice.Spice.Parser.Statement

This class implements an element definition.

“{ expression }” are allowed in device line.

property name

Name of the element

class PySpice.Spice.Parser.Include(line)[source]

Bases: PySpice.Spice.Parser.Statement

This class implements a include definition.

class PySpice.Spice.Parser.Line(line, line_range, end_of_line_comment)[source]

Bases: object

This class implements a line in the netlist.

lower_case_statement(statement)[source]

Lower case the statement

read_words(start_location, number_of_words)[source]

Read a fixed number of words separated by space.

split_line(keyword)[source]

Split the line according to the following pattern:

keyword parameter1 parameter2 ... key1=value1 key2=value2 ...

Return the list of parameters and the dictionary.

class PySpice.Spice.Parser.Model(line)[source]

Bases: PySpice.Spice.Parser.Statement

This class implements a model definition.

Spice syntax:

.model mname type (pname1=pval1 pname2=pval2)
property name

Name of the model

exception PySpice.Spice.Parser.ParseError[source]

Bases: NameError

class PySpice.Spice.Parser.PrefixData(prefix, classes)[source]

Bases: object

This class represents a device prefix.

class PySpice.Spice.Parser.SpiceParser(path=None, source=None, end_of_line_comment='$', '//', ';')[source]

Bases: object

This class parse a Spice netlist file and build a syntax tree.

Public Attributes:

circuit

models

subcircuits

build_circuit(ground=0)[source]

Build a Circuit instance.

Use the ground parameter to specify the node which must be translated to 0 (SPICE ground node).

class PySpice.Spice.Parser.Statement(line, statement=None)[source]

Bases: object

This class implements a statement, in fact a line in a Spice netlist.

class PySpice.Spice.Parser.SubCircuitStatement(line)[source]

Bases: PySpice.Spice.Parser.Statement

This class implements a sub-circuit definition.

Spice syntax:

.SUBCKT name node1 ... param1=value1 ...
append(statement)[source]

Append a statement to the statement’s list.

property name

Name of the sub-circuit.

property nodes

Nodes of the sub-circuit.

class PySpice.Spice.Parser.Title(line)[source]

Bases: PySpice.Spice.Parser.Statement

This class implements a title definition.