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