22#if !defined(_EXGRAM_H) && ( defined(MINTOKEN) || defined(YYTOKENTYPE) )
32#define ex_lex() extoken_fn(expr.program)
34#define ALLOCATE(p,x) exalloc(p,sizeof(x))
81 if (x->
data.call.args)
134 if (x->
data.string.repl)
139 if (x->
data.split.seps)
142 if (x->
data.split.array->local) {
152 if (x->
data.print.descriptor)
154 pn = x->
data.print.args;
206 exerror(
"in %s, array %s must have integer index type, not %s",
209 exerror(
"in %s, array %s entries must have string type, not %s",
212 exerror(
"first argument to %s must have string type, not %s",
215 exerror(
"third argument to %s must have string type, not %s",
218 ss->
data.split.array = dyn;
219 ss->
data.split.string =
s;
220 ss->
data.split.seps = seps;
234 base = extract(p, &args,
STRING);
236 exerror(
"invalid first argument to sub operator");
237 pat = extract(p, &args,
STRING);
239 exerror(
"invalid second argument to sub operator");
241 repl = extract(p, &args,
STRING);
243 exerror(
"invalid third argument to sub operator");
247 exerror(
"too many arguments to sub operator");
249 ss->
data.string.base = base;
250 ss->
data.string.pat = pat;
251 ss->
data.string.repl = repl;
264 base = extract(p, &args,
STRING);
266 exerror(
"invalid first argument to substr operator");
267 pat = extract(p, &args,
INTEGER);
269 exerror(
"invalid second argument to substr operator");
271 repl = extract(p, &args,
INTEGER);
273 exerror(
"invalid third argument to substr operator");
277 exerror(
"too many arguments to substr operator");
279 ss->
data.string.base = base;
280 ss->
data.string.pat = pat;
281 ss->
data.string.repl = repl;
301 if (p->disc->stringof(p, x, 1) < 0) {
302 exerror(
"cannot convert %s to STRING",
317 if (p->disc->stringof(p, x, 0) < 0)
318 exerror(
"cannot convert constant %s to STRING",
331 exerror(
"internal error: %ld: unknown type",
type);
387 if (!prog->disc->getf)
388 exerror(
"%s: identifier references not supported", sym->
name);
399static char*
typename[] =
401 "external",
"integer",
"unsigned",
"char",
"float",
"string"
404static int typecast[6][6] =
414#define TYPEINDEX(t) (((t)>=INTEGER&&(t)<=STRING)?((t)-INTEGER+1):0)
415#define TYPENAME(t) typename[TYPEINDEX(t)]
416#define TYPECAST(f,t) typecast[TYPEINDEX(f)][TYPEINDEX(t)]
418#define EXTERNAL(t) ((t)>=F2X)
422 return TYPENAME(
type);
423 return p->disc->typename(
type);
447 if (!(t2t = TYPECAST(x->
type,
type)))
449 if (
EXTERNAL(t2t) && !p->disc->convertf)
454 if (p->disc->convertf(x,
type, 1) < 0) {
457 exerror (
"%s: cannot use value of type %s as argument %d in function %s",
461 exerror(
"%s: cannot convert %s to %s",
466 exerror(
"cannot convert %s to %s",
482 if (xref && xref->
op ==
ID)
484 if (p->disc->convertf(x,
type, arg) < 0)
487 else if (p->disc->convertf(x,
type, arg) < 0)
517 exerror(
"internal error: %d: unknown cast op", t2t);
543 while ((
type =
T(t)))
580 exerror(
"format string argument expected");
596 exerror(
"%s: trailing %% in format", f);
622 exerror(
"unterminated %%... in format");
628 exerror(
"format %s has too many * arguments", f);
634 exerror(
"format %s * argument expected", f);
672 exerror(
"short formats not supported");
703 exerror(
"%s: trailing %% in format", f);
717 exerror(
"%s format argument expected", f);
728 x->arg->op ==
ID ? x->arg :
NULL);
736 x->arg->op ==
ID ? x->arg :
NULL);
745 exerror(
"cannot convert string format argument");
749 exerror(
"string format argument expected");
754 x->arg->op ==
ID ? x->arg :
NULL);
769 exerror(
"too many format arguments");
779int expush(
Expr_t *p,
const char *name,
int line, FILE *fp) {
782 if (!(in = calloc(1,
sizeof(
Exinput_t))))
793 if (!(in->
fp = fopen(name,
"r")))
795 exerror(
"%s: file not found", name);
803 if (!(in->
next = p->input)->next)
819 in->
unit = !name && !line;
835 if (!(in = p->input) || !in->
next || in->
unit)
838 exerror(
"unbalanced quote or nesting construct");
844 if (p->errors && in->
fp && p->linep != p->line)
845 while ((c = getc(in->
fp)) != EOF)
874 if (
expush(p, name, line, fp))
876 p->input->unit = line >= 0;
878 p->input->pushback = p->input->pp =
prefix;
910 while ((in = p->input))
915 if ((p->input = in->
next))
936 if (p->disc->binaryf(l, ex, r, 1) < 0) {
939 (
"cannot apply operator %s to expressions of types %s and %s",
944 (
"cannot apply operator %s to expression of type %s",
954static void checkName(
Exid_t *
id)
958 exerror(
"Variable \"%s\" already declared",
id->name);
961 exerror(
"Name \"%s\" already used as a function",
id->name);
964 exerror(
"Name \"%s\" already used as a keyword",
id->name);
970 "Unexpected token \"%s\" as name in dcl_item",
id->name);
975static int cmpKey(
void *k1,
void *k2) {
989 return n->
op ==
'=' && n->subop ==
'=';
static void agxbfree(agxbuf *xb)
free any malloced resources
static void agxbclear(agxbuf *xb)
resets pointer to data
static WUR char * agxbuse(agxbuf *xb)
static int agxbputc(agxbuf *xb, char c)
add character to buffer
CDT_API int dtclose(Dt_t *)
static int binary(Exnode_t *l, Exnode_t *ex, Exnode_t *r, int arg)
void exerror(const char *format,...)
struct Exstate_s Exstate_t
int exisAssign(Exnode_t *)
Exnode_t * exnoncast(Exnode_t *)
Exnode_t * excast(Expr_t *, Exnode_t *, long, Exnode_t *, int)
static char * exprintf(Vmalloc_t *vm, const char *fmt,...)
void exclose(Expr_t *, int)
Exnode_t * exnewnode(Expr_t *, long, bool, long, Exnode_t *, Exnode_t *)
void exfreenode(Expr_t *, Exnode_t *)
char * extypename(Expr_t *p, long)
int expush(Expr_t *, const char *, int, FILE *)
int excomp(Expr_t *p, const char *name, int line, FILE *fp, char *prefix)
require define api prefix
replacements for ctype.h functions
static bool gv_isalpha(int c)
void * local
user defined local stuff
bool binary
data.operand.{left,right} ok
struct Exnode_s * param[3]
struct Exdata_u::@87 variable
struct Exdata_u::@84 constant
struct Exdata_u::@85 operand
struct Exdata_u::@86 select
void vmfree(Vmalloc_t *vm, void *data)
char * vmstrdup(Vmalloc_t *, const char *)
void vmclear(Vmalloc_t *)
void vmclose(Vmalloc_t *)