BELFEM 0.9.0
Berkeley Lab Finite Element Framework
Loading...
Searching...
No Matches
belfem::electronics::NetlistParser Class Reference

Lexes an ngspice netlist into the intermediate representation the NgspiceCircuitFactory consumes ( todo/ngspice_parser_plan.md §9.1 ). More...

#include <cl_NetlistParser.hpp>

Public Member Functions

 NetlistParser (const string &aPath)
 lex a netlist file from disk
 NetlistParser (const Cell< string > &aLines, const string &aSource="<memory>")
 lex an in-memory netlist ( unit tests ); aLines are the physical lines including the title line
 ~NetlistParser ()=default
const stringtitle () const
const stringsource () const
 the path or "<memory>" label errors are reported under
const Cell< NetlistElement > & elements () const
const Cell< NetlistModel > & models () const
const Cell< NetlistControl > & controls () const
const Cell< NetlistDirective > & directives () const
const Cell< string > & node_names () const
 distinct node names in order of first appearance – the factory's packing order ( ground moves to the last index there, not here )
bool has_end () const
 true if the deck carried an explicit .end

Detailed Description

Lexes an ngspice netlist into the intermediate representation the NgspiceCircuitFactory consumes ( todo/ngspice_parser_plan.md §9.1 ).

Handled here: the mandatory title line ( always consumed, never parsed ); full-line '' comments; "</em> belfem:" directives ( single line, recognized before the comment strip, whitespace tolerated before the colon ); end-of-line comments ';', '$' and token-leading '//' ( PSPICE compatibility decks, where '$' is an ordinary character, are not supported ); leading '+' continuations; '(' ')' ',' normalized to spaces and whitespace around '=' removed before tokenizing; case-folding of every identifier; ".end" ( exactly that token – trailing tokens hard-error ) after which remaining lines are ignored; the ordered first-appearance node-name list ( restart contract O9 ), including nodes introduced only by a directive's n+/n- keys.

Two deliberate BELFEM extensions beyond the manual's strict wording ( the manual both demands that continuations "immediately follow" and declares empty lines ignored and comment lines legal anywhere ): comment and blank lines may sit between a card and its '+' continuation, and EOF terminates a deck that has no ".end". Both accept strictly more than stock ngspice and never reinterpret a deck ngspice accepts. A "* belfem:" DIRECTIVE is a statement, not a comment: it completes the pending card ( so node collection follows line order, O9 ) and ends the continuation chain.

Hard errors ( BELFEM_ERROR, each naming source, line and card ): unsupported element letters – controlled switches S/W ( use the "* belfem: switch" directive ), subcircuit instances X, and every other letter beyond R/C/L/V/I/D; every control card except ".model", ".tran" and ".end" ( .subckt/.control/.ac/.dc/.op/ .param/.ic/... – v1 refuses rather than silently altering the deck, plan §12.2 ); a continuation with no card to continue; an element card with fewer than two nodes; a deck with no cards.

Parameter-level policy ( e.g. rejecting "ic=" on a supported card ) is deliberately NOT enforced here – the factory owns card semantics.

Constructor & Destructor Documentation

◆ NetlistParser() [1/2]

belfem::electronics::NetlistParser::NetlistParser ( const string & aPath)

lex a netlist file from disk

◆ NetlistParser() [2/2]

belfem::electronics::NetlistParser::NetlistParser ( const Cell< string > & aLines,
const string & aSource = "<memory>" )

lex an in-memory netlist ( unit tests ); aLines are the physical lines including the title line

◆ ~NetlistParser()

belfem::electronics::NetlistParser::~NetlistParser ( )
default

Member Function Documentation

◆ controls()

const Cell< NetlistControl > & belfem::electronics::NetlistParser::controls ( ) const
inline

◆ directives()

const Cell< NetlistDirective > & belfem::electronics::NetlistParser::directives ( ) const
inline

◆ elements()

const Cell< NetlistElement > & belfem::electronics::NetlistParser::elements ( ) const
inline

◆ has_end()

bool belfem::electronics::NetlistParser::has_end ( ) const
inline

true if the deck carried an explicit .end

◆ models()

const Cell< NetlistModel > & belfem::electronics::NetlistParser::models ( ) const
inline

◆ node_names()

const Cell< string > & belfem::electronics::NetlistParser::node_names ( ) const
inline

distinct node names in order of first appearance – the factory's packing order ( ground moves to the last index there, not here )

◆ source()

const string & belfem::electronics::NetlistParser::source ( ) const
inline

the path or "<memory>" label errors are reported under

◆ title()

const string & belfem::electronics::NetlistParser::title ( ) const
inline

The documentation for this class was generated from the following files: