cparse.c

来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 1,732 行 · 第 1/5 页

C
1,732
字号
/****************************************************************************
*
*                            Open Watcom Project
*
*    Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
*  ========================================================================
*
*    This file contains Original Code and/or Modifications of Original
*    Code as defined in and that are subject to the Sybase Open Watcom
*    Public License version 1.0 (the 'License'). You may not use this file
*    except in compliance with the License. BY USING THIS FILE YOU AGREE TO
*    ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
*    provided with the Original Code and Modifications, and is also
*    available at www.sybase.com/developer/opensource.
*
*    The Original Code and all software distributed under the License are
*    distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
*    EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
*    ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
*    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
*    NON-INFRINGEMENT. Please see the License for the specific language
*    governing rights and limitations under the License.
*
*  ========================================================================
*
* Description:  WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
*               DESCRIBE IT HERE!
*
****************************************************************************/


/* c:\mks\YACC.EXE -p c ..\c\cparse.y */


#include <stdlib.h>
#include <stdio.h>
#include "wic.h"

#define CSTYPE ParseUnion

#ifndef __SMALL__
#define __SMALL__ 0            // To avoid warnings in MKS yacc
#endif

#pragma disable_message(118)
#define Y_EOF   300
#define Y_EXCLAMATION   301
#define Y_NE    302
#define Y_POUND 303
#define Y_POUND_POUND   304
#define Y_AND   305
#define Y_AND_AND       306
#define Y_AND_EQUAL     307
#define Y_LEFT_PAREN    308
#define Y_RIGHT_PAREN   309
#define Y_TIMES 310
#define Y_TIMES_EQUAL   311
#define Y_PLUS  312
#define Y_PLUS_PLUS     313
#define Y_PLUS_EQUAL    314
#define Y_COMMA 315
#define Y_MINUS 316
#define Y_MINUS_MINUS   317
#define Y_MINUS_EQUAL   318
#define Y_ARROW 319
#define Y_DOT   320
#define Y_DOT_DOT_DOT   321
#define Y_DIVIDE        322
#define Y_DIVIDE_EQUAL  323
#define Y_COLON 324
#define Y_SEG_OP        325
#define Y_SEMICOLON     326
#define Y_LT    327
#define Y_LSHIFT        328
#define Y_LSHIFT_EQUAL  329
#define Y_LE    330
#define Y_EQUAL 331
#define Y_EQ    332
#define Y_GT    333
#define Y_GE    334
#define Y_RSHIFT        335
#define Y_RSHIFT_EQUAL  336
#define Y_QUESTION      337
#define Y_LEFT_BRACKET  338
#define Y_RIGHT_BRACKET 339
#define Y_XOR   340
#define Y_XOR_EQUAL     341
#define Y___BASED       342
#define Y___CDECL       343
#define Y___EXPORT      344
#define Y___FAR 345
#define Y___FAR16       346
#define Y___FORTRAN     347
#define Y___HUGE        348
#define Y___INTERRUPT   349
#define Y___LOADDS      350
#define Y___NEAR        351
#define Y___PASCAL      352
#define Y___PRAGMA      353
#define Y___SAVEREGS    354
#define Y___SEGMENT     355
#define Y___SEGNAME     356
#define Y___SELF        357
#define Y___STDCALL     358
#define Y__PACKED       359
#define Y__SEG16        360
#define Y__SYSCALL      361
#define Y_AUTO  362
#define Y_CHAR  363
#define Y_CONST 364
#define Y_DOUBLE        365
#define Y_ELSE  366
#define Y_ENUM  367
#define Y_EXTERN        368
#define Y_FLOAT 369
#define Y_INT   370
#define Y_LONG  371
#define Y_REGISTER      372
#define Y_SHORT 373
#define Y_SIGNED        374
#define Y_SIZEOF        375
#define Y_STATIC        376
#define Y_STRUCT        377
#define Y_TYPEDEF       378
#define Y_UNION 379
#define Y_UNSIGNED      380
#define Y_VOID  381
#define Y_VOLATILE      382
#define Y_LEFT_BRACE    383
#define Y_OR    384
#define Y_OR_EQUAL      385
#define Y_OR_OR 386
#define Y_RIGHT_BRACE   387
#define Y_TILDE 388
#define Y_ID    389
#define Y_STRING        390
#define Y_INCLUDE_FILE_NAME     391
#define Y_TYPEDEF_NAME  392
#define Y_NUMBER        393
#define Y_PERCENT       394
#define Y_PERCENT_EQUAL 395
#define Y_DEFINED       396
#define Y_PRE_COMMENT   500
#define Y_PRE_NULL      501
#define Y_PRE_NEWLINE   502
#define Y_PRE_DEFINE    503
#define Y_PRE_ELIF      504
#define Y_PRE_ELSE      505
#define Y_PRE_ENDIF     506
#define Y_PRE_ERROR     507
#define Y_PRE_IF        508
#define Y_PRE_IFDEF     509
#define Y_PRE_IFNDEF    510
#define Y_PRE_INCLUDE   511
#define Y_PRE_LINE      512
#define Y_PRE_PRAGMA    513
#define Y_PRE_UNDEF     514
#define Y_PRE_SPECIAL_LEFT_PAREN        515
extern int cchar, cerrflag;
extern CSTYPE cval, clval;
static pToken savedToken;

int cerror(char *str) {
    str = str;
    return 0;
}

void cparseInterface(void) {
    savedToken = NULL;
    cparse();
}

static int clex(void) {
    int retval;
    int dummy;

    if (savedToken != NULL) {
        clval.token = savedToken;
        savedToken = NULL;
    } else {
        clval.token = getExpandToken(EXP_OP_EXPAND, &dummy);
    }
    while (getTokDataType(clval.token->data) == TT_PREPROCESSOR) {
        if (clval.token->data->code == Y_PRE_NEWLINE) {
            //This is an optimization
            zapToken(clval.token);
        } else {
            preparseInterface(clval.token);
        }
        clval.token = getExpandToken(1, &dummy);
    }
    retval = clval.token->data->code;
    return retval;
}

#define cclearin        cchar = -1
                        // We have to copy yacc def'n of cclearin since
                        // yacc puts recoverError() function before it declares
                        // 'cclearin'. If yacc's def'n ever changes,
                        // we will get a redefinition error.
#define CLEARIN cclearin  // Needed for recoverError

static void recoverError(void) {
    pToken tok;
    int code;
    pSLList context = createSLList();
    int recordMaxTok = 15;
    char *s1, *s2;

    for (tok = clval.token, code = tok->data->code;
            code != Y_SEMICOLON && code != Y_EOF && code != Y_RIGHT_BRACE &&
            getTokDataType(tok->data) != TT_PREPROCESSOR;
         clex(), tok = clval.token, code = tok->data->code)
    {
        if (recordMaxTok-- > 0) {
            addSLListElem(context, tok);
        }
    }

    s1 = getTokListString(context);
    s2 = staticGetTokenStr(tok, 0);
    reportError(RERR_CPARSE_WITH_CONTEXT, s1, s2);
    zapSLList(context, zapToken);
    CLEARIN;
    savedToken = tok;
}
static short cdef[] = {
         185,  184,  105,   -1,   -5,   25,   24,   23,   22,   35,
          30,  198,   28,   -9,   21,   37,   36,  -13,   27,  183,
          39,  181,  182,  186,  187,  188,  189,  190,  191,  192,
         193,  194,  195,  196,   34,  -17,   33,   32,   31,  -21,
          29,    4,  -25,  110,   20,   19,   18,   17,   16,   15,
          14,   13,   12,   11,   10,    9,    8,    7,    6,  197,
         -29,   33,   32,   31
};
static short cex[] = {
           0,    3,   -1,  139,    0,    0,   -1,    1,  387,   26,
          -1,    1,  309,   38,   -1,    1,  309,   38,   -1,    1,
         309,    5,   -1,    1,  309,   38,   -1,    1,  309,   38,
          -1,    1
};
static short cact[] = {
          -4, -248, -206, -200, -174, -195, -137,   -3, -196, -198,
        -197, -205, -199, -194, -203, -267, -202, -268, -193, -201,
        -173, -209,  392,  382,  381,  380,  379,  378,  377,  376,
         374,  373,  372,  371,  370,  369,  368,  367,  365,  364,
         363,  362,  300,  256, -133, -139,  389,  383, -132, -265,
        -266,  392,  389,  383, -206, -200, -174, -195, -204, -196,
        -198, -197, -205, -199, -194, -203, -202, -193, -201, -173,
         382,  381,  380,  378,  376,  374,  373,  372,  371,  370,
         369,  368,  365,  364,  363,  362, -206, -200, -174, -195,
        -137, -204, -196, -198, -197, -205, -199, -194, -203, -267,
        -202, -268, -193, -201, -173, -209,  392,  382,  381,  380,
         379,  378,  377,  376,  374,  373,  372,  371,  370,  369,
         368,  367,  365,  364,  363,  362, -131,  -10, -240, -275,
        -272, -273, -277, -274, -271, -276, -279, -278, -139, -270,
         392,  389,  361,  358,  352,  351,  348,  347,  346,  345,
         343,  326,  310,  308, -126,  390, -238, -247, -206, -200,
        -174, -195, -137,   -3, -196, -198, -197, -205, -199, -194,
        -203, -267, -202, -268, -193, -201, -173, -209,  392,  382,
         381,  380,  379,  378,  377,  376,  374,  373,  372,  371,
         370,  369,  368,  367,  365,  364,  363,  362,  300,  256,
        -139,  389, -124,  383, -132,  383,  -17,  -16,  382,  364,
        -131,  -10, -275, -272, -273, -277, -274, -271, -276, -279,
        -278, -139, -270,  392,  389,  361,  358,  352,  351,  348,
         347,  346,  345,  343,  310,  308,  -18, -120,  338,  308,
        -119,  331, -118, -239,  326,  315, -238, -206, -200, -174,
        -195, -137, -204, -196, -198, -197, -205, -199, -194, -203,
        -267, -202, -268, -193, -201, -173, -117, -209,  392,  383,
         382,  381,  380,  379,  378,  377,  376,  374,  373,  372,
         371,  370,  369,  368,  367,  365,  364,  363,  362,  256,
        -116,  331, -177,  -19,  315,  256, -180,  387, -131,  -10,
        -186, -275, -272, -273, -277, -274, -271, -276, -279, -278,
        -139, -270,  392,  389,  361,  358,  352,  351,  348,  347,
         346,  345,  343,  326,  310,  308, -187, -206, -200, -174,
        -195, -137, -204, -196, -198, -197, -205, -199, -194, -203,
        -267, -202, -268, -193, -201, -173, -190, -209,  392,  387,
         382,  381,  380,  379,  378,  377,  376,  374,  373,  372,
         371,  370,  369,  368,  367,  365,  364,  363,  362,  256,
        -147,  364, -148,  382, -163,  309, -140, -206, -200, -174,
        -195, -137, -204, -196, -198, -197, -205, -199, -194, -203,
        -267, -202, -268, -193, -201, -173, -209,  392,  382,  381,
         380,  379,  378,  377,  376,  374,  373,  372,  371,  370,
         369,  368,  367,  365,  364,  363,  362,  321, -220, -223,
        -109, -224, -222, -221, -161, -111, -219, -139, -168, -171,
         393,  390,  389,  388,  375,  339,  316,  312,  310,  308,
         305,  301, -220, -223, -109, -224, -222, -221, -111, -219,
        -139, -168, -171,  393,  390,  389,  388,  375,  316,  312,
         310,  308,  305,  301, -238, -206, -200, -174, -195, -137,
          -3, -196, -198, -197, -205, -199, -194, -203, -267, -202,
        -268, -193, -201, -173, -209,  392,  382,  381,  380,  379,
         378,  377,  376,  374,  373,  372,  371,  370,  369,  368,
         367,  365,  364,  363,  362,  256, -181,  387, -107,  324,
        -106, -185,  326,  315,  -36,  -10, -105, -275, -272, -273,
        -277, -274, -271, -276, -279, -278, -139, -270,  392,  389,
         361,  358,  352,  351,  348,  347,  346,  345,  343,  338,
         310,  308, -104,  315, -160,  309, -162,  339, -168,  390,
        -103, -102,  386,  337, -101,  306, -100,  384,  -99,  340,
         -98,  305,  -97,  -96,  332,  302,  -92,  -93,  -94,  -95,
         334,  333,  330,  327,  -91,  -90,  335,  328,  -88,  -89,
         316,  312,  -85,  -86,  -87,  394,  322,  310, -220, -223,
         -84, -224, -222, -221, -111, -219, -139, -168, -171,  393,
         390,  389,  388,  375,  316,  312,  310,  308,  305,  301,
         -40,  -83,  -82,  -81,  338,  320,  319,  308, -220, -223,
        -109, -224, -222, -221, -206, -200, -174, -195, -137, -204,
        -196, -198, -197, -205, -199, -194, -111, -203, -267, -202,
        -268, -193, -201, -173, -219, -139, -168, -209, -171,  393,
         392,  390,  389,  388,  382,  381,  380,  379,  378,  377,
         376,  375,  374,  373,  372,  371,  370,  369,  368,  367,
         365,  364,  363,  362,  316,  312,  310,  308,  305,  301,
        -238, -241, -206, -200, -174, -195, -137,   -3, -196, -198,
        -197, -205, -199, -194, -203, -267, -202, -268, -193, -201,
        -173,  -42, -209,  392,  387,  382,  381,  380,  379,  378,
         377,  376,  374,  373,  372,  371,  370,  369,  368,  367,
         365,  364,  363,  362,  300,  256, -220, -223, -109, -224,
        -222, -221, -153, -111, -219, -139, -168, -171,  393,  390,
         389,  388,  375,  339,  316,  312,  310,  308,  305,  301,
         -43,  -77,  338,  308,  -36,  -10, -140, -105, -275, -272,
        -273, -277, -274, -271, -276, -279, -278, -206, -200, -174,
        -195, -137, -204, -196, -198, -197, -205, -199, -194, -203,
        -267, -202, -268, -193, -201, -173, -139,  -44,  392,  389,
         382,  381,  380,  379,  378,  377,  376,  374,  373,  372,
         371,  370,  369,  368,  367,  365,  364,  363,  362,  361,
         358,  352,  351,  348,  347,  346,  345,  343,  338,  321,
         310,  308,  -61,  -10, -105, -275, -272, -273, -277, -274,
        -271, -276, -279, -278,  361,  358,  352,  351,  348,  347,
         346,  345,  343,  338,  310,  308,  -70,  309, -234,  -69,
         315,  309, -242,  326, -152,  339, -220, -223, -109, -224,
        -222, -221, -155, -111, -219, -139, -168, -171,  393,  390,
         389,  388,  375,  339,  316,  312,  310,  308,  305,  301,
        -150,  309, -156,  309,  -69,  -66,  324,  315, -225,  309,
         -65,  315, -231,  309,  -69, -232,  339,  315,  -61,  -10,
        -140, -105, -275, -272, -273, -277, -274, -271, -276, -279,
        -278, -206, -200, -174, -195, -137, -204, -196, -198, -197,
        -205, -199, -194, -203, -267, -202, -268, -193, -201, -173,
        -209,  392,  382,  381,  380,  379,  378,  377,  376,  374,
         373,  372,  371,  370,  369,  368,  367,  365,  364,  363,
         362,  361,  358,  352,  351,  348,  347,  346,  345,  343,
         338,  321,  310,  308, -151,  309, -154,  339,   -1
};
static short cpact[] = {
          70,  106,  155,  156,  200,  203,  205,   70,   70,  208,
         238,  241,  291,  294,   70,  371,  373,  397,  201,  509,
         528,  543,  549,  552,  555,  557,  559,  561,  564,  570,
         576,  580,  585,  614,  752,  788,  528,  528,  528,  453,
         834,  853,  397,  884,  555,  557,  559,  561,  564,  570,

⌨️ 快捷键说明

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