2 * Copyright (C) 1994, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.5 1995-09-04 12:33:27 adam
8 * Various cleanup. YAZ util used instead.
10 * Revision 1.4 1995/01/25 11:30:51 adam
11 * Simple error reporting when parsing regular expressions.
12 * Memory usage reduced.
14 * Revision 1.3 1995/01/24 16:00:22 adam
15 * Added -ansi to CFLAGS.
16 * Some changes to the dfa module.
18 * Revision 1.2 1994/09/26 16:30:57 adam
19 * Minor changes. imalloc uses xmalloc now.
21 * Revision 1.1 1994/09/26 10:16:56 adam
22 * First version of dfa module in alex. This version uses yacc to parse
23 * regular expressions. This should be hand-made instead.
41 static const char *inf_name;
48 read_rules (struct DFA *dfap),
54 static void prep (char **s)
56 static char expr_buf[MAXLINE+1];
68 static char *read_line (void)
70 static char linebuf[MAXLINE+1];
72 return fgets (linebuf, MAXLINE, inf);
75 static void read_defs (void)
78 while ((s=read_line()))
80 if (*s == '%' && s[1] == '%')
82 else if (*s == '\0' || isspace (*s))
85 error ("missing rule section");
88 static void read_rules (struct DFA *dfa)
94 fputs ("\n#ifndef YY_BREAK\n#define YY_BREAK break;\n#endif\n", outf);
95 fputs ("void lexact (int no)\n{\n", outf);
96 fputs ( "\tswitch (no)\n\t{\n", outf);
97 while ((s=read_line()))
99 if (*s == '%' && s[1] == '%')
101 else if (*s == '\0' || isspace (*s))
102 /* copy rest of line to output */
106 /* preprocess regular expression */
108 /* now parse regular expression */
109 i = dfa_parse (dfa, &s);
112 fprintf (stderr, "%s #%d: regular expression syntax error\n",
120 fputs ("\t\tYY_BREAK\n", outf);
122 fprintf (outf, "\tcase %d:\n#line %d\n\t\t", no, line_no);
124 while (*s == '\t' || *s == ' ')
129 fputs ("\tYY_BREAK\n\t}\n}\n", outf);
131 error ("no regular expressions in rule section");
134 static void read_tail (void)
137 while ((s=read_line()))
141 int read_file (const char *s, struct DFA *dfa)
144 if (!(inf=fopen (s,"r")))
146 error ("cannot open `%s'", s);
150 if (!(outf=fopen ("lex.yy.c", "w")))
152 error ("cannot open `%s'", "lex.yy.c");