2 * Copyright (C) 1994, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.1 1994-09-26 10:16:56 adam
8 * First version of dfa module in alex. This version uses yacc to parse
9 * regular expressions. This should be hand-made instead.
27 static const char *inf_name;
34 read_rules (DFA **dfap),
40 static void prep (char **s)
42 static char expr_buf[MAXLINE+1];
54 static char *read_line (void)
56 static char linebuf[MAXLINE+1];
58 return fgets( linebuf, MAXLINE, inf );
61 static void read_defs (void)
64 while( (s=read_line()) )
66 if( *s == '%' && s[1] == '%' )
68 else if( *s == '\0' || isspace( *s ) )
71 error( "missing rule section" );
74 static void read_rules (DFA **dfap)
81 *dfap = dfa = init_dfa();
82 fputs( "\n#ifndef YY_BREAK\n#define YY_BREAK break;\n#endif\n", outf );
83 fputs( "void lexact( int no )\n{\n", outf );
84 fputs( "\tswitch( no )\n\t{\n", outf );
86 while( (s=read_line()) )
88 if( *s == '%' && s[1] == '%' )
90 else if( *s == '\0' || isspace( *s ) )
91 /* copy rest of line to output */
95 /* preprocess regular expression */
97 /* now parse regular expression */
99 i = parse_dfa( dfa, &s, ccl_chars );
101 i = parse_dfa( dfa, &s, thompson_chars );
104 fputs( "\t\tYY_BREAK\n", outf );
105 fprintf( outf, "\tcase %d:\n#line %d\n\t\t", dfa->rule, line_no );
108 fprintf( stderr, "%s #%d: regular expression syntax error\n",
112 else if( !dfa->root )
113 dfa->root = dfa->top;
118 n->u.p[0] = dfa->root;
119 n->u.p[1] = dfa->top;
122 while( *s == '\t' || *s == ' ' )
127 fputs( "\tYY_BREAK\n\t}\n}\n", outf );
129 error( "no regular expressions in rule section" );
132 static void read_tail (void)
135 while( (s=read_line()) )
139 int read_file (const char *s, DFA **dfap)
142 if( !(inf=fopen( s,"r" )) )
144 error( "cannot open `%s'", s );
148 if( !(outf=fopen( "lex.yy.c", "w" )) )
150 error( "cannot open `%s'", "lex.yy.c" );