xref: /aosp_15_r20/external/bc/include/dc.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 dc only.
33*5a6e8488SAndroid Build Coastguard Worker  *
34*5a6e8488SAndroid Build Coastguard Worker  */
35*5a6e8488SAndroid Build Coastguard Worker 
36*5a6e8488SAndroid Build Coastguard Worker #ifndef BC_DC_H
37*5a6e8488SAndroid Build Coastguard Worker #define BC_DC_H
38*5a6e8488SAndroid Build Coastguard Worker 
39*5a6e8488SAndroid Build Coastguard Worker #if DC_ENABLED
40*5a6e8488SAndroid Build Coastguard Worker 
41*5a6e8488SAndroid Build Coastguard Worker #include <status.h>
42*5a6e8488SAndroid Build Coastguard Worker #include <lex.h>
43*5a6e8488SAndroid Build Coastguard Worker #include <parse.h>
44*5a6e8488SAndroid Build Coastguard Worker 
45*5a6e8488SAndroid Build Coastguard Worker /**
46*5a6e8488SAndroid Build Coastguard Worker  * The main function for dc. It just sets variables and passes its arguments
47*5a6e8488SAndroid Build Coastguard Worker  * through to @a bc_vm_boot().
48*5a6e8488SAndroid Build Coastguard Worker  * @return  A status.
49*5a6e8488SAndroid Build Coastguard Worker  */
50*5a6e8488SAndroid Build Coastguard Worker BcStatus
51*5a6e8488SAndroid Build Coastguard Worker dc_main(int argc, const char* argv[]);
52*5a6e8488SAndroid Build Coastguard Worker 
53*5a6e8488SAndroid Build Coastguard Worker // A reference to the dc help text.
54*5a6e8488SAndroid Build Coastguard Worker extern const char dc_help[];
55*5a6e8488SAndroid Build Coastguard Worker 
56*5a6e8488SAndroid Build Coastguard Worker /**
57*5a6e8488SAndroid Build Coastguard Worker  * The @a BcLexNext function for dc. (See include/lex.h for a definition of
58*5a6e8488SAndroid Build Coastguard Worker  * @a BcLexNext.)
59*5a6e8488SAndroid Build Coastguard Worker  * @param l  The lexer.
60*5a6e8488SAndroid Build Coastguard Worker  */
61*5a6e8488SAndroid Build Coastguard Worker void
62*5a6e8488SAndroid Build Coastguard Worker dc_lex_token(BcLex* l);
63*5a6e8488SAndroid Build Coastguard Worker 
64*5a6e8488SAndroid Build Coastguard Worker /**
65*5a6e8488SAndroid Build Coastguard Worker  * Returns true if the negative char `_` should be treated as a command or not.
66*5a6e8488SAndroid Build Coastguard Worker  * dc considers negative a command if it does *not* immediately proceed a
67*5a6e8488SAndroid Build Coastguard Worker  * number. Otherwise, it's just considered a negative.
68*5a6e8488SAndroid Build Coastguard Worker  * @param l  The lexer.
69*5a6e8488SAndroid Build Coastguard Worker  * @return   True if a negative should be treated as a command, false if it
70*5a6e8488SAndroid Build Coastguard Worker  *           should be treated as a negative sign on a number.
71*5a6e8488SAndroid Build Coastguard Worker  */
72*5a6e8488SAndroid Build Coastguard Worker bool
73*5a6e8488SAndroid Build Coastguard Worker dc_lex_negCommand(BcLex* l);
74*5a6e8488SAndroid Build Coastguard Worker 
75*5a6e8488SAndroid Build Coastguard Worker // References to the signal message and its length.
76*5a6e8488SAndroid Build Coastguard Worker extern const char dc_sig_msg[];
77*5a6e8488SAndroid Build Coastguard Worker extern const uchar dc_sig_msg_len;
78*5a6e8488SAndroid Build Coastguard Worker 
79*5a6e8488SAndroid Build Coastguard Worker // References to an array and its length. This array is an array of lex tokens
80*5a6e8488SAndroid Build Coastguard Worker // that, when encountered, should be treated as commands that take a register.
81*5a6e8488SAndroid Build Coastguard Worker extern const uint8_t dc_lex_regs[];
82*5a6e8488SAndroid Build Coastguard Worker extern const size_t dc_lex_regs_len;
83*5a6e8488SAndroid Build Coastguard Worker 
84*5a6e8488SAndroid Build Coastguard Worker // References to an array of tokens and its length. This array corresponds to
85*5a6e8488SAndroid Build Coastguard Worker // the ASCII table, starting at double quotes. This makes it easy to look up
86*5a6e8488SAndroid Build Coastguard Worker // tokens for characters.
87*5a6e8488SAndroid Build Coastguard Worker extern const uint8_t dc_lex_tokens[];
88*5a6e8488SAndroid Build Coastguard Worker extern const uint8_t dc_parse_insts[];
89*5a6e8488SAndroid Build Coastguard Worker 
90*5a6e8488SAndroid Build Coastguard Worker /**
91*5a6e8488SAndroid Build Coastguard Worker  * The @a BcParseParse function for dc. (See include/parse.h for a definition of
92*5a6e8488SAndroid Build Coastguard Worker  * @a BcParseParse.)
93*5a6e8488SAndroid Build Coastguard Worker  * @param p  The parser.
94*5a6e8488SAndroid Build Coastguard Worker  */
95*5a6e8488SAndroid Build Coastguard Worker void
96*5a6e8488SAndroid Build Coastguard Worker dc_parse_parse(BcParse* p);
97*5a6e8488SAndroid Build Coastguard Worker 
98*5a6e8488SAndroid Build Coastguard Worker /**
99*5a6e8488SAndroid Build Coastguard Worker  * The @a BcParseExpr function for dc. (See include/parse.h for a definition of
100*5a6e8488SAndroid Build Coastguard Worker  * @a BcParseExpr.)
101*5a6e8488SAndroid Build Coastguard Worker  * @param p      The parser.
102*5a6e8488SAndroid Build Coastguard Worker  * @param flags  Flags that define the requirements that the parsed code must
103*5a6e8488SAndroid Build Coastguard Worker  *               meet or an error will result. See @a BcParseExpr for more info.
104*5a6e8488SAndroid Build Coastguard Worker  */
105*5a6e8488SAndroid Build Coastguard Worker void
106*5a6e8488SAndroid Build Coastguard Worker dc_parse_expr(BcParse* p, uint8_t flags);
107*5a6e8488SAndroid Build Coastguard Worker 
108*5a6e8488SAndroid Build Coastguard Worker #endif // DC_ENABLED
109*5a6e8488SAndroid Build Coastguard Worker 
110*5a6e8488SAndroid Build Coastguard Worker #endif // BC_DC_H
111