Re: infinite loop in spice parser

al davis <[email protected]>
Newsgroups gmane.comp.gnu.gnucap.devel
Message-ID <[email protected]>
Thanks for the bug report.


On Friday 29 March 2013, Felix Salfelder wrote:
> Hi Al, hi list.
> 
> playing with spicelib, i found the parser hanging at
> gnucap-spice>C1 0 1 2;
> 
> while its not exceptionally clever to place that semicolon,
> it's still a gnucap bug.
> 
> i fixed it with
> 
>      cmd >> node_name;
> +    if(spots.back() == cmd.cursor()) {
> +      throw Exception("what's this?");
> +    }
>      spots.push_back(cmd.cursor());

The usual gnucap way to handle that would be:

    unsigned here = cmd.cursor();
    cmd >> node_name;
    if (cmd.stuck(&here)) {
.....

your way works too.

Having opened this one up .. What does Spice (NGspice?) do?

How does Spice (any of them) handle a semicolon?

What should it do?

Does that spice use a semicolon to introduce a comment?

It seems to me that perhaps the semicolon should be treated as 
"end of statement", so perhaps ...

      num_nodes = i;
      break;
    }else if (cmd.is_end()) {
      // found the end, no '='

should be 

      num_nodes = i;
      break;
    }else if (cmd.skip1b(';') || cmd.is_end()) {
      // found the end, no '='

??

It still needs the check for "stuck".


For readers who don't understand that code, wonder what it does 
...

Consider, in spice format, the line:

X1 a b c d e f g h i j

Which are nodes?  subckt name?  parameters?

Good luck.

How about 

X1 a b c d e=f g=h i=j

ok .. now we can tell "d" is the subckt name, a,b,c are nodes 
....

this function is the one to figure that out.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.