From: Christos Zoulas Date: Thu, 5 Dec 2013 17:24:48 +0000 (-0500) Subject: Change the way we handle multiple lex scanners and yacc parsers X-Git-Url: https://git.fsl.cs.sunysb.edu/?a=commitdiff_plain;h=171fa0e08665ba3394bda271445d091c1001784f;p=am-utils-6.2.git Change the way we handle multiple lex scanners and yacc parsers in a single program. Our old patch to ylwrap does not work anymore because the bison parsers need shared symbols that start with yy and we can't easily select which ones work. So now we use -P and -p to let lex and yacc do the work for us. This requires a patch to ylwrap, but it is smaller. --- diff --git a/ChangeLog b/ChangeLog index e0cf3483..73201a4e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ + +2013-12-05 Christos Zoulas + + * Change the way we handle multiple lex scanners and yacc parsers + in a single program. Our old patch to ylwrap does not work anymore + because the bison parsers need shared symbols that start with yy + and we can't easily select which ones work. So now we use -P and + -p to let lex and yacc do the work for us. This requires a patch + to ylwrap, but it is smaller. + + +2013-12-05 Christos Zoulas + + * Change the way we handle multiple lex scanners and yacc parsers + in a single program. Our old patch to ylwrap does not work anymore + because the bison parsers need shared symbols that start with yy + and we can't easily select which ones work. So now we use -P and + -p to let lex and yacc do the work for us. This requires a patch + to ylwrap, but it is smaller. + 2013-05-14 Christos Zoulas * update to handle new autoconf and regen files diff --git a/amd/conf_tok.l b/amd/conf_tok.l index fb97f865..ccfe0946 100644 --- a/amd/conf_tok.l +++ b/amd/conf_tok.l @@ -132,19 +132,19 @@ NONQUOTE [^\"] \[ { dprintf("%8d: Left bracket \"%s\"\n", yytext); - yylval.strtype = xstrdup(yytext); + conf_lval.strtype = xstrdup(yytext); amu_return(LEFT_BRACKET); } \] { dprintf("%8d: Right bracket \"%s\"\n", yytext); - yylval.strtype = xstrdup(yytext); + conf_lval.strtype = xstrdup(yytext); amu_return(RIGHT_BRACKET); } = { dprintf("%8d: Equal \"%s\"\n", yytext); - yylval.strtype = xstrdup(yytext); + conf_lval.strtype = xstrdup(yytext); amu_return(EQUAL); } @@ -160,7 +160,7 @@ NONQUOTE [^\"] {NONWSCHAR}{NONWSCHAR}* { dprintf("%8d: Non-WS string \"%s\"\n", yytext); - yylval.strtype = xstrdup(yytext); + conf_lval.strtype = xstrdup(yytext); amu_return(NONWS_STRING); } @@ -168,13 +168,13 @@ NONQUOTE [^\"] dprintf("%8d: QUOTED-Non-WS-EQ string \"%s\"\n", yytext); /* must strip quotes */ yytext[strlen((char *)yytext)-1] = '\0'; - yylval.strtype = xstrdup(&yytext[1]); + conf_lval.strtype = xstrdup(&yytext[1]); amu_return(QUOTED_NONWSEQ_STRING); } {NONWSEQCHAR}{NONWSEQCHAR}* { dprintf("%8d: Non-WS-EQ string \"%s\"\n", yytext); - yylval.strtype = xstrdup(yytext); + conf_lval.strtype = xstrdup(yytext); amu_return(NONWSEQ_STRING); } diff --git a/amd/sun_map_tok.l b/amd/sun_map_tok.l index 54e65ae4..74cb47b6 100644 --- a/amd/sun_map_tok.l +++ b/amd/sun_map_tok.l @@ -76,7 +76,7 @@ #endif /* FLEX_SCANNER */ int yylex(void); -int yyerror(const char *); +int sun_map_error(const char *); /* * We need to configure lex to parse from a string @@ -157,7 +157,7 @@ CONTINUE_REX "\\"\n {WORD_REX} { sun_map_tokpos += yyleng; - xstrlcpy((char *)yylval.strval,(const char *)yytext,sizeof(yylval.strval)); + xstrlcpy((char *)sun_map_lval.strval,(const char *)yytext,sizeof(sun_map_lval.strval)); return WORD; } @@ -189,7 +189,7 @@ CONTINUE_REX "\\"\n int -yyerror(const char* s) +sun_map_error(const char* s) { return 1; } diff --git a/bootstrap b/bootstrap index e614ff67..80bf9b28 100755 --- a/bootstrap +++ b/bootstrap @@ -50,35 +50,49 @@ fi echo "AMU: Fixing ylwrap..." patch << \EOF ---- ylwrap.orig 2013-05-14 20:00:39.000000000 -0400 -+++ ylwrap 2013-05-14 20:06:06.000000000 -0400 -@@ -199,8 +199,24 @@ - # include guards too. - FROM=`guard "$from"` - TARGET=`guard "$to"` -+ -+ prefix=`echo $input | sed \ -+ -e 's,^.*/,,g' \ -+ -e 's/_parse.[yl]$/_/g' \ -+ -e 's/_tok.[yl]$/_/g'` +--- ylwrap.orig 2013-12-02 19:42:59.239979147 -0500 ++++ ylwrap 2013-12-02 19:42:36.559379132 -0500 +@@ -96,6 +96,23 @@ + *[\\/]*) prog="`pwd`/$prog" ;; + esac + ++set -x ++prefix=`echo $input | sed \ ++ -e 's,^.*/,,g' \ ++ -e 's/_gram.[yl]$/_/g' \ ++ -e 's/_lex.[yl]$/_/g' \ ++ -e 's/_parse.[yl]$/_/g' \ ++ -e 's/_tok.[yl]$/_/g'` + -+ case $prefix in -+ *.y) -+ code_prefix="$(basename $prefix _gram.y)_yy";; -+ *.l) -+ code_prefix="$(basename $prefix _lex.l)_yy";; -+ *) -+ code_prefix="$prefix";; -+ esac ++case "$prog" in ++*lex) ++ flags="-P $prefix" ++ out="mv lex.$prefix.c lex.yy.c" ++ ;; ++yacc|bison) ++ flags="-p $prefix";; ++esac + - sed -e "/^#/!b" -e "s|$input_rx|$input_sub_rx|" -e "$rename_sed" \ -- -e "s|$FROM|$TARGET|" "$from" >"$target" || ret=$? -+ -e "s|$FROM|$TARGET|" "$from" | sed -e "s|yy|$code_prefix|g" > \ -+ "$target" || ret=$? + # FIXME: add hostname here for parallel makes that run commands on + # other machines. But that might take us over the 14-char limit. + dirname=ylwrap$$ +@@ -105,10 +122,13 @@ + cd $dirname + + case $# in +- 0) "$prog" "$input" ;; +- *) "$prog" "$@" "$input" ;; ++ 0) "$prog" $flags "$input" ;; ++ *) "$prog" $flags "$@" "$input" ;; + esac + ret=$? ++if [ -n "$out" ]; then ++ eval $out ++fi - # Check whether files must be updated. - if test "$from" != "$parser"; then -\EOF + if test $ret -eq 0; then + set X $pairlist +EOF # save timestamp echo "AMU: save timestamp..." diff --git a/fsinfo/fsi_lex.l b/fsinfo/fsi_lex.l index 4b1f445e..3282b244 100644 --- a/fsinfo/fsi_lex.l +++ b/fsinfo/fsi_lex.l @@ -115,7 +115,7 @@ static int ayylineno; int yywrap(void); #endif /* not yywrap or yylex */ -int yyerror(const char *, ...); +int fsi_error(const char *, ...); YYSTYPE yylval; static char *fsi_filename; @@ -180,7 +180,7 @@ struct r { [={}] { return *yytext; } \" { BEGIN Q; optr = ostr; quoted = 1; } -\n { ayylineno++; yyerror("\" expected"); BEGIN F; } +\n { ayylineno++; fsi_error("\" expected"); BEGIN F; } \\b { *optr++ = '\b'; /* escape */ } \\t { *optr++ = '\t'; /* escape */ } \\\" { *optr++ = '\"'; /* escape */ } @@ -190,7 +190,7 @@ struct r { \\n { *optr++ = '\n'; /* escape */ } \\f { *optr++ = '\f'; /* escape */ } "\\ " { *optr++ = ' '; /* force space */ } -\\. { yyerror("Unknown \\ sequence"); } +\\. { fsi_error("Unknown \\ sequence"); } ([ \t]|"\\\n"){2,} { char *p = (char *) yytext-1; while ((p = strchr(p+1, '\n'))) ayylineno++; } \" { BEGIN F; quoted = 0; *optr = '\0'; @@ -239,7 +239,7 @@ find_resword(char *s) int -yyerror(const char *fmt, ...) +fsi_error(const char *fmt, ...) { va_list ap; diff --git a/fsinfo/fsi_util.c b/fsinfo/fsi_util.c index 15440032..a90296b6 100644 --- a/fsinfo/fsi_util.c +++ b/fsinfo/fsi_util.c @@ -355,7 +355,7 @@ set_host(host *hp, int k, char *v) int m = 1 << k; if (hp->h_mask & m) { - fsi_yyerror("host field \"%s\" already set", host_strings[k]); + fsi_error("host field \"%s\" already set", host_strings[k]); return; } hp->h_mask |= m; @@ -367,7 +367,7 @@ set_host(host *hp, int k, char *v) dict_ent *de = dict_locate(dict_of_hosts, v); if (de) - fsi_yyerror("duplicate host %s!", v); + fsi_error("duplicate host %s!", v); else dict_add(dict_of_hosts, v, (char *) hp); hp->h_hostname = v; @@ -442,7 +442,7 @@ set_ether_if(ether_if *ep, int k, char *v) int m = 1 << k; if (ep->e_mask & m) { - fsi_yyerror("netif field \"%s\" already set", ether_if_strings[k]); + fsi_error("netif field \"%s\" already set", ether_if_strings[k]); return; } ep->e_mask |= m; @@ -452,7 +452,7 @@ set_ether_if(ether_if *ep, int k, char *v) case EF_INADDR:{ ep->e_inaddr.s_addr = inet_addr(v); if ((int) ep->e_inaddr.s_addr == (int) INADDR_NONE) - fsi_yyerror("malformed IP dotted quad: %s", v); + fsi_error("malformed IP dotted quad: %s", v); XFREE(v); } break; @@ -463,7 +463,7 @@ set_ether_if(ether_if *ep, int k, char *v) if ((sscanf(v, "0x%lx", &nm) == 1 || sscanf(v, "%lx", &nm) == 1) && nm != 0) ep->e_netmask = htonl(nm); else - fsi_yyerror("malformed netmask: %s", v); + fsi_error("malformed netmask: %s", v); XFREE(v); } break; @@ -485,7 +485,7 @@ set_disk_fs(disk_fs *dp, int k, char *v) int m = 1 << k; if (dp->d_mask & m) { - fsi_yyerror("fs field \"%s\" already set", disk_fs_strings[k]); + fsi_error("fs field \"%s\" already set", disk_fs_strings[k]); return; } dp->d_mask |= m; @@ -546,7 +546,7 @@ set_mount(fsi_mount *mp, int k, char *v) int m = 1 << k; if (mp->m_mask & m) { - fsi_yyerror("mount tree field \"%s\" already set", mount_strings[k]); + fsi_error("mount tree field \"%s\" already set", mount_strings[k]); return; } mp->m_mask |= m; @@ -590,7 +590,7 @@ set_fsmount(fsmount *fp, int k, char *v) int m = 1 << k; if (fp->f_mask & m) { - fsi_yyerror("mount field \"%s\" already set", fsmount_strings[k]); + fsi_error("mount field \"%s\" already set", fsmount_strings[k]); return; } fp->f_mask |= m; diff --git a/fsinfo/fsinfo.c b/fsinfo/fsinfo.c index b487861b..daec3870 100644 --- a/fsinfo/fsinfo.c +++ b/fsinfo/fsinfo.c @@ -258,7 +258,7 @@ main(int argc, char *argv[]) * Parse input */ show_area_being_processed("read config", 11); - if (fsi_yyparse()) + if (fsi_parse()) errors = 1; errors += file_io_errors + parse_errors; diff --git a/fsinfo/fsinfo.h b/fsinfo/fsinfo.h index 18baaf7b..59038ac3 100644 --- a/fsinfo/fsinfo.h +++ b/fsinfo/fsinfo.h @@ -104,9 +104,7 @@ extern void show_area_being_processed(char *area, int n); extern void show_new(char *msg); extern void warning(void); -extern int yyerror(const char *fmt, ...) - __attribute__((__format__(__printf__, 1, 2))); -extern int fsi_yyerror(const char *fmt, ...) +extern int fsi_error(const char *fmt, ...) __attribute__((__format__(__printf__, 1, 2))); extern void domain_strip(char *otherdom, char *localdom); /* @@ -117,8 +115,7 @@ extern void domain_strip(char *otherdom, char *localdom); #ifndef yywrap extern int yywrap(void); #endif /* not yywrap */ -extern int yyparse(void); -extern int fsi_yyparse(void); +extern int fsi_parse(void); extern int write_atab(qelem *q); extern int write_bootparams(qelem *q); extern int write_dumpset(qelem *q); @@ -127,8 +124,7 @@ extern int write_fstab(qelem *q); extern void col_cleanup(int eoj); extern void set_host(host *hp, int k, char *v); extern void set_ether_if(ether_if *ep, int k, char *v); -extern int yylex(void); -extern int fsi_yylex(void); +extern int fsi_lex(void); #define BITSET(m,b) ((m) |= (1<<(b))) diff --git a/fsinfo/null_lex.l b/fsinfo/null_lex.l index f756f561..46bb4638 100644 --- a/fsinfo/null_lex.l +++ b/fsinfo/null_lex.l @@ -1,7 +1,7 @@ %{ #include "null_gram.h" -void yyerror(const char *fmt, ...) {} +void null_error(const char *fmt, ...) {} int yywrap(void) { return 0; } %} %option nounput