Skip to content

Commit

Permalink
Merge pull request #791 from in3otd/fix_sparams_parsing
Browse files Browse the repository at this point in the history
Use left recursion for parsing S-parameters files
  • Loading branch information
guitorri committed May 10, 2018
2 parents b4f27d9 + e29fd00 commit ccbf8cb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
1 change: 1 addition & 0 deletions qucs-core/src/check_touchstone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ using namespace qucs;

strlist * touchstone_idents = NULL;
dataset * touchstone_result = NULL;
qucs::vector * touchstone_line = NULL;
qucs::vector * touchstone_vector = NULL;

/* default touchstone options */
Expand Down
1 change: 1 addition & 0 deletions qucs-core/src/check_touchstone.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ namespace qucs {
}

extern qucs::dataset * touchstone_result;
extern qucs::vector * touchstone_line;
extern qucs::vector * touchstone_vector;
extern qucs::strlist * touchstone_idents;

Expand Down
32 changes: 19 additions & 13 deletions qucs-core/src/parse_touchstone.ypp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

#define YYERROR_VERBOSE 42
#define YYDEBUG 1
#define YYMAXDEPTH 1000000
//#define YYMAXDEPTH 1000000

#include "logging.h"
#include "complex.h"
Expand Down Expand Up @@ -76,36 +76,42 @@ Input:

OptionLine: /* option line */
'#' OptionList 'R' Float OptionList Eol {
touchstone_vector = NULL;
touchstone_line = NULL;
touchstone_options.resistance = $4;
}
| '#' OptionList Eol {
touchstone_vector = NULL;
touchstone_line = NULL;
touchstone_options.resistance = 50.0;
}
| Eol OptionLine { /* skip this line */ }
;

OptionList: /* nothing */ { }
| Option OptionList {
| OptionList Option {
if (touchstone_idents == NULL) touchstone_idents = new strlist ();
touchstone_idents->add ($1);
free ($1);
touchstone_idents->add ($2);
free ($2);
}
;

Dataset: /* nothing */ { }
| DataLine Eol Dataset { /* append vector lines */
$1->setNext (touchstone_vector);
touchstone_vector = $1;
| Dataset DataLine Eol { /* append vector lines */
if (!touchstone_vector)
touchstone_vector = $2; /* save first vector location */
if (touchstone_line)
touchstone_line->setNext($2);
touchstone_line = $2;
}
| DataLine { /* last line, no trailing end-of-line */
$1->setNext (touchstone_vector);
touchstone_vector = $1;
| Dataset DataLine { /* last line, no trailing end-of-line */
if (!touchstone_vector)
touchstone_vector = $2; /* save first vector location */
if (touchstone_line)
touchstone_line->setNext($2);
touchstone_line = $2;
logprint (LOG_ERROR, "line %d: no trailing end-of-line found, "
"continuing...\n", touchstone_lineno);
}
| Eol Dataset { /* skip this line */ }
| Dataset Eol { /* skip this line */ }
;

DataLine:
Expand Down

0 comments on commit ccbf8cb

Please sign in to comment.