2 * Copyright (C) 1994, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.3 1995-01-24 16:00:22 adam
8 * Added -ansi to CFLAGS.
9 * Some changes to the dfa module.
11 * Revision 1.2 1994/09/26 16:30:57 adam
12 * Minor changes. imalloc uses xmalloc now.
14 * Revision 1.1 1994/09/26 10:16:56 adam
15 * First version of dfa module in alex. This version uses yacc to parse
16 * regular expressions. This should be hand-made instead.
34 static const char *inf_name;
41 read_rules (struct DFA *dfap),
47 static void prep (char **s)
49 static char expr_buf[MAXLINE+1];
61 static char *read_line (void)
63 static char linebuf[MAXLINE+1];
65 return fgets (linebuf, MAXLINE, inf);
68 static void read_defs (void)
71 while ((s=read_line()))
73 if (*s == '%' && s[1] == '%')
75 else if (*s == '\0' || isspace (*s))
78 error ("missing rule section");
81 static void read_rules (struct DFA *dfa)
87 fputs ("\n#ifndef YY_BREAK\n#define YY_BREAK break;\n#endif\n", outf);
88 fputs ("void lexact (int no)\n{\n", outf);
89 fputs ( "\tswitch (no)\n\t{\n", outf);
90 while ((s=read_line()))
92 if (*s == '%' && s[1] == '%')
94 else if (*s == '\0' || isspace (*s))
95 /* copy rest of line to output */
99 /* preprocess regular expression */
101 /* now parse regular expression */
102 i = dfa_parse (dfa, &s);
105 fprintf (stderr, "%s #%d: regular expression syntax error\n",
112 fputs ("\t\tYY_BREAK\n", outf);
114 fprintf (outf, "\tcase %d:\n#line %d\n\t\t", no, line_no);
116 while (*s == '\t' || *s == ' ')
121 fputs ("\tYY_BREAK\n\t}\n}\n", outf);
123 error ("no regular expressions in rule section");
126 static void read_tail (void)
129 while ((s=read_line()))
133 int read_file (const char *s, struct DFA *dfa)
136 if (!(inf=fopen (s,"r")))
138 error ("cannot open `%s'", s);
142 if (!(outf=fopen ("lex.yy.c", "w")))
144 error ("cannot open `%s'", "lex.yy.c");