xref: /aosp_15_r20/external/bc/include/parse.h (revision 5a6e848804d15c18a0125914844ee4eb0bda4fcf)
1*5a6e8488SAndroid Build Coastguard Worker /*
2*5a6e8488SAndroid Build Coastguard Worker  * *****************************************************************************
3*5a6e8488SAndroid Build Coastguard Worker  *
4*5a6e8488SAndroid Build Coastguard Worker  * SPDX-License-Identifier: BSD-2-Clause
5*5a6e8488SAndroid Build Coastguard Worker  *
6*5a6e8488SAndroid Build Coastguard Worker  * Copyright (c) 2018-2024 Gavin D. Howard and contributors.
7*5a6e8488SAndroid Build Coastguard Worker  *
8*5a6e8488SAndroid Build Coastguard Worker  * Redistribution and use in source and binary forms, with or without
9*5a6e8488SAndroid Build Coastguard Worker  * modification, are permitted provided that the following conditions are met:
10*5a6e8488SAndroid Build Coastguard Worker  *
11*5a6e8488SAndroid Build Coastguard Worker  * * Redistributions of source code must retain the above copyright notice, this
12*5a6e8488SAndroid Build Coastguard Worker  *   list of conditions and the following disclaimer.
13*5a6e8488SAndroid Build Coastguard Worker  *
14*5a6e8488SAndroid Build Coastguard Worker  * * Redistributions in binary form must reproduce the above copyright notice,
15*5a6e8488SAndroid Build Coastguard Worker  *   this list of conditions and the following disclaimer in the documentation
16*5a6e8488SAndroid Build Coastguard Worker  *   and/or other materials provided with the distribution.
17*5a6e8488SAndroid Build Coastguard Worker  *
18*5a6e8488SAndroid Build Coastguard Worker  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19*5a6e8488SAndroid Build Coastguard Worker  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20*5a6e8488SAndroid Build Coastguard Worker  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21*5a6e8488SAndroid Build Coastguard Worker  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22*5a6e8488SAndroid Build Coastguard Worker  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23*5a6e8488SAndroid Build Coastguard Worker  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24*5a6e8488SAndroid Build Coastguard Worker  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25*5a6e8488SAndroid Build Coastguard Worker  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26*5a6e8488SAndroid Build Coastguard Worker  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27*5a6e8488SAndroid Build Coastguard Worker  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28*5a6e8488SAndroid Build Coastguard Worker  * POSSIBILITY OF SUCH DAMAGE.
29*5a6e8488SAndroid Build Coastguard Worker  *
30*5a6e8488SAndroid Build Coastguard Worker  * *****************************************************************************
31*5a6e8488SAndroid Build Coastguard Worker  *
32*5a6e8488SAndroid Build Coastguard Worker  * Definitions for bc's parser.
33*5a6e8488SAndroid Build Coastguard Worker  *
34*5a6e8488SAndroid Build Coastguard Worker  */
35*5a6e8488SAndroid Build Coastguard Worker 
36*5a6e8488SAndroid Build Coastguard Worker #ifndef BC_PARSE_H
37*5a6e8488SAndroid Build Coastguard Worker #define BC_PARSE_H
38*5a6e8488SAndroid Build Coastguard Worker 
39*5a6e8488SAndroid Build Coastguard Worker #include <limits.h>
40*5a6e8488SAndroid Build Coastguard Worker #include <stdbool.h>
41*5a6e8488SAndroid Build Coastguard Worker #include <stdint.h>
42*5a6e8488SAndroid Build Coastguard Worker 
43*5a6e8488SAndroid Build Coastguard Worker #include <status.h>
44*5a6e8488SAndroid Build Coastguard Worker #include <vector.h>
45*5a6e8488SAndroid Build Coastguard Worker #include <lex.h>
46*5a6e8488SAndroid Build Coastguard Worker #include <lang.h>
47*5a6e8488SAndroid Build Coastguard Worker 
48*5a6e8488SAndroid Build Coastguard Worker // The following are flags that can be passed to @a BcParseExpr functions. They
49*5a6e8488SAndroid Build Coastguard Worker // define the requirements that the parsed expression must meet to not have an
50*5a6e8488SAndroid Build Coastguard Worker // error thrown.
51*5a6e8488SAndroid Build Coastguard Worker 
52*5a6e8488SAndroid Build Coastguard Worker /// A flag that requires that the expression is valid for conditionals in for
53*5a6e8488SAndroid Build Coastguard Worker /// loops, while loops, and if statements. This is because POSIX requires that
54*5a6e8488SAndroid Build Coastguard Worker /// certain operators are *only* used in those cases. It's whacked, but that's
55*5a6e8488SAndroid Build Coastguard Worker /// how it is.
56*5a6e8488SAndroid Build Coastguard Worker #define BC_PARSE_REL (UINTMAX_C(1) << 0)
57*5a6e8488SAndroid Build Coastguard Worker 
58*5a6e8488SAndroid Build Coastguard Worker /// A flag that requires that the expression is valid for a print statement.
59*5a6e8488SAndroid Build Coastguard Worker #define BC_PARSE_PRINT (UINTMAX_C(1) << 1)
60*5a6e8488SAndroid Build Coastguard Worker 
61*5a6e8488SAndroid Build Coastguard Worker /// A flag that requires that the expression does *not* have any function call.
62*5a6e8488SAndroid Build Coastguard Worker #define BC_PARSE_NOCALL (UINTMAX_C(1) << 2)
63*5a6e8488SAndroid Build Coastguard Worker 
64*5a6e8488SAndroid Build Coastguard Worker /// A flag that requires that the expression does *not* have a read()
65*5a6e8488SAndroid Build Coastguard Worker /// expression.
66*5a6e8488SAndroid Build Coastguard Worker #define BC_PARSE_NOREAD (UINTMAX_C(1) << 3)
67*5a6e8488SAndroid Build Coastguard Worker 
68*5a6e8488SAndroid Build Coastguard Worker /// A flag that *allows* (rather than requires) that an array appear in the
69*5a6e8488SAndroid Build Coastguard Worker /// expression. This is mostly used as parameters in bc.
70*5a6e8488SAndroid Build Coastguard Worker #define BC_PARSE_ARRAY (UINTMAX_C(1) << 4)
71*5a6e8488SAndroid Build Coastguard Worker 
72*5a6e8488SAndroid Build Coastguard Worker /// A flag that requires that the expression is not empty and returns a value.
73*5a6e8488SAndroid Build Coastguard Worker #define BC_PARSE_NEEDVAL (UINTMAX_C(1) << 5)
74*5a6e8488SAndroid Build Coastguard Worker 
75*5a6e8488SAndroid Build Coastguard Worker /**
76*5a6e8488SAndroid Build Coastguard Worker  * Returns true if the parser has been initialized.
77*5a6e8488SAndroid Build Coastguard Worker  * @param p    The parser.
78*5a6e8488SAndroid Build Coastguard Worker  * @param prg  The program.
79*5a6e8488SAndroid Build Coastguard Worker  * @return     True if @a p has been initialized, false otherwise.
80*5a6e8488SAndroid Build Coastguard Worker  */
81*5a6e8488SAndroid Build Coastguard Worker #define BC_PARSE_IS_INITED(p, prg) ((p)->prog == (prg))
82*5a6e8488SAndroid Build Coastguard Worker 
83*5a6e8488SAndroid Build Coastguard Worker /**
84*5a6e8488SAndroid Build Coastguard Worker  * Returns true if the current parser state allows parsing, false otherwise.
85*5a6e8488SAndroid Build Coastguard Worker  * @param p  The parser.
86*5a6e8488SAndroid Build Coastguard Worker  * @return   True if parsing can proceed, false otherwise.
87*5a6e8488SAndroid Build Coastguard Worker  */
88*5a6e8488SAndroid Build Coastguard Worker #define BC_PARSE_CAN_PARSE(p) ((p).l.t != BC_LEX_EOF)
89*5a6e8488SAndroid Build Coastguard Worker 
90*5a6e8488SAndroid Build Coastguard Worker /**
91*5a6e8488SAndroid Build Coastguard Worker  * Pushes the instruction @a i onto the bytecode vector for the current
92*5a6e8488SAndroid Build Coastguard Worker  * function.
93*5a6e8488SAndroid Build Coastguard Worker  * @param p  The parser.
94*5a6e8488SAndroid Build Coastguard Worker  * @param i  The instruction to push onto the bytecode vector.
95*5a6e8488SAndroid Build Coastguard Worker  */
96*5a6e8488SAndroid Build Coastguard Worker #define bc_parse_push(p, i) (bc_vec_pushByte(&(p)->func->code, (uchar) (i)))
97*5a6e8488SAndroid Build Coastguard Worker 
98*5a6e8488SAndroid Build Coastguard Worker /**
99*5a6e8488SAndroid Build Coastguard Worker  * Pushes an index onto the bytecode vector. For more information, see
100*5a6e8488SAndroid Build Coastguard Worker  * @a bc_vec_pushIndex() in src/vector.c and @a bc_program_index() in
101*5a6e8488SAndroid Build Coastguard Worker  * src/program.c.
102*5a6e8488SAndroid Build Coastguard Worker  * @param p    The parser.
103*5a6e8488SAndroid Build Coastguard Worker  * @param idx  The index to push onto the bytecode vector.
104*5a6e8488SAndroid Build Coastguard Worker  */
105*5a6e8488SAndroid Build Coastguard Worker #define bc_parse_pushIndex(p, idx) (bc_vec_pushIndex(&(p)->func->code, (idx)))
106*5a6e8488SAndroid Build Coastguard Worker 
107*5a6e8488SAndroid Build Coastguard Worker /**
108*5a6e8488SAndroid Build Coastguard Worker  * A convenience macro for throwing errors in parse code. This takes care of
109*5a6e8488SAndroid Build Coastguard Worker  * plumbing like passing in the current line the lexer is on.
110*5a6e8488SAndroid Build Coastguard Worker  * @param p  The parser.
111*5a6e8488SAndroid Build Coastguard Worker  * @param e  The error.
112*5a6e8488SAndroid Build Coastguard Worker  */
113*5a6e8488SAndroid Build Coastguard Worker #if BC_DEBUG
114*5a6e8488SAndroid Build Coastguard Worker #define bc_parse_err(p, e) \
115*5a6e8488SAndroid Build Coastguard Worker 	(bc_vm_handleError((e), __FILE__, __LINE__, (p)->l.line))
116*5a6e8488SAndroid Build Coastguard Worker #else // BC_DEBUG
117*5a6e8488SAndroid Build Coastguard Worker #define bc_parse_err(p, e) (bc_vm_handleError((e), (p)->l.line))
118*5a6e8488SAndroid Build Coastguard Worker #endif // BC_DEBUG
119*5a6e8488SAndroid Build Coastguard Worker 
120*5a6e8488SAndroid Build Coastguard Worker /**
121*5a6e8488SAndroid Build Coastguard Worker  * A convenience macro for throwing errors in parse code. This takes care of
122*5a6e8488SAndroid Build Coastguard Worker  * plumbing like passing in the current line the lexer is on.
123*5a6e8488SAndroid Build Coastguard Worker  * @param p    The parser.
124*5a6e8488SAndroid Build Coastguard Worker  * @param e    The error.
125*5a6e8488SAndroid Build Coastguard Worker  * @param ...  The varags that are needed.
126*5a6e8488SAndroid Build Coastguard Worker  */
127*5a6e8488SAndroid Build Coastguard Worker #if BC_DEBUG
128*5a6e8488SAndroid Build Coastguard Worker #define bc_parse_verr(p, e, ...) \
129*5a6e8488SAndroid Build Coastguard Worker 	(bc_vm_handleError((e), __FILE__, __LINE__, (p)->l.line, __VA_ARGS__))
130*5a6e8488SAndroid Build Coastguard Worker #else // BC_DEBUG
131*5a6e8488SAndroid Build Coastguard Worker #define bc_parse_verr(p, e, ...) \
132*5a6e8488SAndroid Build Coastguard Worker 	(bc_vm_handleError((e), (p)->l.line, __VA_ARGS__))
133*5a6e8488SAndroid Build Coastguard Worker #endif // BC_DEBUG
134*5a6e8488SAndroid Build Coastguard Worker 
135*5a6e8488SAndroid Build Coastguard Worker // Forward declarations.
136*5a6e8488SAndroid Build Coastguard Worker struct BcParse;
137*5a6e8488SAndroid Build Coastguard Worker struct BcProgram;
138*5a6e8488SAndroid Build Coastguard Worker 
139*5a6e8488SAndroid Build Coastguard Worker /**
140*5a6e8488SAndroid Build Coastguard Worker  * A function pointer to call when more parsing is needed.
141*5a6e8488SAndroid Build Coastguard Worker  * @param p  The parser.
142*5a6e8488SAndroid Build Coastguard Worker  */
143*5a6e8488SAndroid Build Coastguard Worker typedef void (*BcParseParse)(struct BcParse* p);
144*5a6e8488SAndroid Build Coastguard Worker 
145*5a6e8488SAndroid Build Coastguard Worker /**
146*5a6e8488SAndroid Build Coastguard Worker  * A function pointer to call when an expression needs to be parsed. This can
147*5a6e8488SAndroid Build Coastguard Worker  * happen for read() expressions or dc strings.
148*5a6e8488SAndroid Build Coastguard Worker  * @param p      The parser.
149*5a6e8488SAndroid Build Coastguard Worker  * @param flags  The flags for what is allowed or required. (See flags above.)
150*5a6e8488SAndroid Build Coastguard Worker  */
151*5a6e8488SAndroid Build Coastguard Worker typedef void (*BcParseExpr)(struct BcParse* p, uint8_t flags);
152*5a6e8488SAndroid Build Coastguard Worker 
153*5a6e8488SAndroid Build Coastguard Worker /// The parser struct.
154*5a6e8488SAndroid Build Coastguard Worker typedef struct BcParse
155*5a6e8488SAndroid Build Coastguard Worker {
156*5a6e8488SAndroid Build Coastguard Worker 	/// The lexer.
157*5a6e8488SAndroid Build Coastguard Worker 	BcLex l;
158*5a6e8488SAndroid Build Coastguard Worker 
159*5a6e8488SAndroid Build Coastguard Worker #if BC_ENABLED
160*5a6e8488SAndroid Build Coastguard Worker 	/// The stack of flags for bc. (See comments in include/bc.h.) This stack is
161*5a6e8488SAndroid Build Coastguard Worker 	/// *required* to have one item at all times. Not maintaining that invariant
162*5a6e8488SAndroid Build Coastguard Worker 	/// will cause problems.
163*5a6e8488SAndroid Build Coastguard Worker 	BcVec flags;
164*5a6e8488SAndroid Build Coastguard Worker 
165*5a6e8488SAndroid Build Coastguard Worker 	/// The stack of exits. These are indices into the bytecode vector where
166*5a6e8488SAndroid Build Coastguard Worker 	/// blocks for loops and if statements end. Basically, these are the places
167*5a6e8488SAndroid Build Coastguard Worker 	/// to jump to when skipping code.
168*5a6e8488SAndroid Build Coastguard Worker 	BcVec exits;
169*5a6e8488SAndroid Build Coastguard Worker 
170*5a6e8488SAndroid Build Coastguard Worker 	/// The stack of conditionals. Unlike exits, which are indices to jump
171*5a6e8488SAndroid Build Coastguard Worker 	/// *forward* to, this is a vector of indices to jump *backward* to, usually
172*5a6e8488SAndroid Build Coastguard Worker 	/// to the conditional of a loop, hence the name.
173*5a6e8488SAndroid Build Coastguard Worker 	BcVec conds;
174*5a6e8488SAndroid Build Coastguard Worker 
175*5a6e8488SAndroid Build Coastguard Worker 	/// A stack of operators. When parsing expressions, the bc parser uses the
176*5a6e8488SAndroid Build Coastguard Worker 	/// Shunting-Yard algorithm, which requires a stack of operators. This can
177*5a6e8488SAndroid Build Coastguard Worker 	/// hold the stack for multiple expressions at once because the expressions
178*5a6e8488SAndroid Build Coastguard Worker 	/// stack as well. For more information, see the Expression Parsing section
179*5a6e8488SAndroid Build Coastguard Worker 	/// of the Development manual (manuals/development.md).
180*5a6e8488SAndroid Build Coastguard Worker 	BcVec ops;
181*5a6e8488SAndroid Build Coastguard Worker 
182*5a6e8488SAndroid Build Coastguard Worker 	/// A buffer to temporarily store a string in. This is because the lexer
183*5a6e8488SAndroid Build Coastguard Worker 	/// might generate a string as part of its work, and the parser needs that
184*5a6e8488SAndroid Build Coastguard Worker 	/// string, but it also needs the lexer to continue lexing, which might
185*5a6e8488SAndroid Build Coastguard Worker 	/// overwrite the string stored in the lexer. This buffer is for copying
186*5a6e8488SAndroid Build Coastguard Worker 	/// that string from the lexer to keep it safe.
187*5a6e8488SAndroid Build Coastguard Worker 	BcVec buf;
188*5a6e8488SAndroid Build Coastguard Worker #endif // BC_ENABLED
189*5a6e8488SAndroid Build Coastguard Worker 
190*5a6e8488SAndroid Build Coastguard Worker 	/// A reference to the program to grab the current function when necessary.
191*5a6e8488SAndroid Build Coastguard Worker 	struct BcProgram* prog;
192*5a6e8488SAndroid Build Coastguard Worker 
193*5a6e8488SAndroid Build Coastguard Worker 	/// A reference to the current function. The function is what holds the
194*5a6e8488SAndroid Build Coastguard Worker 	/// bytecode vector that the parser is filling.
195*5a6e8488SAndroid Build Coastguard Worker 	BcFunc* func;
196*5a6e8488SAndroid Build Coastguard Worker 
197*5a6e8488SAndroid Build Coastguard Worker 	/// The index of the function.
198*5a6e8488SAndroid Build Coastguard Worker 	size_t fidx;
199*5a6e8488SAndroid Build Coastguard Worker 
200*5a6e8488SAndroid Build Coastguard Worker #if BC_ENABLED
201*5a6e8488SAndroid Build Coastguard Worker 	/// True if the bc parser just entered a function and an auto statement
202*5a6e8488SAndroid Build Coastguard Worker 	/// would be valid.
203*5a6e8488SAndroid Build Coastguard Worker 	bool auto_part;
204*5a6e8488SAndroid Build Coastguard Worker #endif // BC_ENABLED
205*5a6e8488SAndroid Build Coastguard Worker 
206*5a6e8488SAndroid Build Coastguard Worker } BcParse;
207*5a6e8488SAndroid Build Coastguard Worker 
208*5a6e8488SAndroid Build Coastguard Worker /**
209*5a6e8488SAndroid Build Coastguard Worker  * Initializes a parser.
210*5a6e8488SAndroid Build Coastguard Worker  * @param p     The parser to initialize.
211*5a6e8488SAndroid Build Coastguard Worker  * @param prog  A referenc to the program.
212*5a6e8488SAndroid Build Coastguard Worker  * @param func  The index of the current function.
213*5a6e8488SAndroid Build Coastguard Worker  */
214*5a6e8488SAndroid Build Coastguard Worker void
215*5a6e8488SAndroid Build Coastguard Worker bc_parse_init(BcParse* p, struct BcProgram* prog, size_t func);
216*5a6e8488SAndroid Build Coastguard Worker 
217*5a6e8488SAndroid Build Coastguard Worker /**
218*5a6e8488SAndroid Build Coastguard Worker  * Frees a parser. This is not guarded by #if BC_DEBUG because a separate
219*5a6e8488SAndroid Build Coastguard Worker  * parser is created at runtime to parse read() expressions and dc strings.
220*5a6e8488SAndroid Build Coastguard Worker  * @param p  The parser to free.
221*5a6e8488SAndroid Build Coastguard Worker  */
222*5a6e8488SAndroid Build Coastguard Worker void
223*5a6e8488SAndroid Build Coastguard Worker bc_parse_free(BcParse* p);
224*5a6e8488SAndroid Build Coastguard Worker 
225*5a6e8488SAndroid Build Coastguard Worker /**
226*5a6e8488SAndroid Build Coastguard Worker  * Resets the parser. Resetting means erasing all state to the point that the
227*5a6e8488SAndroid Build Coastguard Worker  * parser would think it was just initialized.
228*5a6e8488SAndroid Build Coastguard Worker  * @param p  The parser to reset.
229*5a6e8488SAndroid Build Coastguard Worker  */
230*5a6e8488SAndroid Build Coastguard Worker void
231*5a6e8488SAndroid Build Coastguard Worker bc_parse_reset(BcParse* p);
232*5a6e8488SAndroid Build Coastguard Worker 
233*5a6e8488SAndroid Build Coastguard Worker /**
234*5a6e8488SAndroid Build Coastguard Worker  * Adds a string. See @a BcProgram in include/program.h for more details.
235*5a6e8488SAndroid Build Coastguard Worker  * @param p  The parser that parsed the string.
236*5a6e8488SAndroid Build Coastguard Worker  */
237*5a6e8488SAndroid Build Coastguard Worker void
238*5a6e8488SAndroid Build Coastguard Worker bc_parse_addString(BcParse* p);
239*5a6e8488SAndroid Build Coastguard Worker 
240*5a6e8488SAndroid Build Coastguard Worker /**
241*5a6e8488SAndroid Build Coastguard Worker  * Adds a number. See @a BcProgram in include/program.h for more details.
242*5a6e8488SAndroid Build Coastguard Worker  * @param p  The parser that parsed the number.
243*5a6e8488SAndroid Build Coastguard Worker  */
244*5a6e8488SAndroid Build Coastguard Worker void
245*5a6e8488SAndroid Build Coastguard Worker bc_parse_number(BcParse* p);
246*5a6e8488SAndroid Build Coastguard Worker 
247*5a6e8488SAndroid Build Coastguard Worker /**
248*5a6e8488SAndroid Build Coastguard Worker  * Update the current function in the parser.
249*5a6e8488SAndroid Build Coastguard Worker  * @param p     The parser.
250*5a6e8488SAndroid Build Coastguard Worker  * @param fidx  The index of the new function.
251*5a6e8488SAndroid Build Coastguard Worker  */
252*5a6e8488SAndroid Build Coastguard Worker void
253*5a6e8488SAndroid Build Coastguard Worker bc_parse_updateFunc(BcParse* p, size_t fidx);
254*5a6e8488SAndroid Build Coastguard Worker 
255*5a6e8488SAndroid Build Coastguard Worker /**
256*5a6e8488SAndroid Build Coastguard Worker  * Adds a new variable or array. See @a BcProgram in include/program.h for more
257*5a6e8488SAndroid Build Coastguard Worker  * details.
258*5a6e8488SAndroid Build Coastguard Worker  * @param p     The parser that parsed the variable or array name.
259*5a6e8488SAndroid Build Coastguard Worker  * @param name  The name of the variable or array to add.
260*5a6e8488SAndroid Build Coastguard Worker  * @param var   True if the name is for a variable, false if it's for an array.
261*5a6e8488SAndroid Build Coastguard Worker  */
262*5a6e8488SAndroid Build Coastguard Worker void
263*5a6e8488SAndroid Build Coastguard Worker bc_parse_pushName(const BcParse* p, char* name, bool var);
264*5a6e8488SAndroid Build Coastguard Worker 
265*5a6e8488SAndroid Build Coastguard Worker /**
266*5a6e8488SAndroid Build Coastguard Worker  * Sets the text that the parser will parse.
267*5a6e8488SAndroid Build Coastguard Worker  * @param p     The parser.
268*5a6e8488SAndroid Build Coastguard Worker  * @param text  The text to lex.
269*5a6e8488SAndroid Build Coastguard Worker  * @param mode  The mode to parse in.
270*5a6e8488SAndroid Build Coastguard Worker  */
271*5a6e8488SAndroid Build Coastguard Worker void
272*5a6e8488SAndroid Build Coastguard Worker bc_parse_text(BcParse* p, const char* text, BcMode mode);
273*5a6e8488SAndroid Build Coastguard Worker 
274*5a6e8488SAndroid Build Coastguard Worker // References to const 0 and 1 strings for special cases. bc and dc have
275*5a6e8488SAndroid Build Coastguard Worker // specific instructions for 0 and 1 because they pop up so often and (in the
276*5a6e8488SAndroid Build Coastguard Worker // case of 1), increment/decrement operators.
277*5a6e8488SAndroid Build Coastguard Worker extern const char bc_parse_zero[2];
278*5a6e8488SAndroid Build Coastguard Worker extern const char bc_parse_one[2];
279*5a6e8488SAndroid Build Coastguard Worker 
280*5a6e8488SAndroid Build Coastguard Worker #endif // BC_PARSE_H
281