Mercurial > ~dholland > hg > ag > index.cgi
comparison examples/mpp/mpp.h @ 0:13d2b8934445
Import AnaGram (near-)release tree into Mercurial.
author | David A. Holland |
---|---|
date | Sat, 22 Dec 2007 17:52:45 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:13d2b8934445 |
---|---|
1 /* | |
2 * AnaGram, a System for Syntax Directed Programming | |
3 * C Macro preprocessor | |
4 * Global Definitions | |
5 * | |
6 * Copyright 1993 Parsifal Software. All Rights Reserved. | |
7 * | |
8 * This software is provided 'as-is', without any express or implied | |
9 * warranty. In no event will the authors be held liable for any damages | |
10 * arising from the use of this software. | |
11 * | |
12 * Permission is granted to anyone to use this software for any purpose, | |
13 * including commercial applications, and to alter it and redistribute it | |
14 * freely, subject to the following restrictions: | |
15 * | |
16 * 1. The origin of this software must not be misrepresented; you must not | |
17 * claim that you wrote the original software. If you use this software | |
18 * in a product, an acknowledgment in the product documentation would be | |
19 * appreciated but is not required. | |
20 * 2. Altered source versions must be plainly marked as such, and must not be | |
21 * misrepresented as being the original software. | |
22 * 3. This notice may not be removed or altered from any source distribution. | |
23 */ | |
24 | |
25 #ifndef MPP_H | |
26 #define MPP_H | |
27 | |
28 | |
29 //#define NDEBUG | |
30 #include "token.h" | |
31 #include <charsink.h> | |
32 #include <stack.h> | |
33 #include <strdict.h> | |
34 #include "ex.h" | |
35 | |
36 #include "krc.h" | |
37 //#include "jrc.h" | |
38 | |
39 #define N_MACROS 500 // max number of macros | |
40 #define N_SYMBOLS 5000 // size of token dictionary | |
41 | |
42 enum symbol_type_enum {identifier, typedef_name}; | |
43 | |
44 struct macro_descriptor { | |
45 unsigned name; // token dictionary index of name | |
46 unsigned* arg_names; // pointer to list of parameter names | |
47 unsigned n_args; // number of parameters | |
48 token *body; // body of macro | |
49 unsigned busy_flag : 1; // set when macro should not be expanded | |
50 unsigned parens : 1; // set if macro defined with parens | |
51 }; | |
52 | |
53 struct op_descriptor { | |
54 const char *op; | |
55 token_id id; | |
56 }; | |
57 | |
58 | |
59 // Parser classes | |
60 | |
61 // Expression evaluator | |
62 // member functions are in EX.SYN | |
63 | |
64 class expression_evaluator : public token_sink { | |
65 ex_pcb_type pcb; | |
66 public: | |
67 expression_evaluator(); | |
68 friend token_sink& reset(expression_evaluator &); | |
69 token_sink& operator << (token t); | |
70 token_sink& operator << (token *tp); | |
71 operator long(); | |
72 // friend int error(expression_evaluator &); | |
73 }; | |
74 | |
75 | |
76 // C parser | |
77 // Member Functions are in JRC.SYN or KRC.SYN | |
78 | |
79 class c_parser: public token_sink { | |
80 public: | |
81 cc_pcb_type pcb; | |
82 c_parser(); | |
83 ~c_parser(); | |
84 token_sink &operator << (token); | |
85 token_sink& operator << (token *); | |
86 // friend int error(c_parser &p); | |
87 friend c_parser &reset(c_parser &); | |
88 }; | |
89 | |
90 | |
91 // Global variables | |
92 // Variables are defined in mpp.cpp | |
93 | |
94 extern expression_evaluator condition; | |
95 extern char default_path[]; | |
96 extern unsigned defined_value; | |
97 extern int if_clause; | |
98 extern macro_descriptor macro[]; | |
99 extern unsigned macro_id[]; | |
100 extern int n_macros; | |
101 extern unsigned n_reserved_words; | |
102 extern int nest_comments; | |
103 extern unsigned one_value; | |
104 extern stack<char *> paths; | |
105 extern op_descriptor reserved_words[]; | |
106 extern string_accumulator sa; | |
107 extern token_accumulator ta; | |
108 extern token_sink *scanner_sink; | |
109 extern string_dictionary td; | |
110 extern unsigned token_handles[]; | |
111 extern unsigned zero_value; | |
112 | |
113 | |
114 // Function declarations | |
115 | |
116 token_id classify_token(char *); // ct.syn | |
117 void expand_macro(token, unsigned); // asc.syn | |
118 void expand_text(token *, int = 0, unsigned * = NULL); // asc.syn | |
119 void scan_input(char *); // ts.syn | |
120 void syntax_error(const char *); // ts.syn | |
121 | |
122 #endif |