Subversion Repositories tendra.SVN

Rev

Rev 5 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5 Rev 6
Line -... Line 1...
-
 
1
/*
-
 
2
 * Copyright (c) 2002-2005 The TenDRA Project <http://www.tendra.org/>.
-
 
3
 * All rights reserved.
-
 
4
 *
-
 
5
 * Redistribution and use in source and binary forms, with or without
-
 
6
 * modification, are permitted provided that the following conditions are met:
-
 
7
 *
-
 
8
 * 1. Redistributions of source code must retain the above copyright notice,
-
 
9
 *    this list of conditions and the following disclaimer.
-
 
10
 * 2. Redistributions in binary form must reproduce the above copyright notice,
-
 
11
 *    this list of conditions and the following disclaimer in the documentation
-
 
12
 *    and/or other materials provided with the distribution.
-
 
13
 * 3. Neither the name of The TenDRA Project nor the names of its contributors
-
 
14
 *    may be used to endorse or promote products derived from this software
-
 
15
 *    without specific, prior written permission.
-
 
16
 *
-
 
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
-
 
18
 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-
 
19
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-
 
20
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
-
 
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-
 
22
 * EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-
 
23
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-
 
24
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-
 
25
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-
 
26
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-
 
27
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 
28
 *
-
 
29
 * $Id$
-
 
30
 */
1
/*
31
/*
2
    		 Crown Copyright (c) 1997
32
    		 Crown Copyright (c) 1997
3
    
33
 
4
    This TenDRA(r) Computer Program is subject to Copyright
34
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
35
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
36
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
37
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
38
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
39
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
40
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
41
    shall be deemed to be acceptance of the following conditions:-
12
    
42
 
13
        (1) Its Recipients shall ensure that this Notice is
43
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
44
        reproduced upon any copies or amended versions of it;
15
    
45
 
16
        (2) Any amended version of it shall be clearly marked to
46
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
47
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
48
        for the relevant amendment or amendments;
19
    
49
 
20
        (3) Its onward transfer from a recipient to another
50
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
51
        party shall be deemed to be that party's acceptance of
22
        these conditions;
52
        these conditions;
23
    
53
 
24
        (4) DERA gives no warranty or assurance as to its
54
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
55
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
56
        no liability whatsoever in relation to any use to which
27
        it may be put.
57
        it may be put.
28
*/
58
*/
Line 59... Line 89...
59
#include "rstack.h"
89
#include "rstack.h"
60
#include "rule.h"
90
#include "rule.h"
61
#include "type.h"
91
#include "type.h"
62
 
92
 
63
/*--------------------------------------------------------------------------*/
93
/*--------------------------------------------------------------------------*/
-
 
94
 
-
 
95
#if FS_WEAK_PROTOTYPES
-
 
96
#pragma TenDRA keyword KW_WEAK_PROTOTYPE for weak
-
 
97
#else
-
 
98
#define KW_WEAK_PROTOTYPE
-
 
99
#endif
64
 
100
 
65
BasicP
101
BasicP
66
basic_create PROTO_N ((grammar, ignored))
102
basic_create(GrammarP grammar, BoolT ignored)
67
	     PROTO_T (GrammarP grammar X
-
 
68
		      BoolT    ignored)
-
 
69
{
103
{
70
    BasicP basic = ALLOCATE (BasicT);
104
    BasicP basic = ALLOCATE(BasicT);
71
 
105
 
72
    basic->terminal        = grammar_next_terminal (grammar);
106
    basic->terminal        = grammar_next_terminal(grammar);
73
    types_init (basic_result (basic));
107
    types_init(basic_result(basic));
74
    basic->result_code     = NIL (GenericP);
108
    basic->result_code     = NIL(GenericP);
75
    basic->ignored         = ignored;
109
    basic->ignored         = ignored;
76
    return (basic);
110
    return(basic);
77
}
111
}
78
 
112
 
79
#ifdef FS_FAST
113
#ifdef FS_FAST
80
#undef basic_terminal
114
#undef basic_terminal
81
#endif /* defined (FS_FAST) */
115
#endif /* defined (FS_FAST) */
82
unsigned
116
unsigned
83
basic_terminal PROTO_N ((basic))
117
basic_terminal(BasicP basic)
84
	       PROTO_T (BasicP basic)
-
 
85
{
118
{
86
    return (basic->terminal);
119
    return(basic->terminal);
87
}
120
}
88
#ifdef FS_FAST
121
#ifdef FS_FAST
89
#define basic_terminal(b) ((b)->terminal)
122
#define basic_terminal(b)	((b)->terminal)
90
#endif /* defined (FS_FAST) */
123
#endif /* defined (FS_FAST) */
91
 
124
 
92
#ifdef FS_FAST
125
#ifdef FS_FAST
93
#undef basic_result
126
#undef basic_result
94
#endif /* defined (FS_FAST) */
127
#endif /* defined (FS_FAST) */
95
TypeTupleP
128
TypeTupleP
96
basic_result PROTO_N ((basic))
129
basic_result(BasicP basic)
97
	     PROTO_T (BasicP basic)
-
 
98
{
130
{
99
    return (&(basic->result));
131
    return(&(basic->result));
100
}
132
}
101
#ifdef FS_FAST
133
#ifdef FS_FAST
102
#define basic_result(b) (&((b)->result))
134
#define basic_result(b)	(&((b)->result))
103
#endif /* defined (FS_FAST) */
135
#endif /* defined (FS_FAST) */
104
 
136
 
105
#ifdef FS_FAST
137
#ifdef FS_FAST
106
#undef basic_get_result_code
138
#undef basic_get_result_code
107
#endif /* defined (FS_FAST) */
139
#endif /* defined (FS_FAST) */
108
GenericP
140
GenericP
109
basic_get_result_code PROTO_N ((basic))
141
basic_get_result_code(BasicP basic)
110
		      PROTO_T (BasicP basic)
-
 
111
{
142
{
112
    return (basic->result_code);
143
    return(basic->result_code);
113
}
144
}
114
#ifdef FS_FAST
145
#ifdef FS_FAST
115
#define basic_get_result_code(b) ((b)->result_code)
146
#define basic_get_result_code(b)	((b)->result_code)
116
#endif /* defined (FS_FAST) */
147
#endif /* defined (FS_FAST) */
117
 
148
 
118
#ifdef FS_FAST
149
#ifdef FS_FAST
119
#undef basic_set_result_code
150
#undef basic_set_result_code
120
#endif /* defined (FS_FAST) */
151
#endif /* defined (FS_FAST) */
121
void
152
void
122
basic_set_result_code PROTO_N ((basic, code))
153
basic_set_result_code(BasicP basic, GenericP code)
123
		      PROTO_T (BasicP   basic X
-
 
124
			       GenericP code)
-
 
125
{
154
{
126
    basic->result_code = code;
155
    basic->result_code = code;
127
}
156
}
128
#ifdef FS_FAST
157
#ifdef FS_FAST
129
#define basic_set_result_code(b, c) ((b)->result_code = (c))
158
#define basic_set_result_code(b, c)	((b)->result_code = (c))
130
#endif /* defined (FS_FAST) */
159
#endif /* defined (FS_FAST) */
131
 
160
 
132
#ifdef FS_FAST
161
#ifdef FS_FAST
133
#undef basic_get_ignored
162
#undef basic_get_ignored
134
#endif /* defined (FS_FAST) */
163
#endif /* defined (FS_FAST) */
135
BoolT
164
BoolT
136
basic_get_ignored PROTO_N ((basic))
165
basic_get_ignored(BasicP basic)
137
		  PROTO_T (BasicP basic)
-
 
138
{
166
{
139
    return (basic->ignored);
167
    return(basic->ignored);
140
}
168
}
141
#ifdef FS_FAST
169
#ifdef FS_FAST
142
#define basic_get_ignored(b) ((b)->ignored)
170
#define basic_get_ignored(b)	((b)->ignored)
143
#endif /* defined (FS_FAST) */
171
#endif /* defined (FS_FAST) */
144
 
172
 
145
void
173
void
146
basic_iter_for_table PROTO_N ((basic, full, proc, closure))
174
basic_iter_for_table(BasicP basic, BoolT full,
147
		     PROTO_T (BasicP   basic X
-
 
148
			      BoolT    full X
-
 
149
			      void   (*proc) PROTO_S ((EntryP, GenericP)) X
175
		     void(*proc)KW_WEAK_PROTOTYPE(EntryP, GenericP),
150
			      GenericP closure)
176
		     GenericP closure)
151
{
177
{
152
    if (full) {
178
    if (full) {
153
	types_iter_for_table (basic_result (basic), proc, closure);
179
	types_iter_for_table(basic_result(basic), proc, closure);
154
    }
180
    }
155
}
181
}
156
 
182
 
157
void
183
void
158
write_basics PROTO_N ((ostream, closure))
184
write_basics(OStreamP ostream, BasicClosureP closure)
159
	     PROTO_T (OStreamP      ostream X
-
 
160
		      BasicClosureP closure)
-
 
161
{
185
{
162
    BitVecP  bitvec   = closure->bitvec;
186
    BitVecP  bitvec   = closure->bitvec;
163
    TableP   table    = grammar_table (closure->grammar);
187
    TableP   table    = grammar_table(closure->grammar);
164
    unsigned terminal = bitvec_first_bit (bitvec);
188
    unsigned terminal = bitvec_first_bit(bitvec);
165
    unsigned num_bits = bitvec_num_bits (bitvec);
189
    unsigned num_bits = bitvec_num_bits(bitvec);
166
 
190
 
167
    while (num_bits) {
191
    while (num_bits) {
168
	EntryP entry = table_get_basic_by_number (table, terminal);
192
	EntryP entry = table_get_basic_by_number(table, terminal);
169
 
193
 
170
	if (entry) {
194
	if (entry) {
171
	    write_char (ostream, '\'');
195
	    write_char(ostream, '\'');
172
	    write_key (ostream, entry_key (entry));
196
	    write_key(ostream, entry_key(entry));
173
	    write_char (ostream, '\'');
197
	    write_char(ostream, '\'');
174
	} else {
198
	} else {
175
	    write_unsigned (ostream, terminal);
199
	    write_unsigned(ostream, terminal);
176
	}
200
	}
177
	if (num_bits > 2) {
201
	if (num_bits > 2) {
178
	    write_cstring (ostream, ", ");
202
	    write_cstring(ostream, ", ");
179
	} else if (num_bits == 2) {
203
	} else if (num_bits == 2) {
180
	    write_cstring (ostream, " & ");
204
	    write_cstring(ostream, " & ");
181
	}
205
	}
182
	num_bits --;
206
	num_bits--;
183
	(void) bitvec_next_bit (bitvec, &terminal);
207
	(void)bitvec_next_bit(bitvec, &terminal);
184
    }
208
    }
185
}
209
}
186

210

187
/*
211
/*
188
 * Local variables(smf):
212
 * Local variables(smf):