SLiCAPyacc.py

addParDefsParam(parName, parDict)

Adds a the definition of a global parameter (from SLiCAP.lib or from a user library) and, recursively, the parameters from its expression to the dictionary parDict.

Parameters

parName (sympy.Symbol, or str.) – Name of the parameter.

Returns

parDict

Return type

dict

checkCircuit(fileName)

Main function for checking a netlist and converting it into a ‘flattened’ circuit object.

PASS 1: Tokenize and parse the netlist to a nested circuit object

PASS 2: Complete all data, include libraries and replace models and circuits to be expanded with thei prototype circuit

PASS 3: Expand subcircuits and models using their prototypes

PASS 4: Complete data for instructions

Parameters

fileName (str) – Name of the netlist file, residing in the .cir subdirectory of the product folder.

Returns

Circuit object

Return type

SLiCAPprotos.circuit

checkElementModel(circuitObject)
Checks:
  1. If the element has a correct model definition

  2. If the model parameters correspond with those of the prototype model

  3. If the use of the Laplace variable in expressions is allowed.

If the element model is not a built-in model, and the model definition is not included in the circuit, the definition will be taken from a library file.

If the element model is not given the default device model will be used.

If the element is not a subcircuit, the model attribute will be set to that basic model (e.g. ‘Q2N3904’ will be replaced with ‘Q’), and model parameters that have not been defined will obtain their default value.

If the element is a subcircuit model parameters that have not been defined with the call will obtain their default value.

Parameters

circuitObject (SLiCAP circuit object) – Circuit object to be checked.

Returns

None

Return type

NoneType

checkElementModelParams(circuitObject, el)

Checks the model parameters used in elements that are not subcircuits (X). If the model parameters correspond with those of the prototype, the values will be passed to the instance of the prototype. if no values are given with the element, default values of the prototype will be used.

If the model requires expansion then its model attribute will be replaced with its prototype subcircuit.

Parameters
Returns

circuit object with updated element el.

Return type

SLiCAPprotos.circuit

checkElementReferences(circuitObject)

Checks if referenced elements exist in the circuit.

Parameters

circuitObject (SLiCAP circuit object) – Circuit object to be checked.

checkModelDefs(circuitObject)

Checks if the parameters given with a model statement (.model line) correspond with those of the model definition.

Parameters

circuitObject (SLiCAP circuit object) – Circuit object to be checked.

Returns

None

Return type

NoneType

checkReferences(circuitObject)

Second pass of the parser:

  1. Check if the referenced elements exsist in the circuit

  2. Check if the parameters of a model correspond with those of its basic model, if so, the model name is replaced with the model definition.

  3. Check if the model definitions of the elements are correct and can be found. If so, the model name in a model definition (.model netlist entry) is replaced with its definition.

  4. Check if the element parameters correspond with those of the model.

Parameters

circuitObject (SLiCAP circuit object) – Circuit object to be checked.

Returns

None

Return type

NoneType

checkSubCircuitElementModelParams(circuitObject, el)

Checks the model parameters of subcircuit elements (X). If the model parameters correspond with those of the prototype, the values will be passed to the instance of the prototype. if no values are given with the element, default values of the prototype will be used.

The model attribute will be replaced with its prototype subcircuit.

Parameters
Returns

circuit object with updated element el.

Return type

SLiCAPprotos.circuit

compileSLiCAPLibraries()

Compiles the SLiCAP bult-in libraries and writes the subcircuit, models, and global parameters to SLiCAPCIRCUITS, SLiCAPMODELS, and SLiCAPPARAMS, respectively.

Returns

None

Return type

NoneType

compileUSERLibrary(fileName)

Parses a user library file and writes the subcircuit, models, and global parameters to USERCIRCUITS, USERPMODELS, and USERPARAMS, respectively.

Parameters

fileName (str) – Path of the library file

Returns

None

Return type

NoneType

createDepVarIndex(circuitObject)

Creates an index dict for the dependent variables, this easies the construction of the matrix.

Parameters

circuitObject (SLiCAPprotos.circuit) – Circuit object to be updated

Returns

SLiCAP circuit object

Return type

SLiCAP circuit object

expandCircuit(circuitObject)

This functions flattens the hierarchy of circuitObject:

  1. Sub circuits and model expansions will be expanded and connected to the main circuit

  2. Parameter definitions will be updated:

Parameters

circuitObject – SLiCAP circuit object to be expanded

Returns

SLiCAP circuit object of the expanded circuit

Return type

SLiCAP circuit object

makeLibraries()
parseCommand(line, circuitDict={})

Parsing of a command the netlist to the active circuit object. The name of the active circuit object is the last name in the global CIRCUITNAMES: CIRCUITNAMES[-1]. The circuit object itself is stored in the dictionary CIRCUITS under this name: circuitDict[CIRCUITNAMES[-1]].

Parameters
  • circuitDict (dictionary) – Dictionary to which the definition will be written, defaults to CIRCUITS.

  • line (list with tokens) – list with tokens from a netlist line

Returns

Errors: number of errors found in this line.

Return type

Integer

parseElement(line, circuitDict={})

Parsing of an element line to the active circuit object. The name of the active circuit object is the last name in the global CIRCUITNAMES: CIRCUITNAMES[-1]. The circuit object itself is stored in the dictionary CIRCUITS under this name: circuitDict[CIRCUITNAMES[-1]].

Parameters
  • line (list with tokens) – list with tokens from a netlist line

  • circuitDict (dictionary) – Dictionary to which the definition will be written

Returns

Errors: number of errors found in this line.

Return type

Integer

parseLibrary(line, circuitDict={})

Parsing of a .include or .lib command. If the library exists and has not been called earlier, the path of the library will be stured in the list USERLIBS, and the library will be compiled (see: compileUSERLibrary()).

If the library does not exist the error count of the active circuit will be increased with one.

The name of the active circuit object is the last name in the global CIRCUITNAMES: CIRCUITNAMES[-1]. The circuit object itself is stored in the dictionary CIRCUITS under this name: circuitDict[CIRCUITNAMES[-1]].

  1. Check of the file exists at the first of the following locations:

    1. In the absolute path or path relative to the project directory

    2. In the circuit directory (ini.circuitPath)

    3. In the project library directory (ini.libraryPath)

  2. Add the definitions of subcircuits, models and parameters to the globals USERCIRCUITS, USERMODELS, and USERPARAMS, respectively

Note: libraries are always global.

Parameters
  • line (list with tokens) – list with tokens from a netlist line

  • circuitDict (dictionary) – Dictionary to which the definition will be written, defaults to CIRCUITS.

Returns

Errors: number of errors found in this line.

Return type

Integer

parseNetlist(netlist, cirName='main', circuitDict={})

Netlist parser: converts a netlist to the active circuit object. The name of the active circuit object is the last name in the global CIRCUITNAMES: CIRCUITNAMES[-1]. The circuit object itself is stored in the dictionary CIRCUITS under this name: circuitDict[CIRCUITNAMES[-1]].

Parameters
  • netlist (String) – Netlist of the circuit

  • cirName (String (no whitespace characters)) – Name of the (sub)circuit, defaults to ‘main’

  • circuitDict (dictionary) – Dictionary to which the definition will be written

Returns

None

Return type

Nonetype

parseSubcircuitElement(line, circuitDict={})

Parsing of a subcircuit call (an X element) in the netlist in the active circuit object. The name of the active circuit object is the last name in the global CIRCUITNAMES: CIRCUITNAMES[-1]. The circuit object itself is stored in the dictionary CIRCUITS under this name: circuitDict[CIRCUITNAMES[-1]].

Parameters
  • line (list with tokens) – list with tokens from a netlist line

  • circuitDict (dictionary) – Dictionary to which the definition will be written, defaults to CIRCUITS.

Returns

Errors: number of errors found in this line.

Return type

Integer

updateCirData(circuitObject)

Updates data of the main expanded circuit required for instructions.

  • Updates the lists with dependent variables (detectors), sources (independent variables) and controlled sources (possible loop gain references).

  • If global parameters are used in the circuit, their definition is added to the ‘.parDefs’ attribute of the circuit.

  • Checks if the global ground node ‘0’ is used in the circuit.

  • Checks if the circuit has at least two nodes.

  • Checks if the referenced elements exist.

  • Converts circuitObject.params into list and puts the undefined parameters in it

Parameters

circuitObject (SLiCAPprotos.circuit) – Circuit object to be updated

Returns

Updated circuit object

Return type

SLiCAPprotos.circuit

updateElementParams(newElement, parentParams, prototypeParams, parentRefDes)

After expansion of the elements, the element parameters can be: ‘value’ ‘noise’ ‘dc’ ‘dcvar’ ‘noisetemp’ ‘noiseflow’

The values of these parameters are symbolic expressions. The atoms of these expressions are parameters. The update procedure is as follows:

  1. If the parameter is a parameter of the parent circuit, then it needs to obtain the value given with the parent circuit.

  2. Else if the parameter is a parameter of the prototype circuit, then it needs to obtain the value given with the prototype circuit

  3. Else if the parameter is defined in a user library (in USERPARAMS), then the definition from this library needs to be added to the parameter definitions of the parent circuit.

  4. Else if the parameter is defined in a system library (in SLiCAPPARAMS), then the definition from this library needs to be added to the parameter definitions of the parent circuit.

  5. Else: the parameter name will receive the postfix: _<parentRefDes)>.

Parameters
  • newElement (SLiCAPprotos.element) – Element of the subciorcuit that needs to be connected to the parent circuit.

  • parentParams

    Dictionary with key-value pairs of parameters of the parent element:

    • key str: name of the parameter

    • value: SympyExpression: value or expression of this parameter

  • prototypeParams

    Dictionary with key-value pairs of parameters of the prototype circuit:

    • key str: name of the parameter

    • value: SympyExpression: value or expression of this parameter

  • parentRrefDes – Reference designator of the parent element

Returns

newElement with updated node list

Return type

SLiCAPprotos.element

updateNodes(newElement, parentNodes, prototypeNodes, parentRefDes)

Determines the nodes of a subcircuit element.

  1. If the node is in de node list of the prototype circuit, it is replaced with the corresponding (same index) node of the parent element.

  2. If this is not the case, the node is an interbal node and it will receive the name of the node of the pprototype circuit with the postfix _<refDes of parent element>.

Parameters
  • newElement (SLiCAPprotos.element) – Element of the subciorcuit that needs to be connected to the parent circuit.

  • parentNodes (list) – Node list of the parent element.

  • prototypeNodes (list) – Node list of the prototype expansion (circuit)

  • parentRrefDes – Reference designator of the parent element

Returns

newElement with updated node list

Return type

SLiCAPprotos.element

updateParDefs(parentParDefs, childParDefs, parentParams, prototypeParams, parentRefDes)

The parameter definitions of the parent circuit will be updated:

Parameters of the child circuit as well as parameters in their expressions will be treated as follows:

  1. If the parameter is a parameter of the parent circuit, then it needs to obtain the value given with the parent circuit.

  2. Else if the parameter is a parameter of the prototype circuit, then it needs to obtain the value given with the prototype circuit

  3. Else if the parameter is defined in a user library (in USERPARAMS), then the definition from this library needs to be added to the parameter definitions of the parent circuit.

  4. Else if the parameter is defined in a system library (in SLiCAPPARAMS), then the definition from this library needs to be added to the parameter definitions of the parent circuit.

  5. Else: the parameter name will receive the postfix: _<parentRefDes)>.

Parameters
  • newElement (SLiCAPprotos.element) – Element of the subciorcuit that needs to be connected to the parent circuit.

  • parentParams

    Dictionary with key-value pairs of parameters of the parent element:

    • key str: name of the parameter

    • value: SympyExpression: value or expression of this parameter

  • prototypeParams

    Dictionary with key-value pairs of parameters of the prototype circuit:

    • key str: name of the parameter

    • value: SympyExpression: value or expression of this parameter

  • parentRrefDes – Reference designator of the parent element

Returns

newElement with updated node list

Return type

SLiCAPprotos.element