22#if !defined(_EXGRAM_H) && ( defined(MINTOKEN) || defined(YYTOKENTYPE) )
33#define ex_lex() extoken_fn(expr.program)
78 if (x->
data.call.args)
131 if (x->
data.string.repl)
136 if (x->
data.split.seps)
139 if (x->
data.split.array->local) {
149 if (x->
data.print.descriptor)
151 pn = x->
data.print.args;
164 if (x->
data.procedure.args)
166 if (x->
data.procedure.body)
209 exerror(
"in %s, array %s must have integer index type, not %s",
212 exerror(
"in %s, array %s entries must have string type, not %s",
215 exerror(
"first argument to %s must have string type, not %s",
218 exerror(
"third argument to %s must have string type, not %s",
221 ss->
data.split.array = dyn;
222 ss->
data.split.string =
s;
223 ss->
data.split.seps = seps;
237 base = extract(p, &args,
STRING);
239 exerror(
"invalid first argument to sub operator");
240 pat = extract(p, &args,
STRING);
242 exerror(
"invalid second argument to sub operator");
244 repl = extract(p, &args,
STRING);
246 exerror(
"invalid third argument to sub operator");
250 exerror(
"too many arguments to sub operator");
252 ss->
data.string.base = base;
253 ss->
data.string.pat = pat;
254 ss->
data.string.repl = repl;
267 base = extract(p, &args,
STRING);
269 exerror(
"invalid first argument to substr operator");
270 pat = extract(p, &args,
INTEGER);
272 exerror(
"invalid second argument to substr operator");
274 repl = extract(p, &args,
INTEGER);
276 exerror(
"invalid third argument to substr operator");
280 exerror(
"too many arguments to substr operator");
282 ss->
data.string.base = base;
283 ss->
data.string.pat = pat;
284 ss->
data.string.repl = repl;
292static char*
typename[] =
294 "external",
"integer",
"unsigned",
"char",
"float",
"string"
297static int typecast[6][6] =
307#define TYPEINDEX(t) (((t)>=INTEGER&&(t)<=STRING)?((t)-INTEGER+1):0)
308#define TYPENAME(t) typename[TYPEINDEX(t)]
309#define TYPECAST(f,t) typecast[TYPEINDEX(f)][TYPEINDEX(t)]
311#define EXTERNAL(t) ((t)>=F2X)
315 return TYPENAME(
type);
316 return p->disc->typename(
type);
335 if (p->disc->stringof(p, x, 1) < 0) {
336 exerror(
"cannot convert %s to STRING",
340 }
else if (TYPEINDEX(
type) != 0) {
345 if (p->disc->stringof(p, x, 0) < 0)
346 exerror(
"cannot convert constant %s to STRING",
359 exerror(
"internal error: %ld: unknown type",
type);
415 if (!prog->disc->getf)
416 exerror(
"%s: identifier references not supported", sym->
name);
444 if (!(t2t = TYPECAST(x->
type,
type)))
446 if (
EXTERNAL(t2t) && !p->disc->convertf)
451 if (p->disc->convertf(x,
type, 1) < 0) {
454 exerror (
"%s: cannot use value of type %s as argument %d in function %s",
458 exerror(
"%s: cannot convert %s to %s",
463 exerror(
"cannot convert %s to %s",
479 if (xref && xref->
op ==
ID)
481 if (p->disc->convertf(x,
type, arg) < 0)
484 else if (p->disc->convertf(x,
type, arg) < 0)
514 exerror(
"internal error: %d: unknown cast op", t2t);
540 while ((
type =
T(t)))
577 exerror(
"format string argument expected");
592 exerror(
"%s: trailing %% in format", f);
618 exerror(
"unterminated %%... in format");
624 exerror(
"format %s has too many * arguments", f);
630 exerror(
"format %s * argument expected", f);
668 exerror(
"short formats not supported");
699 exerror(
"%s: trailing %% in format", f);
713 exerror(
"%s format argument expected", f);
724 x->arg->op ==
ID ? x->arg :
NULL);
732 x->arg->op ==
ID ? x->arg :
NULL);
741 exerror(
"cannot convert string format argument");
745 exerror(
"string format argument expected");
750 x->arg->op ==
ID ? x->arg :
NULL);
762 exerror(
"too many format arguments");
772int expush(
Expr_t *p,
const char *name,
int line, FILE *fp) {
786 if (!(
in->fp = fopen(name,
"r")))
788 exerror(
"%s: file not found", name);
796 if (!(
in->next = p->input)->next)
812 in->unit = !name && !line;
828 if (!(
in = p->input) || !
in->next ||
in->unit)
831 exerror(
"unbalanced quote or nesting construct");
837 if (p->errors &&
in->fp && p->linep != p->line)
838 while ((c = getc(
in->fp)) != EOF)
846 if (
in->fp &&
in->close)
867 if (
expush(p, name, line, fp))
869 p->input->unit = line >= 0;
871 p->input->pushback = p->input->pp =
prefix;
897 while ((
in = p->input))
900 if (
in->fp &&
in->close)
902 if ((p->input =
in->next))
917 if (p->disc->binaryf(l, ex, r, 1) < 0) {
920 (
"cannot apply operator %s to expressions of types %s and %s",
925 (
"cannot apply operator %s to expression of type %s",
935static void checkName(
const Exid_t *
id) {
938 exerror(
"Variable \"%s\" already declared",
id->name);
941 exerror(
"Name \"%s\" already used as a function",
id->name);
944 exerror(
"Name \"%s\" already used as a keyword",
id->name);
950 "Unexpected token \"%s\" as name in dcl_item",
id->name);
955static int cmpKey(
void *k1,
void *k2) {
969 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
void gv_arena_reset(arena_t *arena)
char * gv_arena_strdup(arena_t *arena, const char *s)
void gv_arena_free(arena_t *arena, void *ptr, size_t size)
Region-based memory allocator.
#define ARENA_NEW(arena, type)
CDT_API int dtclose(Dt_t *)
static int binary(Exnode_t *l, Exnode_t *ex, Exnode_t *r, int arg)
static int in(Extype_t lhs, Exid_t *rhs, Exdisc_t *disc)
void exerror(const char *format,...)
int exisAssign(Exnode_t *)
Exnode_t * exnoncast(Exnode_t *)
Exnode_t * excast(Expr_t *, Exnode_t *, long, Exnode_t *, int)
static char * exprintf(arena_t *vm, const char *fmt,...)
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::@94 select
struct Exdata_u::@93 operand
struct Exdata_u::@95 variable
struct Exdata_u::@92 constant