⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 preccx.c

📁 編譯器的辭法分析器工具
💻 C
📖 第 1 页 / 共 3 页
字号:
/*       PRE-CC 2.42 compiler-compiler    *       Copyright Peter Breuer 1989-1994 *    <ptb@eng.cam.ac.uk> Tel +44 (0)223 68682 *    <ptb@comlab.ox.ac.uk> <ptb@dit.upm.es> */# define TOKEN char# define VALUE char*# define STACKTOKENS 1# define STACKSIZE 2048# define BEGIN p_begin()# include "cc.h"# include "preccx.h"# undef UNSETNAME# include "preamble.h"char* p_infile,            /* stdin name (eventually "-" if not a file) */    * p_outfile;           /* stdout name (eventually "-" if not a file) */int p_begin(){        static int passes; /* no. of times re-entered MAIN */        int narg;          /* no of command line args */        int nswitch;       /* count of command line switches */        int switches;      /* flag - when doing command line switches */        int dup2();                if(passes++==0){   /* print motto */                printf("\n\/*       PRE-CC %.2f compiler-compiler   \n\ *       Copyright Peter Breuer 1989-1994\n\ *    <ptb@eng.cam.ac.uk> Tel +44 (0)223 68682\n\ *    <ptb@comlab.ox.ac.uk> <ptb@dit.upm.es>\n\ */\n\",__PRECC__);            call_mode=1;/* set no-auto shift in value stack */            dup2(0,5);  /* save stdin and stdout */            dup2(1,6);            nswitch=0;  /* begin command line processing */            switches=1;            for (narg=1;narg<p_argc;narg++){                switch(p_argv[narg][0]){                case '-':                    if(!switches) /* mixed switches and files */                      usage (1);                    nswitch++;                    switch(p_argv[narg][1]){                    case 'r': /* read buffer size in Kb */                        getkintarg(p_argv[narg]+2,&precc_data.readbuffersize,                                   sizeof (TOKEN) + sizeof (VALUE));                        break;                    case 'p': /* internal program length in Kb */                        getkintarg(p_argv[narg]+2,&precc_data.maxprogramsize,                                   sizeof (VALUE));                        break;                    case 'v': /* internal VALUE stack size in Kb */                        getkintarg(p_argv[narg]+2,&precc_data.stacksize,                                   sizeof (STACKVALUE));                        break;                    case 'f': /* internal FRAME stack size in Kb */                        getkintarg(p_argv[narg]+2,&precc_data.contextstacksize,                                   sizeof (FRAME));                    case 'o': /* internal FRAME stack size in Kb */                        if (0==strcmp(p_argv[narg]+1,"old"))                            precc_data.oldattributes=1;                        else                            precc_data.oldattributes=0;                        break;                    default: /* unknown option */                        usage(3);                    }                    break;                default:                    switches=0; /* end of switches */                    break;                }            }                   /* now deal with redirects */            p_infile = p_outfile = "-"; /* in and out file names */            switch(p_argc-1-nswitch){            case 2:                    if (freopen(p_outfile=p_argv[nswitch+2], "w", stdout)==NULL)                       usage (2);            case 1:                    if (freopen(p_infile=p_argv[nswitch+1], "r", stdin)==NULL)                       usage (5);            case 0: break;            default: /* too many files named */                    usage (6);            }        }        return 0;                /* success */}char *envs[PSTACKLENGTH];      /*environment stack*/char *plvs[PSTACKLENGTH];      /*plainenv    stack*/int  ecount=0;                 /*pointer */int  countstack[PSTACKLENGTH]; /*stack of number of sequents we have seen */int  countcount =0;            /*pointer */void pushenv()/* save the current environment and begin another */{    ecount++;}void popenv()/* release the current env and recall the old */{    ecount--;}void pushcount()/* save the current count of sequents and begin another */{    countcount++;    /* the next line disambiguates references in blocks, but that is     * probably not what is wanted.     */    /* count = countcount*PSTACKLENGTH + 1; */    /* this next line does no disambiguation     * and therefore causes warnings from C code,     * but it doesn't matter.     */    count = 1;}void popcount()/* release the current count of sequents and recall the old */{    countcount--;}int getcount()/* return the current count level for sequents */{    return countcount;}                /* -- idens with params ------- */static VOID hid0(){VV(2)=V(1);}static STATUS hid1(){PARSER rdbrktargs;ACTION hid0;return p_attach0n(TOPARSER rdbrktargs,0,hid0,0);}static STATUS hid2(){PARSER hid1;return p_option0n(TOPARSER hid1,0);}static STATUS hid3(){PARSER IDENTIFIER, hid2;static STATUS p_tok;P_PAND((TOPARSER IDENTIFIER)(),(TOPARSER hid2)());return p_tok;}STATUS nameplusargs(){PARSER hid3;return((TOPARSER hid3)());}static VOID hid4(){VV(2)=V(1);}static STATUS hid5(){PARSER rdbrktvars;ACTION hid4;return p_attach0n(TOPARSER rdbrktvars,0,hid4,0);}static STATUS hid6(){PARSER hid5;return p_option0n(TOPARSER hid5,0);}static STATUS hid7(){PARSER IDENTIFIER, hid6;static STATUS p_tok;P_PAND((TOPARSER IDENTIFIER)(),(TOPARSER hid6)());return p_tok;}STATUS nameplusvars(){PARSER hid7;return((TOPARSER hid7)());}static STATUS hid8(){PARSER WHITESPACE, closebracket;static STATUS p_tok;P_PAND((TOPARSER WHITESPACE)(),(TOPARSER closebracket)());return p_tok;}static STATUS hid9(){PARSER someargs, hid8;static STATUS p_tok;P_PAND((TOPARSER someargs)(),(TOPARSER hid8)());return p_tok;}static STATUS hid10(){PARSER WHITESPACE, hid9;static STATUS p_tok;P_PAND((TOPARSER WHITESPACE)(),(TOPARSER hid9)());return p_tok;}static STATUS hid11(){PARSER openbracket, hid10;static STATUS p_tok;P_PAND((TOPARSER openbracket)(),(TOPARSER hid10)());return p_tok;}static VOID hid12(){VV(5)=V(3);}static STATUS hid13(){PARSER hid11;ACTION hid12;return p_attach0n(TOPARSER hid11,0,hid12,0);}static STATUS hid14(){PARSER hid13, p_nothing0;static STATUS p_tok;P_PAND((TOPARSER hid13)(),(TOPARSER p_nothing0)());return p_tok;}STATUS sqbrktargs(){PARSER hid14;return((TOPARSER hid14)());}static STATUS hid15(){PARSER WHITESPACE, closeparen;static STATUS p_tok;P_PAND((TOPARSER WHITESPACE)(),(TOPARSER closeparen)());return p_tok;}static STATUS hid16(){PARSER theargs, hid15;static STATUS p_tok;P_PAND((TOPARSER theargs)(),(TOPARSER hid15)());return p_tok;}static STATUS hid17(){PARSER WHITESPACE, hid16;static STATUS p_tok;P_PAND((TOPARSER WHITESPACE)(),(TOPARSER hid16)());return p_tok;}static STATUS hid18(){PARSER openparen, hid17;static STATUS p_tok;P_PAND((TOPARSER openparen)(),(TOPARSER hid17)());return p_tok;}static VOID hid19(){VV(5)=V(3);}static STATUS hid20(){PARSER hid18;ACTION hid19;return p_attach0n(TOPARSER hid18,0,hid19,0);}static STATUS hid21(){PARSER hid20, p_nothing0;static STATUS p_tok;P_PAND((TOPARSER hid20)(),(TOPARSER p_nothing0)());return p_tok;}STATUS rdbrktargs(){PARSER hid21;return((TOPARSER hid21)());}static STATUS hid22(){PARSER WHITESPACE, closeparen;static STATUS p_tok;P_PAND((TOPARSER WHITESPACE)(),(TOPARSER closeparen)());return p_tok;}static STATUS hid23(){PARSER thevars, hid22;static STATUS p_tok;P_PAND((TOPARSER thevars)(),(TOPARSER hid22)());return p_tok;}static STATUS hid24(){PARSER WHITESPACE, hid23;static STATUS p_tok;P_PAND((TOPARSER WHITESPACE)(),(TOPARSER hid23)());return p_tok;}static STATUS hid25(){PARSER openparen, hid24;static STATUS p_tok;P_PAND((TOPARSER openparen)(),(TOPARSER hid24)());return p_tok;}static VOID hid26(){VV(5)=V(3);}static STATUS hid27(){PARSER hid25;ACTION hid26;return p_attach0n(TOPARSER hid25,0,hid26,0);}static STATUS hid28(){PARSER hid27, p_nothing0;static STATUS p_tok;P_PAND((TOPARSER hid27)(),(TOPARSER p_nothing0)());return p_tok;}STATUS rdbrktvars(){PARSER hid28;return((TOPARSER hid28)());}/* these are token-driven writes */static VOID hid29(){ VV(1) = putchar(T(1)); }static STATUS hid30(){PARSER OPENPAREN;ACTION hid29;return p_attach0n(TOPARSER OPENPAREN,0,hid29,0);}STATUS openparen(){PARSER hid30;return((TOPARSER hid30)());}static VOID hid31(){ VV(1) = putchar(T(1)); }static STATUS hid32(){PARSER CLOSEPAREN;ACTION hid31;return p_attach0n(TOPARSER CLOSEPAREN,0,hid31,0);}STATUS closeparen(){PARSER hid32;return((TOPARSER hid32)());}static VOID hid33(){ VV(1) = putchar(T(1)); }static STATUS hid34(){PARSER OPENBRACKET;ACTION hid33;return p_attach0n(TOPARSER OPENBRACKET,0,hid33,0);}STATUS openbracket(){PARSER hid34;return((TOPARSER hid34)());}static VOID hid35(){ VV(1) = putchar(T(1)); }static STATUS hid36(){PARSER CLOSEBRACKET;ACTION hid35;return p_attach0n(TOPARSER CLOSEBRACKET,0,hid35,0);}STATUS closebracket(){PARSER hid36;return((TOPARSER hid36)());}static VOID hid37(){ VV(0)=""; }static STATUS hid38(){PARSER p_nothing0;ACTION hid37;return p_attach0n(TOPARSER p_nothing0,0,hid37,0);}static STATUS hid39 (){PARSER someargs, hid38;static STATUS p_tok;p_tok = (TOPARSER someargs) ();return (GOODSTATUS(p_tok))?p_tok:(TOPARSER hid38) ();}STATUS theargs(){PARSER hid39;return((TOPARSER hid39)());}static VOID hid40(){ VV(0)=""; }static STATUS hid41(){PARSER p_nothing0;ACTION hid40;return p_attach0n(TOPARSER p_nothing0,0,hid40,0);}static STATUS hid42 (){PARSER somevars, hid41;static STATUS p_tok;p_tok = (TOPARSER somevars) ();return (GOODSTATUS(p_tok))?p_tok:(TOPARSER hid41) ();}STATUS thevars(){PARSER hid42;return((TOPARSER hid42)());}static VOID hid43(){ VV(1)=putchar(','); }static STATUS hid44(){PARSER COMMA;ACTION hid43;return p_attach0n(TOPARSER COMMA,0,hid43,0);}STATUS comma(){PARSER hid44;return((TOPARSER hid44)());}static STATUS hid45(){PARSER WHITESPACE, expr;static STATUS p_tok;P_PAND((TOPARSER WHITESPACE)(),(TOPARSER expr)());return p_tok;}static STATUS hid46(){PARSER comma, hid45;static STATUS p_tok;P_PAND((TOPARSER comma)(),(TOPARSER hid45)());return p_tok;}static STATUS hid47(){PARSER WHITESPACE, hid46;static STATUS p_tok;P_PAND((TOPARSER WHITESPACE)(),(TOPARSER hid46)());return p_tok;}static VOID hid48(){VV(5)=V(1);}static STATUS hid49(){PARSER hid47;ACTION hid48;return p_attach0n(TOPARSER hid47,0,hid48,0);}static STATUS hid50(){PARSER hid49;return p_many0n(TOPARSER hid49,0);}static STATUS hid51(){PARSER expr, hid50;static STATUS p_tok;P_PAND((TOPARSER expr)(),(TOPARSER hid50)());return p_tok;}STATUS someargs(){PARSER hid51;return((TOPARSER hid51)());}static STATUS hid52(){PARSER WHITESPACE, var;static STATUS p_tok;P_PAND((TOPARSER WHITESPACE)(),(TOPARSER var)());return p_tok;}static STATUS hid53(){PARSER comma, hid52;static STATUS p_tok;P_PAND((TOPARSER comma)(),(TOPARSER hid52)());return p_tok;}static STATUS hid54(){PARSER WHITESPACE, hid53;static STATUS p_tok;P_PAND((TOPARSER WHITESPACE)(),(TOPARSER hid53)());return p_tok;}static VOID hid55(){VV(5)=V(1);}static STATUS hid56(){PARSER hid54;ACTION hid55;return p_attach0n(TOPARSER hid54,0,hid55,0);}static STATUS hid57(){PARSER hid56;return p_many0n(TOPARSER hid56,0);}static STATUS hid58(){PARSER var, hid57;static STATUS p_tok;P_PAND((TOPARSER var)(),(TOPARSER hid57)());return p_tok;}STATUS somevars(){PARSER hid58;return((TOPARSER hid58)());}static VOID hid59(){if(*putargs(""))putargs(",");putargs("PARAM ");putargs(V(1));                 if(*putmeta(""))putmeta(",");putmeta(V(1));}static STATUS hid60(){PARSER IDENTIFIER;ACTION hid59;return p_attach0n(TOPARSER IDENTIFIER,0,hid59,0);}STATUS var(){PARSER hid60;return((TOPARSER hid60)());}                /* -- parser identifiers --- *//* collect IDENTIFIERs from buffers */void SETENV()/* seal the current environment to be whats in the buffers now */{  environment=putargs("");  plainenv=putmeta("");  getargs(&environment);  getmeta(&plainenv);}char *LASTVAR()/* last variable in the current environment */{char *s;if (ecount<0)  return NULL;s = strchr(plainenv,',');if (!s)  return plainenv;return s+1;}/* first item written in a declaration block */static VOID hid61(){getname(&V(1));SETENV();}static STATUS hid62(){PARSER nameplusvars;ACTION hid61;return p_attach0n(TOPARSER nameplusvars,0,hid61,0);}STATUS declname(){PARSER hid62;return((TOPARSER hid62)());}/* to make #line references to definitions immediately before the   FIRST STATUS foo line in the emitted code, insert P_LINE; before the   getname above *//* collect a domain IDENTIFIER in the same way */static VOID hid63(){getname(&V(1));}static STATUS hid64(){PARSER nameplusargs;ACTION hid63;return p_attach0n(TOPARSER nameplusargs,0,hid63,0);}STATUS exprname(){PARSER hid64;return((TOPARSER hid64)());}                /* -- start of precc defn ----   */static STATUS hid65(){PARSER declerr;return p_uerror0n(TOPARSER declerr,0);}static STATUS hid66(){PARSER expression, WHITESPACE;static STATUS p_tok;P_PAND((TOPARSER expression)(),(TOPARSER WHITESPACE)());return p_tok;}static STATUS hid67(){PARSER WHITESPACE, hid66;static STATUS p_tok;P_PAND((TOPARSER WHITESPACE)(),(TOPARSER hid66)());return p_tok;}static STATUS hid68(){PARSER EQUALS, hid67;static STATUS p_tok;P_PAND((TOPARSER EQUALS)(),(TOPARSER hid67)());return p_tok;}static STATUS hid69(){PARSER WHITESPACE, hid68;static STATUS p_tok;P_PAND((TOPARSER WHITESPACE)(),(TOPARSER hid68)());return p_tok;}static STATUS hid70(){PARSER declname, hid69;static STATUS p_tok;P_PAND((TOPARSER declname)(),(TOPARSER hid69)());return p_tok;}static STATUS hid71(){PARSER WHITESPACE, hid70;static STATUS p_tok;P_PAND((TOPARSER WHITESPACE)(),(TOPARSER hid70)());return p_tok;}static STATUS hid72(){PARSER hid65, hid71;static STATUS p_tok;P_PAND((TOPARSER hid65)(),(TOPARSER hid71)());return p_tok;}static STATUS hid73(){PARSER AT, hid72;static STATUS p_tok;P_PAND((TOPARSER AT)(),(TOPARSER hid72)());return p_tok;}static STATUS hid74(){PARSER p_first0, hid73;static STATUS p_tok;P_PAND((TOPARSER p_first0)(),(TOPARSER hid73)());return p_tok;}static VOID hid75(){VV(10) = P_REN(V(5),V(9));countcount=0;RESET;}static STATUS hid76(){PARSER hid74;ACTION hid75;return p_attach0n(TOPARSER hid74,0,hid75,0);}STATUS declaration(){PARSER hid76;return((TOPARSER hid76)());}void ADDVAR(char *x)/* make a new environment with one more var. save the old. */{  char *n;                 /* finish off current env */  getargs(&n);  getmeta(&n);                 /* copy old to new - start by buffering it */  putargs(environment);  putmeta(plainenv);                 /* increment env count */  pushenv();                 /* point env at buffer */  environment=putargs("");  plainenv=putmeta("");                 /* add new var */  if (is_in(x,plainenv))      return;    /* unless already there */  if(*environment){    putargs(",");    putmeta(",");  }  putargs("PARAM ");  putargs(x);  putmeta(x);                 /* note that the buffer is still unterminated */}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -