source: vendor/flex/2.5.33/parse.y@ 3031

Last change on this file since 3031 was 3031, checked in by bird, 19 years ago

flex 2.5.33.

File size: 21.1 KB
Line 
1/* parse.y - parser for flex input */
2
3%token CHAR NUMBER SECTEND SCDECL XSCDECL NAME PREVCCL EOF_OP
4%token OPTION_OP OPT_OUTFILE OPT_PREFIX OPT_YYCLASS OPT_HEADER
5%token OPT_TABLES
6
7%token CCE_ALNUM CCE_ALPHA CCE_BLANK CCE_CNTRL CCE_DIGIT CCE_GRAPH
8%token CCE_LOWER CCE_PRINT CCE_PUNCT CCE_SPACE CCE_UPPER CCE_XDIGIT
9
10/*
11 *POSIX and AT&T lex place the
12 * precedence of the repeat operator, {}, below that of concatenation.
13 * Thus, ab{3} is ababab. Most other POSIX utilities use an Extended
14 * Regular Expression (ERE) precedence that has the repeat operator
15 * higher than concatenation. This causes ab{3} to yield abbb.
16 *
17 * In order to support the POSIX and AT&T precedence and the flex
18 * precedence we define two token sets for the begin and end tokens of
19 * the repeat operator, '{' and '}'. The lexical scanner chooses
20 * which tokens to return based on whether posix_compat or lex_compat
21 * are specified. Specifying either posix_compat or lex_compat will
22 * cause flex to parse scanner files as per the AT&T and
23 * POSIX-mandated behavior.
24 */
25
26%token BEGIN_REPEAT_POSIX END_REPEAT_POSIX BEGIN_REPEAT_FLEX END_REPEAT_FLEX
27
28
29%{
30/* Copyright (c) 1990 The Regents of the University of California. */
31/* All rights reserved. */
32
33/* This code is derived from software contributed to Berkeley by */
34/* Vern Paxson. */
35
36/* The United States Government has rights in this work pursuant */
37/* to contract no. DE-AC03-76SF00098 between the United States */
38/* Department of Energy and the University of California. */
39
40/* This file is part of flex. */
41
42/* Redistribution and use in source and binary forms, with or without */
43/* modification, are permitted provided that the following conditions */
44/* are met: */
45
46/* 1. Redistributions of source code must retain the above copyright */
47/* notice, this list of conditions and the following disclaimer. */
48/* 2. Redistributions in binary form must reproduce the above copyright */
49/* notice, this list of conditions and the following disclaimer in the */
50/* documentation and/or other materials provided with the distribution. */
51
52/* Neither the name of the University nor the names of its contributors */
53/* may be used to endorse or promote products derived from this software */
54/* without specific prior written permission. */
55
56/* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR */
57/* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED */
58/* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */
59/* PURPOSE. */
60
61/* Some versions of bison are broken in that they use alloca() but don't
62 * declare it properly. The following is the patented (just kidding!)
63 * #ifdef chud to fix the problem, courtesy of Francois Pinard.
64 */
65#ifdef YYBISON
66/* AIX requires this to be the first thing in the file. What a piece. */
67# ifdef _AIX
68 #pragma alloca
69# endif
70#endif
71
72#include "flexdef.h"
73#include "tables.h"
74
75/* The remainder of the alloca() cruft has to come after including flexdef.h,
76 * so HAVE_ALLOCA_H is (possibly) defined.
77 */
78#ifdef YYBISON
79# ifdef __GNUC__
80# ifndef alloca
81# define alloca __builtin_alloca
82# endif
83# else
84# if HAVE_ALLOCA_H
85# include <alloca.h>
86# else
87# ifdef __hpux
88void *alloca ();
89# else
90# ifdef __TURBOC__
91# include <malloc.h>
92# else
93char *alloca ();
94# endif
95# endif
96# endif
97# endif
98#endif
99
100/* Bletch, ^^^^ that was ugly! */
101
102
103int pat, scnum, eps, headcnt, trailcnt, anyccl, lastchar, i, rulelen;
104int trlcontxt, xcluflg, currccl, cclsorted, varlength, variable_trail_rule;
105
106int *scon_stk;
107int scon_stk_ptr;
108
109static int madeany = false; /* whether we've made the '.' character class */
110int previous_continued_action; /* whether the previous rule's action was '|' */
111
112#define format_warn3(fmt, a1, a2) \
113 do{ \
114 char fw3_msg[MAXLINE];\
115 snprintf( fw3_msg, MAXLINE,(fmt), (a1), (a2) );\
116 warn( fw3_msg );\
117 }while(0)
118
119/* Expand a POSIX character class expression. */
120#define CCL_EXPR(func) \
121 do{ \
122 int c; \
123 for ( c = 0; c < csize; ++c ) \
124 if ( isascii(c) && func(c) ) \
125 ccladd( currccl, c ); \
126 }while(0)
127
128/* While POSIX defines isblank(), it's not ANSI C. */
129#define IS_BLANK(c) ((c) == ' ' || (c) == '\t')
130
131/* On some over-ambitious machines, such as DEC Alpha's, the default
132 * token type is "long" instead of "int"; this leads to problems with
133 * declaring yylval in flexdef.h. But so far, all the yacc's I've seen
134 * wrap their definitions of YYSTYPE with "#ifndef YYSTYPE"'s, so the
135 * following should ensure that the default token type is "int".
136 */
137#define YYSTYPE int
138
139%}
140
141%%
142goal : initlex sect1 sect1end sect2 initforrule
143 { /* add default rule */
144 int def_rule;
145
146 pat = cclinit();
147 cclnegate( pat );
148
149 def_rule = mkstate( -pat );
150
151 /* Remember the number of the default rule so we
152 * don't generate "can't match" warnings for it.
153 */
154 default_rule = num_rules;
155
156 finish_rule( def_rule, false, 0, 0, 0);
157
158 for ( i = 1; i <= lastsc; ++i )
159 scset[i] = mkbranch( scset[i], def_rule );
160
161 if ( spprdflt )
162 add_action(
163 "YY_FATAL_ERROR( \"flex scanner jammed\" )" );
164 else
165 add_action( "ECHO" );
166
167 add_action( ";\n\tYY_BREAK\n" );
168 }
169 ;
170
171initlex :
172 { /* initialize for processing rules */