This commit was manufactured by cvs2svn to create tag 'FreeBSD-release/1.0'.
[unix-history] / usr.bin / yacc / output.c
index d0bc44b..88c77b5 100644 (file)
@@ -1,43 +1,3 @@
-/*
- * Copyright (c) 1989 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Robert Paul Corbett.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the University of
- *     California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)output.c   5.6 (Berkeley) 1/20/91";
-#endif /* not lint */
-
 #include "defs.h"
 
 static int nvectors;
 #include "defs.h"
 
 static int nvectors;
@@ -62,6 +22,7 @@ output()
     free_itemsets();
     free_shifts();
     free_reductions();
     free_itemsets();
     free_shifts();
     free_reductions();
+    output_prefix();
     output_stored_text();
     output_defines();
     output_rule_data();
     output_stored_text();
     output_defines();
     output_rule_data();
@@ -79,13 +40,73 @@ output()
 }
 
 
 }
 
 
+output_prefix()
+{
+    if (symbol_prefix == NULL)
+       symbol_prefix = "yy";
+    else
+    {
+       ++outline;
+       fprintf(code_file, "#define yyparse %sparse\n", symbol_prefix);
+       ++outline;
+       fprintf(code_file, "#define yylex %slex\n", symbol_prefix);
+       ++outline;
+       fprintf(code_file, "#define yyerror %serror\n", symbol_prefix);
+       ++outline;
+       fprintf(code_file, "#define yychar %schar\n", symbol_prefix);
+       ++outline;
+       fprintf(code_file, "#define yyval %sval\n", symbol_prefix);
+       ++outline;
+       fprintf(code_file, "#define yylval %slval\n", symbol_prefix);
+       ++outline;
+       fprintf(code_file, "#define yydebug %sdebug\n", symbol_prefix);
+       ++outline;
+       fprintf(code_file, "#define yynerrs %snerrs\n", symbol_prefix);
+       ++outline;
+       fprintf(code_file, "#define yyerrflag %serrflag\n", symbol_prefix);
+       ++outline;
+       fprintf(code_file, "#define yyss %sss\n", symbol_prefix);
+       ++outline;
+       fprintf(code_file, "#define yyssp %sssp\n", symbol_prefix);
+       ++outline;
+       fprintf(code_file, "#define yyvs %svs\n", symbol_prefix);
+       ++outline;
+       fprintf(code_file, "#define yyvsp %svsp\n", symbol_prefix);
+       ++outline;
+       fprintf(code_file, "#define yylhs %slhs\n", symbol_prefix);
+       ++outline;
+       fprintf(code_file, "#define yylen %slen\n", symbol_prefix);
+       ++outline;
+       fprintf(code_file, "#define yydefred %sdefred\n", symbol_prefix);
+       ++outline;
+       fprintf(code_file, "#define yydgoto %sdgoto\n", symbol_prefix);
+       ++outline;
+       fprintf(code_file, "#define yysindex %ssindex\n", symbol_prefix);
+       ++outline;
+       fprintf(code_file, "#define yyrindex %srindex\n", symbol_prefix);
+       ++outline;
+       fprintf(code_file, "#define yygindex %sgindex\n", symbol_prefix);
+       ++outline;
+       fprintf(code_file, "#define yytable %stable\n", symbol_prefix);
+       ++outline;
+       fprintf(code_file, "#define yycheck %scheck\n", symbol_prefix);
+       ++outline;
+       fprintf(code_file, "#define yyname %sname\n", symbol_prefix);
+       ++outline;
+       fprintf(code_file, "#define yyrule %srule\n", symbol_prefix);
+    }
+    ++outline;
+    fprintf(code_file, "#define YYPREFIX \"%s\"\n", symbol_prefix);
+}
+
+
 output_rule_data()
 {
     register int i;
     register int j;
 
   
 output_rule_data()
 {
     register int i;
     register int j;
 
   
-    fprintf(output_file, "short yylhs[] = {%42d,",
+    fprintf(output_file, "short %slhs[] = {%42d,", symbol_prefix,
            symbol_value[start_symbol]);
 
     j = 10;
            symbol_value[start_symbol]);
 
     j = 10;
@@ -105,7 +126,7 @@ output_rule_data()
     if (!rflag) outline += 2;
     fprintf(output_file, "\n};\n");
 
     if (!rflag) outline += 2;
     fprintf(output_file, "\n};\n");
 
-    fprintf(output_file, "short yylen[] = {%42d,", 2);
+    fprintf(output_file, "short %slen[] = {%42d,", symbol_prefix, 2);
 
     j = 10;
     for (i = 3; i < nrules; i++)
 
     j = 10;
     for (i = 3; i < nrules; i++)
@@ -130,7 +151,7 @@ output_yydefred()
 {
     register int i, j;
 
 {
     register int i, j;
 
-    fprintf(output_file, "short yydefred[] = {%39d,",
+    fprintf(output_file, "short %sdefred[] = {%39d,", symbol_prefix,
            (defred[0] ? defred[0] - 2 : 0));
 
     j = 10;
            (defred[0] ? defred[0] - 2 : 0));
 
     j = 10;
@@ -272,7 +293,7 @@ goto_actions()
     state_count = NEW2(nstates, short);
 
     k = default_goto(start_symbol + 1);
     state_count = NEW2(nstates, short);
 
     k = default_goto(start_symbol + 1);
-    fprintf(output_file, "short yydgoto[] = {%40d,", k);
+    fprintf(output_file, "short %sdgoto[] = {%40d,", symbol_prefix, k);
     save_column(start_symbol + 1, k);
 
     j = 10;
     save_column(start_symbol + 1, k);
 
     j = 10;
@@ -596,7 +617,7 @@ output_base()
 {
     register int i, j;
 
 {
     register int i, j;
 
-    fprintf(output_file, "short yysindex[] = {%39d,", base[0]);
+    fprintf(output_file, "short %ssindex[] = {%39d,", symbol_prefix, base[0]);
 
     j = 10;
     for (i = 1; i < nstates; i++)
 
     j = 10;
     for (i = 1; i < nstates; i++)
@@ -614,7 +635,7 @@ output_base()
     }
 
     if (!rflag) outline += 2;
     }
 
     if (!rflag) outline += 2;
-    fprintf(output_file, "\n};\nshort yyrindex[] = {%39d,",
+    fprintf(output_file, "\n};\nshort %srindex[] = {%39d,", symbol_prefix,
            base[nstates]);
 
     j = 10;
            base[nstates]);
 
     j = 10;
@@ -633,7 +654,7 @@ output_base()
     }
 
     if (!rflag) outline += 2;
     }
 
     if (!rflag) outline += 2;
-    fprintf(output_file, "\n};\nshort yygindex[] = {%39d,",
+    fprintf(output_file, "\n};\nshort %sgindex[] = {%39d,", symbol_prefix,
            base[2*nstates]);
 
     j = 10;
            base[2*nstates]);
 
     j = 10;
@@ -665,7 +686,8 @@ output_table()
 
     ++outline;
     fprintf(code_file, "#define YYTABLESIZE %d\n", high);
 
     ++outline;
     fprintf(code_file, "#define YYTABLESIZE %d\n", high);
-    fprintf(output_file, "short yytable[] = {%40d,", table[0]);
+    fprintf(output_file, "short %stable[] = {%40d,", symbol_prefix,
+           table[0]);
 
     j = 10;
     for (i = 1; i <= high; i++)
 
     j = 10;
     for (i = 1; i <= high; i++)
@@ -694,7 +716,8 @@ output_check()
     register int i;
     register int j;
 
     register int i;
     register int j;
 
-    fprintf(output_file, "short yycheck[] = {%40d,", check[0]);
+    fprintf(output_file, "short %scheck[] = {%40d,", symbol_prefix,
+           check[0]);
 
     j = 10;
     for (i = 1; i <= high; i++)
 
     j = 10;
     for (i = 1; i <= high; i++)
@@ -796,7 +819,8 @@ output_defines()
        if (union_file == NULL) open_error(union_file_name);
        while ((c = getc(union_file)) != EOF)
            putc(c, defines_file);
        if (union_file == NULL) open_error(union_file_name);
        while ((c = getc(union_file)) != EOF)
            putc(c, defines_file);
-       fprintf(defines_file, " YYSTYPE;\nextern YYSTYPE yylval;\n");
+       fprintf(defines_file, " YYSTYPE;\nextern YYSTYPE %slval;\n",
+               symbol_prefix);
     }
 }
 
     }
 }
 
@@ -861,7 +885,7 @@ output_debug()
     symnam[0] = "end-of-file";
 
     if (!rflag) ++outline;
     symnam[0] = "end-of-file";
 
     if (!rflag) ++outline;
-    fprintf(output_file, "#if YYDEBUG\nchar *yyname[] = {");
+    fprintf(output_file, "#if YYDEBUG\nchar *%sname[] = {", symbol_prefix);
     j = 80;
     for (i = 0; i <= max; ++i)
     {
     j = 80;
     for (i = 0; i <= max; ++i)
     {
@@ -987,7 +1011,7 @@ output_debug()
     FREE(symnam);
 
     if (!rflag) ++outline;
     FREE(symnam);
 
     if (!rflag) ++outline;
-    fprintf(output_file, "char *yyrule[] = {\n");
+    fprintf(output_file, "char *%srule[] = {\n", symbol_prefix);
     for (i = 2; i < nrules; ++i)
     {
        fprintf(output_file, "\"%s :", symbol_name[rlhs[i]]);
     for (i = 2; i < nrules; ++i)
     {
        fprintf(output_file, "\"%s :", symbol_name[rlhs[i]]);