Change the way we handle multiple lex scanners and yacc parsers
authorChristos Zoulas <christos@zoulas.com>
Thu, 5 Dec 2013 17:24:48 +0000 (12:24 -0500)
committerChristos Zoulas <christos@zoulas.com>
Thu, 5 Dec 2013 17:24:48 +0000 (12:24 -0500)
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.

ChangeLog
amd/conf_tok.l
amd/sun_map_tok.l
bootstrap
fsinfo/fsi_lex.l
fsinfo/fsi_util.c
fsinfo/fsinfo.c
fsinfo/fsinfo.h
fsinfo/null_lex.l

index e0cf3483ecfd97e68dbcf92d6a9f247189fc9ae1..73201a4e596496e9c011e02ab7665460eb4cb522 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+
+2013-12-05  Christos Zoulas <christos@zoulas.com>
+
+       * 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 <christos@zoulas.com>
+
+       * 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 <christos@zoulas.com>
 
        * update to handle new autoconf and regen files
index fb97f865912067c4d99a98fcef7f5d03fd03ee3a..ccfe09469473063bb859fdf9b6a36c17a5c18eb8 100644 (file)
@@ -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);
                        }
 
index 54e65ae44413377524fa479a4c6101b3d71ecad6..74cb47b69341693efbb1dd79fa67c4edbcf75885 100644 (file)
@@ -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;
 }
index e614ff67125fbe2ea4190d70c2eea5406c4ba22c..80bf9b283893be29af065aabfbefc5dac3cbacda 100755 (executable)
--- 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..."
index 4b1f445e7ec81d00cbaf426708e4a7280cd33db4..3282b2445c284245af0ff7f04eab6944f38df6ff 100644 (file)
@@ -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 {
 <F>[={}]               { return *yytext; }
 
 <F>\"                  { BEGIN Q; optr = ostr; quoted = 1; }
-<Q>\n                  { ayylineno++; yyerror("\" expected"); BEGIN F; }
+<Q>\n                  { ayylineno++; fsi_error("\" expected"); BEGIN F; }
 <Q>\\b                 { *optr++ = '\b'; /* escape */ }
 <Q>\\t                 { *optr++ = '\t'; /* escape */ }
 <Q>\\\"                        { *optr++ = '\"'; /* escape */ }
@@ -190,7 +190,7 @@ struct r {
 <Q>\\n                 { *optr++ = '\n'; /* escape */ }
 <Q>\\f                 { *optr++ = '\f'; /* escape */ }
 <Q>"\\ "               { *optr++ = ' '; /* force space */ }
-<Q>\\.                 { yyerror("Unknown \\ sequence"); }
+<Q>\\.                 { fsi_error("Unknown \\ sequence"); }
 <Q>([ \t]|"\\\n"){2,}  { char *p = (char *) yytext-1; while ((p = strchr(p+1, '\n'))) ayylineno++; }
 <Q>\"                  { 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;
 
index 15440032f5f0f1a0f628286074441ebb64b8f86d..a90296b6b2e265d01fc272f0bb4b2765259487a9 100644 (file)
@@ -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;
index b487861ba9f167922d7771e3aa9f4c1c993d8f50..daec38707b3aac7d64c14bc8a9181de0cdab395d 100644 (file)
@@ -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;
 
index 18baaf7bea1cc8617216c655e846af62ae2d9cd6..59038ac3fe1b4b612d7558df7764eb523a1f1567 100644 (file)
@@ -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)))
index f756f561ef5b3dfa6c05a2491c2600f27ea80179..46bb46381e438065c05f7af9e6d46e24f7550bcc 100644 (file)
@@ -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