Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/lib/libexpr/exlib.h
1808 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 1989-2012 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Glenn Fowler <[email protected]> *
18
* *
19
***********************************************************************/
20
#pragma prototyped
21
/*
22
* Glenn Fowler
23
* AT&T Research
24
*
25
* expression library private definitions
26
*/
27
28
#ifndef _EXLIB_H
29
#define _EXLIB_H
30
31
#include <align.h>
32
#include <ast.h>
33
34
typedef struct Exinput_s /* input stack */
35
{
36
struct Exinput_s*next; /* next in stack */
37
int close; /* close fp on pop */
38
char* file; /* previous file */
39
Sfio_t* fp; /* expression file pointer */
40
int line; /* previous line */
41
int nesting; /* expression nesting level */
42
int peek; /* 1 char peek */
43
int unit; /* first frame in parse unit */
44
char* pushback; /* pushback buffer */
45
char* bp; /* expression string base */
46
char* pp; /* pushback pointer */
47
char* sp; /* expression string pointer */
48
} Exinput_t;
49
50
typedef struct Print_s /* compiled printf arg node */
51
{
52
struct Print_s* next; /* next arg */
53
char* format; /* printf format for arg */
54
struct Exnode_s*param[3]; /* 0:width 1:precision 2:base */
55
struct Exnode_s*arg; /* arg to format */
56
} Print_t;
57
58
#define _EX_DATA_PRIVATE_ \
59
Exnode_t* next; /* free list link */ \
60
Extype_t value; /* dynamic variable value */ \
61
struct \
62
{ \
63
Exid_t* procedure; /* called procedure */ \
64
Exnode_t* args; /* actual argument list */ \
65
} call; /* procedure call */ \
66
struct \
67
{ \
68
Exnode_t* array; /* array name */ \
69
Exid_t* index; /* array index */ \
70
Exnode_t* statement; /* statement to apply */ \
71
} generate; /* associative array generator */ \
72
struct \
73
{ \
74
Exnode_t* descriptor; /* Expr_t.file index */ \
75
Print_t* args; /* compiler printf args */ \
76
} print; /* printf */ \
77
struct \
78
{ \
79
Exnode_t* args; /* formal arg list */ \
80
Exnode_t* body; /* body */ \
81
Dt_t* frame; /* local symbol frame */ \
82
int arity; /* # formal args */ \
83
} procedure; /* procedure args and body */ \
84
struct \
85
{ \
86
Exnode_t* descriptor; /* Expr_t.file index */ \
87
Exnode_t* format; /* format arg */ \
88
Exnode_t* args; /* actual args */ \
89
} scan; /* printf */
90
91
#define _EX_NODE_PRIVATE_ \
92
Exshort_t subop; /* operator qualifier */ \
93
Exshort_t pad_2; /* padding */
94
95
#define _EX_PROG_PRIVATE_ \
96
Vmalloc_t* ve; /* eval tmp region */ \
97
Dt_t* frame; /* frame symbol table */ \
98
Dtdisc_t symdisc; /* Expr_t.symbols discipline */ \
99
Exdisc_t* disc; /* user discipline */ \
100
Exinput_t* input; /* input stack */ \
101
Expr_t* program; /* previous program on stack */ \
102
Sfio_t* tmp; /* tmp string buffer */ \
103
Extype_t loopret; /* return value */ \
104
Exid_t main; /* main procedure */ \
105
char line[512]; /* last few input tokens */ \
106
char* linep; /* line[] pointer */ \
107
int eof; /* lex hit eof */ \
108
int errors; /* fatal error count */ \
109
int formals; /* parsing formal args */ \
110
int linewrap; /* linep wrapped around line[] */ \
111
int loopcount; /* break|continue|return count */ \
112
int loopop; /* break|continue|return op */ \
113
int nesting; /* exstatement() nesting */
114
115
#include <expr.h>
116
#include <ctype.h>
117
#include <error.h>
118
119
#define cast excast
120
#define id_string (&exbuiltin[0])
121
122
#define exunlex(p,c) ((p)->linep--,(p)->input->peek=(c))
123
#define putcontext(p,c) (((p)->linep>=&(p)->line[sizeof((p)->line)]?(p)->linep=(p)->line,(p)->linewrap=1:0),*(p)->linep++=(c))
124
#define setcontext(p) ((p)->linep=(p)->line,(p)->linewrap=0)
125
126
typedef struct Switch_s /* switch parse state */
127
{
128
struct Switch_s*prev; /* previous switch state */
129
Exnode_t* firstcase; /* first case block */
130
Exnode_t* lastcase; /* last case block */
131
Exnode_t* defcase; /* default case block */
132
Extype_t** base; /* label base pointer */
133
Extype_t** cur; /* current label pointer */
134
Extype_t** last; /* last label pointer */
135
int def; /* default label hit */
136
int type; /* switch test type */
137
} Switch_t;
138
139
typedef struct Exassoc_s /* associative array bucket */
140
{
141
Dtlink_t link; /* table link */
142
Extype_t value; /* value */
143
char name[1]; /* index name */
144
} Exassoc_t;
145
146
typedef struct Exstate_s /* ex global state */
147
{
148
Exid_t* id; /* current declaration id */
149
int declare; /* current declaration type */
150
Exref_t* lastref; /* last in . reference list */
151
int nolabel; /* <id>':' not a label */
152
Exinput_t null; /* null input */
153
Expr_t* program; /* current program */
154
Exnode_t* procedure; /* current procedure */
155
Exref_t* refs; /* . reference list */
156
int assigned; /* declaration assignment */
157
int instatic; /* static declaration */
158
int statics; /* static used */
159
Switch_t* swstate; /* switch parse state */
160
char nullstring[1]; /* "" */
161
} Exstate_t;
162
163
extern Exid_t exbuiltin[];
164
extern const char* exversion;
165
extern Exstate_t expr;
166
167
extern int exparse(void); /* yacc should do this */
168
169
#endif
170
171