::SpiceGenTcl::NgspiceTop, Main, Index
ClassesTop, Main, Index
NgspiceParser [::SpiceGenTcl::Ngspice]Top, Main, Index
Method summary
constructor | Constructor for the class. |
buildTopNetlist | See ::SpiceGenTcl::Parser.buildTopNetlist |
configure | Configure properties. |
readAndParse | See ::SpiceGenTcl::Parser.readAndParse |
readFile | Reads netlist file and prepare for parsing: remove redundant white space characters, collapse continuation lines and remove comments lines. |
Properties
Readable: -definitions
, -filepath
, -parsername
, -topnetlist
Writable: -definitions
, -filepath
, -parsername
, -topnetlist
Superclasses
constructor [::SpiceGenTcl::Ngspice::NgspiceParser]NgspiceParser, Top, Main, Index
Creates object of class Parser
that do parsing of valid Ngspice netlist.
NgspiceParser create OBJNAME name filepath
NgspiceParser new name filepath
NgspiceParser new name filepath
Details
Parameters
name | Name of the object. |
filepath | Path to file that should be parsed. |
method constructor {name filepath} { # Creates object of class `Parser` that do parsing of valid Ngspice netlist. # name - name of the object # filepath - path to file that should be parsed set ElemsMethods [dcreate b CreateBehSource c CreateCap d CreateDio e CreateVCVS f CreateCCCS g CreateVCCS h CreateCCVS i CreateVIsource j CreateJFET k CreateCoupling l CreateInd m CreateMOSFET n CreateVerilogA q CreateBJT r CreateRes s CreateVSwitch v CreateVIsource w CreateCSwitch x CreateSubcktInst z CreateMESFET] set DotsMethods [dcreate ac CreateAc dc CreateDc func CreateFunc global CreateGlobal ic CreateIc include CreateInclude model CreateModel nodeset CreateNodeset op CreateOp options CreateOptions option CreateOptions opt CreateOptions param CreateParam temp CreateTemp tran CreateTran params CreateParam lib CreateLib sens CreateSens sp CreateSp save CreateSave] set SupModelsTypes {r c l sw csw d npn pnp njf pjf nmf pmf} set NamespacePath ::SpiceGenTcl::Ngspice next $name $filepath }
readFile [::SpiceGenTcl::Ngspice::NgspiceParser]NgspiceParser, Top, Main, Index
Reads netlist file and prepare for parsing: remove redundant white space characters, collapse continuation lines and remove comments lines
OBJECT readFile
Details
method readFile {} { # Reads netlist file and prepare for parsing: remove redundant white space characters, collapse continuation # lines and remove comments lines set file [open [my configure -filepath] r] set fileData [split [read $file] "\n"] close $file set fileData [lrange $fileData 1 end] # replace all sequences of white space characters with single space character foreach line $fileData { set processedLine [regsub -all {[[:space:]]+} [string trim $line] { }] if {$processedLine ne {}} { lappend lines $processedLine } } # find continuations and move them to line that is the start of continuation set fileData $lines set contFlag false # create a dictionary like `2 {3 4 5} 6 {7} 8 {} 9 {} 10 {} {11 12} 13 {}...` where keys are start lines, # indexes and values are the lists of lines indexes that are the continuation of the line with key index # also, skip the first line of the netlist for {set i 0} {$i<[llength $fileData]} {incr i} { set line [@ $fileData $i] if {[string index $line 0] eq "+"} { if {$contFlag} { ##nagelfar variable startIndex dict lappend continLinesIndex $startIndex $i continue } dict append continLinesIndex [= {$i-1}] set startIndex [= {$i-1}] dict lappend continLinesIndex $startIndex $i set contFlag true } else { set contFlag false dict append continLinesIndex $i } } # append continuation lines to start line of each continuation list with first symbol removal (it is assumed # to be `+` symbol) dict map {lineIndex contLinesIndexes} $continLinesIndex { if {$contLinesIndexes eq {}} { lappend finalList [@ $fileData $lineIndex] } else { set locList [@ $fileData $lineIndex] foreach contLineIndex $contLinesIndexes { lappend locList [string trim [string range [@ $fileData $contLineIndex] 1 end]] } lappend finalList [join $locList] } } # convert each line to lower case except lines that contains paths in .lib or .include statements foreach line $finalList { set tempLine [string tolower $line] if {[regexp {^\.(include|lib).*} $tempLine]} { lappend tempList $line } else { lappend tempList $tempLine } } set finalList $tempList unset tempList # remove all comments that start with `*` symbol set finalList [lsearch -all -inline -not -glob $finalList {\**}] # remove all end of line comments that starts with symbols \;, \$ and // foreach line $finalList { if {[set index [string first {;} $line]]!=-1} { set line [string trim [string range $line 0 [= {$index-1}]]] } elseif {[set index [string first {$} $line]]!=-1} { set line [string trim [string range $line 0 [= {$index-1}]]] } elseif {[set index [string first {//} $line]]!=-1} { set line [string trim [string range $line 0 [= {$index-1}]]] } lappend tempList $line } set finalList $tempList # remove control section that starts with .control and ends with .endc for {set i 0} {$i<[llength $finalList]} {incr i} { set line [@ $finalList $i] if {[regexp {^\.control\s?} $line]} { set controlStart $i } elseif {[regexp {^\.endc\s?} $line]} { set controlEnd $i } if {[info exists controlStart] && [info exists controlEnd]} { break } } if {[info exists controlStart] && [info exists controlEnd]} { set finalList [lreplace $finalList $controlStart $controlEnd] } # remove spaces after `{` and before `}`, replace `= `, ` = ` and ` =` with single `=` foreach line $finalList { lappend finalList1 [string map [list "\{ " "\{" " \}" "\}" " = " "=" " =" "=" "= " "="] $line] } set FileData $finalList1 return }