]> git.saurik.com Git - bison.git/blob - src/scan-skel.l
Separate parser tables computation and output.
[bison.git] / src / scan-skel.l
1 /* Scan Bison Skeletons. -*- C -*-
2 Copyright (C) 2001, 2002 Free Software Foundation, Inc.
3
4 This file is part of Bison, the GNU Compiler Compiler.
5
6 Bison is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 Bison is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with Bison; see the file COPYING. If not, write to the Free
18 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 02111-1307, USA. */
20
21 %option nodefault noyywrap nounput never-interactive
22 %option prefix="skel_" outfile="lex.yy.c"
23
24 %{
25 #include "system.h"
26 #include "error.h"
27 #include "getargs.h"
28 #include "files.h"
29 int skel_lex PARAMS ((void));
30 static int yylineno = 1;
31 static char *yyoutname = NULL;
32 %}
33 %%
34 /* This is an approximation, but we don't need more. */
35 ^"#output \""[^\"]+\"\n {
36 yytext[yyleng - 2] = '\0';
37 XFREE (yyoutname);
38 yyoutname = xstrdup (yytext + strlen ("#output \""));
39 yyout = xfopen (yyoutname, "w");
40 yylineno = 1;
41 }
42
43 "@<:@" fputc ('[', yyout);
44 "@:>@" fputc (']', yyout);
45
46 "__oline__" fprintf (yyout, "%d", yylineno+1);
47 "__ofile__" fprintf (yyout, "%s", yyoutname);
48 [^@_\n]+ ECHO;
49 \n+ yylineno += yyleng; ECHO;
50 . ECHO;
51
52 <<EOF>> xfclose (yyout); free (yyoutname); return EOF;
53 %%
54
55 /* From lib/readpipe.c. */
56 FILE *readpipe PARAMS ((const char *, ...));
57
58 /*----------------------.
59 | Run our backend, M4. |
60 `----------------------*/
61
62 void m4_invoke PARAMS ((const char *definitions));
63
64 void
65 m4_invoke (const char *definitions)
66 {
67 /* Invoke m4 on the definition of the muscles, and the skeleton. */
68 const char *bison_pkgdatadir = getenv ("BISON_PKGDATADIR");
69 const char *m4 = getenv ("M4");
70 int pkg_data_len;
71 char *full_skeleton;
72
73 if (!m4)
74 m4 = M4;
75 if (!bison_pkgdatadir)
76 bison_pkgdatadir = PKGDATADIR;
77 pkg_data_len = strlen (bison_pkgdatadir);
78 full_skeleton = XMALLOC (char, pkg_data_len + strlen (skeleton) + 2);
79 if (bison_pkgdatadir[pkg_data_len-1] == '/')
80 sprintf (full_skeleton, "%s%s", bison_pkgdatadir, skeleton);
81 else
82 sprintf (full_skeleton, "%s/%s", bison_pkgdatadir, skeleton);
83 if (trace_flag & trace_tools)
84 fprintf (stderr,
85 "running: %s -I %s m4sugar/m4sugar.m4 %s %s\n",
86 m4, bison_pkgdatadir, definitions, full_skeleton);
87 skel_in = readpipe (m4,
88 "-I", bison_pkgdatadir,
89 "m4sugar/m4sugar.m4",
90 definitions,
91 full_skeleton,
92 NULL);
93 XFREE (full_skeleton);
94 if (!skel_in)
95 error (EXIT_FAILURE, errno, "cannot run m4");
96 skel_lex ();
97
98 /* Reclaim Flex's buffers. */
99 yy_delete_buffer (YY_CURRENT_BUFFER);
100 }