2 * Copyright (C) 1994, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.4 1995-01-25 11:30:51 adam
8 * Simple error reporting when parsing regular expressions.
9 * Memory usage reduced.
11 * Revision 1.3 1995/01/24 16:00:22 adam
12 * Added -ansi to CFLAGS.
13 * Some changes to the dfa module.
15 * Revision 1.2 1994/09/26 16:30:57 adam
16 * Minor changes. imalloc uses xmalloc now.
18 * Revision 1.1 1994/09/26 10:16:56 adam
19 * First version of dfa module in alex. This version uses yacc to parse
20 * regular expressions. This should be hand-made instead.
38 static const char *inf_name;
45 read_rules (struct DFA *dfap),
51 static void prep (char **s)
53 static char expr_buf[MAXLINE+1];
65 static char *read_line (void)
67 static char linebuf[MAXLINE+1];
69 return fgets (linebuf, MAXLINE, inf);
72 static void read_defs (void)
75 while ((s=read_line()))
77 if (*s == '%' && s[1] == '%')
79 else if (*s == '\0' || isspace (*s))
82 error ("missing rule section");
85 static void read_rules (struct DFA *dfa)
91 fputs ("\n#ifndef YY_BREAK\n#define YY_BREAK break;\n#endif\n", outf);
92 fputs ("void lexact (int no)\n{\n", outf);
93 fputs ( "\tswitch (no)\n\t{\n", outf);
94 while ((s=read_line()))
96 if (*s == '%' && s[1] == '%')
98 else if (*s == '\0' || isspace (*s))
99 /* copy rest of line to output */
103 /* preprocess regular expression */
105 /* now parse regular expression */
106 i = dfa_parse (dfa, &s);
109 fprintf (stderr, "%s #%d: regular expression syntax error\n",
117 fputs ("\t\tYY_BREAK\n", outf);
119 fprintf (outf, "\tcase %d:\n#line %d\n\t\t", no, line_no);
121 while (*s == '\t' || *s == ' ')
126 fputs ("\tYY_BREAK\n\t}\n}\n", outf);
128 error ("no regular expressions in rule section");
131 static void read_tail (void)
134 while ((s=read_line()))
138 int read_file (const char *s, struct DFA *dfa)
141 if (!(inf=fopen (s,"r")))
143 error ("cannot open `%s'", s);
147 if (!(outf=fopen ("lex.yy.c", "w")))
149 error ("cannot open `%s'", "lex.yy.c");