?? cc.h
字號:
#ifndef CC_H#define CC_H#ifdef __MSDOS__#define p_memleft() coreleft()#else#define p_memleft() 32000#endif/* standard clib */#include <stdio.h>#define p_gets(x) gets(x)#define p_calloc(x,y) calloc((size_t)(x),(size_t)(y))#define p_free(x) free((VOID *)(x))#include <stdarg.h>#include <string.h>#include <setjmp.h>/* default defs */#ifndef VALUE#define VALUE char* /* make sure you define VALUE !! */#endif#ifndef TOKEN#define TOKEN char /* and TOKEN, if not int and char */#endif#ifndef PARAM#define PARAM long /* VALUE=synthetic, PARAM=inherited */#endif#ifndef MAXPROGRAMSIZE#define MAXPROGRAMSIZE 4096 /* 20K (chars) is often too big in DOS */#endif /* but this is ~3x line length, at least */#ifndef READBUFFERSIZE#define READBUFFERSIZE 2048 /* ditto */#endif /* because this IS the line length */#ifndef STACKSIZE# define STACKSIZE 1 /* NOT NEEDED ANY MORE UNLESS OLD STYLE VV(n) */# endif /* ATTRIBUTE REFS ARE BEING SUPPORTED */ /* If set, it is very difficult to overun 2K ! */ /* msdos defns */#ifndef CONTEXTSTACKSIZE#define CONTEXTSTACKSIZE 1024#endif#ifndef C_STACKSIZE#define C_STACKSIZE 0x7FFF#endif /* compatibility */# ifndef STACKTOKENS# define STACKTOKENS 0 /* Don't put tokens on the attribute stack */# endif /* unless you are sure there is one! */# ifndef OLDATTRIBUTES# define OLDATTRIBUTES 0 /* Don't generate code which supports $1, $2, ... */# endif /* (The $named attr. refs. are supported anyway) */#define MAXARGS 16 /* number of params catered for *//* DON'T change it! */extern int yytchar; /* the last thing yylex saw */extern int yylineno; /* line count *//* I'll put in the decls for the yystuff here, in case they're needed */extern int yylen;extern int yylex();extern char *yylloc;extern VALUE yylval;extern TOKEN *yybuffer; /* yyoutput can be written here */#ifndef BAD_ERROR /* failed parse marked at deepest pt */#define BAD_ERROR(x) fprintf(stderr,"(line %d) failed parse:\ probable error near ..<>%s\nSkipping ...\n",yylineno,(char*)maxp);\ while((yytchar!=EOF)&&get1token());get1token();\ yylloc=NULL;#endif#ifndef ZER_ERROR /* incomplete parse shows least remainder */#define ZER_ERROR(x) fprintf(stderr,"(line %d) incomplete parse:\ possible error near ..<>%s\nSkipping ...\n",yylineno,(char*)maxp);\ while((yytchar!=EOF)&&get1token());get1token();\ yylloc=NULL;#endif/* if p_entry is set, use that as handler, else print message. */#ifndef BTK_ERROR /* backtracking across a parse boundary */#define BTK_ERROR(x) if (!p_entry){\ fprintf(stderr,"(line %d) error:\ parse backtracked across cut from point near <>%s\n\",yylineno,(char*)maxp);}\yylloc=NULL;\longjmp(jmpb,1); /* should be to the ! we're backtracking across */#endif#ifndef ON_ERROR /* default error mechanism */#define ON_ERROR(x) switch(x){\case 1:BAD_ERROR(1);break;\case 0:ZER_ERROR(0);break;\case -1:BTK_ERROR(-1);break;\}#endif/* local defs */#define OPCODE char#define VOID void/* typedefs */typedef PARAM status; /* STATUS is returned by a PARSER */#define STATUS statustypedef STATUS PARSER(); /* PARSER returns a STATUS */#define TOPARSER /* *(PARSER*) */#define TOVALUE (VALUE)typedef VOID ACTION(); /* VALUE stack manipulation */typedef int boolean; /* BOOLEAN is returned by a PREDICATE */#define BOOLEAN booleantypedef BOOLEAN PREDICATE(); /* PREDICATE returns a BOOLEAN */typedef struct { /* an INSTRUCTION consists of ... */ OPCODE opcode; /* an OPCODE as opcode and ... */ union { /* an ACTION or ... */ ACTION *act; /* a literal as operand. */ TOKEN tok; /* The opcode selects the */ VALUE val; PARAM par; } operand; /* interpretation of the operand. */} INSTRUCTION;typedef union { /* The VALUE stack actually contains */ VALUE val; /* STACKVALUES, which may be either */ TOKEN tok; /* VALUEs or TOKENs. TOKENs are */ PARAM par; /* ... */} STACKVALUE; /* pushed when literals are hit. */typedef struct { /* all the info required for a REWIND */ TOKEN *pstr; STACKVALUE *value; int pc; int lineno; /* INSTRUCTION instr;*/ /* to track optimization */} FRAME;typedef struct {int readbuffersize, maxprogramsize, stacksize, contextstacksize, stacktokens, /* (boolean) support tokens as attrs for old code*/ oldattributes; /* (boolean) generate yacc style attr. refs */} PRECC_DATA;/* instruction destructors and constructors */#define Action(x) (x).operand.act#define Token(x) (x).operand.tok#define Param(x) (x).operand.par#define Opcode(x) (x).opcode#define Value(x) (x).operand.val/* status macros */#define BADSTATUS(x) (!(x)) /* BADSTATUS(x) is a PREDICATE */#define GOODSTATUS(x) (x) /* as is GOODSTATUS(x) */# define INSTATUS(x) ( (PARAM) ( (long)(x) - ( (0>(int)(x)) ? 0 : 1 ) ) ) /* success deconstructor */# define OK(x) ( (STATUS) ( ( (0>(int)(x)) ? 0 : 1 ) + (long)(x) ) ) /* success constructor */#define KO(x) 0#define SUCCESS OK(1)#define FAILURE KO(0)/* input stream manipulations *//* MARK has to be first line in a routine. * The MARK saves the current parse frame. */#define MARK {\fsave(p_frame);\fpush(p_frame);\}/* REWIND resets the parse point to the MARK at the head of the fn. * provided that the read buffer hasn't been overwritten, in which case * just go back as far as possible */#define REWIND {\fpop(p_frame);\frestore(p_frame);\}/* RELEASE will destroy the temporary references */# define RELEASE fpop(p_frame)/* * maxp+1 is the first address I have not yet written into. The TOKEN space * should be occupied by a 0. maxp is the last position I have written into. * * pstr is the current TOKEN position. Notice that I am going to have to read * one TOKEN into *pstr to start up? * * We start with pstr=maxp=&buffer, and *buffer=first token. */#ifdef OLDSTYLEMOVEON#define MOVEON if(++pstr>maxp){ /* this next space not written into */\ *pstr=(TOKEN)yylex();\ lvbuff[(int)(pstr-buffer)]=yylval;\ maxp=pstr;\ }#else#define MOVEON get1token()#endif/* the secret parse string and stacks */extern TOKEN *pstr; /* parsed stream */extern TOKEN *maxp; /* maximal parse point in stream */extern TOKEN *buffer; /* where the pstr points to */extern VALUE *lvbuff; /* the corresponding yylvals*/extern VALUE *plval; /* and pointer */extern INSTRUCTION *program;extern int pc; /* program counter - counts up from 0 */extern int passcount; /* count cuts */extern STACKVALUE *stack; /* the evaluation stack - either * VALUEs or TOKENs */extern STACKVALUE *value; /* top of evaluation stack */extern FRAME *fstack; /* top of frame stack ... */extern FRAME *fptr; /* and pointer */extern FRAME p_frame; /* a frame cache */extern INSTRUCTION instr; /* single instruction cache */extern int call_mode; /* 0 for auto-calling convention, 1=manual */extern int optimize; /* 1 for flying optimization */extern jmp_buf jmpb;extern jmp_buf p_jmpb; /* or environments */extern int p_argc; /* command line argument count */extern char **p_argv; /* command line argument array */extern PRECC_DATA precc_data;extern int msdos;extern PARSER *p_entry; /* the current entry point */extern int p_enargs;extern PARAM p_eargv[];extern char *p_infile, /* stdin name (eventually "-" if not a file) */ *p_outfile; /* stdout name (eventually "-" if not a file) *//* opcodes */#define INCR 5 /* increment value stack */#define PARM 4 /* parameter to a function call */#define FUNC 3 /* That's got an ACTION operand */#define EXIT 2#define CNST 1 /* That's got a VALUE operand. */#define NOP 0 /* Saves time. *//* program stack manipulation */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -