2 * Copyright (C) 1994, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.7 1996-10-29 13:57:28 adam
8 * Include of zebrautl.h instead of alexutil.h.
10 * Revision 1.6 1996/01/08 09:09:21 adam
11 * Function dfa_parse got 'const' string argument.
12 * New functions to define char mappings made public.
14 * Revision 1.5 1995/09/04 12:33:27 adam
15 * Various cleanup. YAZ util used instead.
17 * Revision 1.4 1995/01/25 11:30:51 adam
18 * Simple error reporting when parsing regular expressions.
19 * Memory usage reduced.
21 * Revision 1.3 1995/01/24 16:00:22 adam
22 * Added -ansi to CFLAGS.
23 * Some changes to the dfa module.
25 * Revision 1.2 1994/09/26 16:30:57 adam
26 * Minor changes. imalloc uses xmalloc now.
28 * Revision 1.1 1994/09/26 10:16:56 adam
29 * First version of dfa module in alex. This version uses yacc to parse
30 * regular expressions. This should be hand-made instead.
48 static const char *inf_name;
55 read_rules (struct DFA *dfap),
61 static void prep (char **s)
63 static char expr_buf[MAXLINE+1];
75 static char *read_line (void)
77 static char linebuf[MAXLINE+1];
79 return fgets (linebuf, MAXLINE, inf);
82 static void read_defs (void)
85 while ((s=read_line()))
87 if (*s == '%' && s[1] == '%')
89 else if (*s == '\0' || isspace (*s))
92 error ("missing rule section");
95 static void read_rules (struct DFA *dfa)
102 fputs ("\n#ifndef YY_BREAK\n#define YY_BREAK break;\n#endif\n", outf);
103 fputs ("void lexact (int no)\n{\n", outf);
104 fputs ( "\tswitch (no)\n\t{\n", outf);
105 while ((s=read_line()))
107 if (*s == '%' && s[1] == '%')
109 else if (*s == '\0' || isspace (*s))
110 /* copy rest of line to output */
114 /* preprocess regular expression */
116 /* now parse regular expression */
118 i = dfa_parse (dfa, &sc);
121 fprintf (stderr, "%s #%d: regular expression syntax error\n",
129 fputs ("\t\tYY_BREAK\n", outf);
131 fprintf (outf, "\tcase %d:\n#line %d\n\t\t", no, line_no);
133 while (*sc == '\t' || *sc == ' ')
138 fputs ("\tYY_BREAK\n\t}\n}\n", outf);
140 error ("no regular expressions in rule section");
143 static void read_tail (void)
146 while ((s=read_line()))
150 int read_file (const char *s, struct DFA *dfa)
153 if (!(inf=fopen (s,"r")))
155 error ("cannot open `%s'", s);
159 if (!(outf=fopen ("lex.yy.c", "w")))
161 error ("cannot open `%s'", "lex.yy.c");