From 62471ecede31b358afaa5dd1bcec70b97330dd1c Mon Sep 17 00:00:00 2001 From: Giles Atkinson <“gatk555@gmail.com”> Date: Tue, 12 Sep 2023 08:18:19 +0100 Subject: [PATCH] Fix two bugs in cmpp: an unmatched right bracket in cfunc.mod causes an infinite parsing loop (mod_yacc.y) and XSPICE macros are replaced in string literals (mod_lex.l). --- src/xspice/cmpp/mod_lex.l | 2 ++ src/xspice/cmpp/mod_yacc.y | 17 ++++++----------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/xspice/cmpp/mod_lex.l b/src/xspice/cmpp/mod_lex.l index 444a7d2ba..fbb86eb5b 100644 --- a/src/xspice/cmpp/mod_lex.l +++ b/src/xspice/cmpp/mod_lex.l @@ -89,6 +89,8 @@ Z [0-9A-Za-z_] } while (ch != '\n'); } +\"(\\.|[^"\\])*\" {return TOK_IDENTIFIER;} /* Literal string. */ + ARGS {return TOK_ARGS;} INIT {return TOK_INIT;} CALLBACK {return TOK_CALLBACK;} diff --git a/src/xspice/cmpp/mod_yacc.y b/src/xspice/cmpp/mod_yacc.y index 4d3e00aa3..92433aca4 100644 --- a/src/xspice/cmpp/mod_yacc.y +++ b/src/xspice/cmpp/mod_yacc.y @@ -31,20 +31,13 @@ SUMMARY INTERFACES mod_yyparse() - Function 'yyparse()' is generated automatically - by UNIX 'yacc' utility and then converted to - 'mod_yyparse()' by UNIX 'sed' utility under - direction of Makefile. + by UNIX 'yacc' utility. All yy* global names + are converted to mod_yy* by #define. REFERENCED FILES mod_lex.l -NON-STANDARD FEATURES - - Names of functions generated by 'yacc' are translated by 'sed' - under direction of the Makefile to prevent collisions with - functions generated from ifs_yacc.y. - ============================================================================*/ @@ -388,8 +381,8 @@ mod_file : /* empty */ c_code : /* empty */ | c_code c_char | c_code macro - /*| TOK_RPAREN {yyerror ("Unmatched )"); YYERROR;} - | TOK_RBRACKET {yyerror ("Unmatched ]"); YYERROR;}*/ + | TOK_RPAREN {yyerror ("Unmatched )"); YYERROR;} + | TOK_RBRACKET {yyerror ("Unmatched ]"); YYERROR;} ; buffered_c_code : {init_buffer();} buffered_c_code2 @@ -416,10 +409,12 @@ buffered_c_char : TOK_IDENTIFIER {append (mod_yytext);} c_char : TOK_IDENTIFIER {fputs (mod_yytext, mod_yyout);} | TOK_MISC_C {fputs (mod_yytext, mod_yyout);} | TOK_COMMA {fputs (mod_yytext, mod_yyout);} + | TOK_LBRACKET TOK_RBRACKET {fputs ("[]", mod_yyout);} | TOK_LBRACKET {putc ('[', mod_yyout);} c_code TOK_RBRACKET {putc (']', mod_yyout);} + | TOK_LPAREN TOK_RPAREN {fputs ("()", mod_yyout);} | TOK_LPAREN {putc ('(', mod_yyout);} c_code TOK_RPAREN