2 * Copyright (C) 1994-1999, Index Data
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.8 1999-02-02 14:50:12 adam
8 * Updated WIN32 code specific sections. Changed header.
10 * Revision 1.7 1996/10/29 13:57:28 adam
11 * Include of zebrautl.h instead of alexutil.h.
13 * Revision 1.6 1996/01/08 09:09:21 adam
14 * Function dfa_parse got 'const' string argument.
15 * New functions to define char mappings made public.
17 * Revision 1.5 1995/09/04 12:33:27 adam
18 * Various cleanup. YAZ util used instead.
20 * Revision 1.4 1995/01/25 11:30:51 adam
21 * Simple error reporting when parsing regular expressions.
22 * Memory usage reduced.
24 * Revision 1.3 1995/01/24 16:00:22 adam
25 * Added -ansi to CFLAGS.
26 * Some changes to the dfa module.
28 * Revision 1.2 1994/09/26 16:30:57 adam
29 * Minor changes. imalloc uses xmalloc now.
31 * Revision 1.1 1994/09/26 10:16:56 adam
32 * First version of dfa module in alex. This version uses yacc to parse
33 * regular expressions. This should be hand-made instead.
51 static const char *inf_name;
58 read_rules (struct DFA *dfap),
64 static void prep (char **s)
66 static char expr_buf[MAXLINE+1];
78 static char *read_line (void)
80 static char linebuf[MAXLINE+1];
82 return fgets (linebuf, MAXLINE, inf);
85 static void read_defs (void)
88 while ((s=read_line()))
90 if (*s == '%' && s[1] == '%')
92 else if (*s == '\0' || isspace (*s))
95 error ("missing rule section");
98 static void read_rules (struct DFA *dfa)
105 fputs ("\n#ifndef YY_BREAK\n#define YY_BREAK break;\n#endif\n", outf);
106 fputs ("void lexact (int no)\n{\n", outf);
107 fputs ( "\tswitch (no)\n\t{\n", outf);
108 while ((s=read_line()))
110 if (*s == '%' && s[1] == '%')
112 else if (*s == '\0' || isspace (*s))
113 /* copy rest of line to output */
117 /* preprocess regular expression */
119 /* now parse regular expression */
121 i = dfa_parse (dfa, &sc);
124 fprintf (stderr, "%s #%d: regular expression syntax error\n",
132 fputs ("\t\tYY_BREAK\n", outf);
134 fprintf (outf, "\tcase %d:\n#line %d\n\t\t", no, line_no);
136 while (*sc == '\t' || *sc == ' ')
141 fputs ("\tYY_BREAK\n\t}\n}\n", outf);
143 error ("no regular expressions in rule section");
146 static void read_tail (void)
149 while ((s=read_line()))
153 int read_file (const char *s, struct DFA *dfa)
156 if (!(inf=fopen (s,"r")))
158 error ("cannot open `%s'", s);
162 if (!(outf=fopen ("lex.yy.c", "w")))
164 error ("cannot open `%s'", "lex.yy.c");