2 * Copyright (C) 1994, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.6 1996-01-08 09:09:21 adam
8 * Function dfa_parse got 'const' string argument.
9 * New functions to define char mappings made public.
11 * Revision 1.5 1995/09/04 12:33:27 adam
12 * Various cleanup. YAZ util used instead.
14 * Revision 1.4 1995/01/25 11:30:51 adam
15 * Simple error reporting when parsing regular expressions.
16 * Memory usage reduced.
18 * Revision 1.3 1995/01/24 16:00:22 adam
19 * Added -ansi to CFLAGS.
20 * Some changes to the dfa module.
22 * Revision 1.2 1994/09/26 16:30:57 adam
23 * Minor changes. imalloc uses xmalloc now.
25 * Revision 1.1 1994/09/26 10:16:56 adam
26 * First version of dfa module in alex. This version uses yacc to parse
27 * regular expressions. This should be hand-made instead.
45 static const char *inf_name;
52 read_rules (struct DFA *dfap),
58 static void prep (char **s)
60 static char expr_buf[MAXLINE+1];
72 static char *read_line (void)
74 static char linebuf[MAXLINE+1];
76 return fgets (linebuf, MAXLINE, inf);
79 static void read_defs (void)
82 while ((s=read_line()))
84 if (*s == '%' && s[1] == '%')
86 else if (*s == '\0' || isspace (*s))
89 error ("missing rule section");
92 static void read_rules (struct DFA *dfa)
99 fputs ("\n#ifndef YY_BREAK\n#define YY_BREAK break;\n#endif\n", outf);
100 fputs ("void lexact (int no)\n{\n", outf);
101 fputs ( "\tswitch (no)\n\t{\n", outf);
102 while ((s=read_line()))
104 if (*s == '%' && s[1] == '%')
106 else if (*s == '\0' || isspace (*s))
107 /* copy rest of line to output */
111 /* preprocess regular expression */
113 /* now parse regular expression */
115 i = dfa_parse (dfa, &sc);
118 fprintf (stderr, "%s #%d: regular expression syntax error\n",
126 fputs ("\t\tYY_BREAK\n", outf);
128 fprintf (outf, "\tcase %d:\n#line %d\n\t\t", no, line_no);
130 while (*sc == '\t' || *sc == ' ')
135 fputs ("\tYY_BREAK\n\t}\n}\n", outf);
137 error ("no regular expressions in rule section");
140 static void read_tail (void)
143 while ((s=read_line()))
147 int read_file (const char *s, struct DFA *dfa)
150 if (!(inf=fopen (s,"r")))
152 error ("cannot open `%s'", s);
156 if (!(outf=fopen ("lex.yy.c", "w")))
158 error ("cannot open `%s'", "lex.yy.c");