Annotation of 42BSD/ingres/source/equel/yylex.c, revision 1.1

1.1     ! root        1: # include      <stdio.h>
        !             2: # include      "constants.h"
        !             3: # include      "globals.h"
        !             4: # include      "y.tab.h"
        !             5: # include      <sccs.h>
        !             6: 
        !             7: SCCSID(@(#)yylex.c     7.1     2/5/81)
        !             8: 
        !             9: 
        !            10: /*
        !            11: **  YYLEX -- Lexical analyzer
        !            12: **     Yylex controls the return to the parser of lexemes,
        !            13: **     and the copying out of C_CODE on the all to yylex 
        !            14: **     after yylex() returned the C_CODE.
        !            15: **
        !            16: **     Returns:
        !            17: **             Lexical tokens.
        !            18: **
        !            19: **     Side Effects:
        !            20: **             Copies C code out on call after seeing it.
        !            21: **             Puts terminals in symbol space.
        !            22: **
        !            23: **     Called By:
        !            24: **             Yacc internals (yyparse()).
        !            25: */
        !            26: 
        !            27: 
        !            28: 
        !            29: yylex()
        !            30: {
        !            31:        register int            rtval;
        !            32:        register char           chr;
        !            33: 
        !            34: 
        !            35: 
        !            36:        /* get next token */
        !            37:        rtval = CONTINUE;
        !            38: 
        !            39:        while (rtval == CONTINUE)
        !            40:        {
        !            41:                if (C_code_flg)
        !            42:                {
        !            43:                        copy_c_code();
        !            44:                        Newline = 1;
        !            45:                }
        !            46:                Pre_proc_flg = 0;
        !            47:        
        !            48:                /* END OF FILE ? */
        !            49:                if ((chr = getch()) == EOF_TOK)
        !            50:                {
        !            51: #                      ifdef xDEBUG
        !            52:                        if (Lex_debug)
        !            53:                                printf("end of file\n");
        !            54: #                      endif
        !            55:                        return (0);
        !            56:                }
        !            57:        
        !            58:                /* Test for a line of C code */
        !            59:                if (Newline && if_c_code(chr))
        !            60:                {
        !            61:                        if (C_code_flg)
        !            62:                                continue;
        !            63:                        rtval = Tokens.sp_c_code;
        !            64:                        C_code_flg = 1;
        !            65:                        break;
        !            66:                }
        !            67:                else
        !            68:                {
        !            69:                        C_code_flg = 0;
        !            70:                        if (Newline)
        !            71:                        {
        !            72:                                Newline = 0;
        !            73:                                continue;
        !            74:                        }
        !            75:                }
        !            76:        
        !            77:                /* CARRIAGE CONTROL ? */
        !            78:                Newline = chr == '\n';
        !            79: 
        !            80:                switch (Cmap [chr])
        !            81:                {
        !            82: 
        !            83:                  case PUNCT :
        !            84:                        continue;
        !            85: 
        !            86:                  case OPATR :
        !            87:                        rtval = operator(chr);
        !            88:                        break;
        !            89: 
        !            90:                  case NUMBR :
        !            91:                        rtval = number(chr);
        !            92:                        break;
        !            93: 
        !            94:                  case ALPHA :
        !            95:                        rtval = name(chr);
        !            96:                        break;
        !            97: 
        !            98:                }
        !            99:        }
        !           100:        if (Lex_debug)
        !           101:                printf("YYLEX : '%s'\n", 
        !           102:                yylval.u_dn ? yylval.u_dn->d_elm : "");
        !           103:        return (rtval);
        !           104: }
        !           105: /*
        !           106: **  COPY_C_CODE -- Copies out a line of C code
        !           107: **     The test for Charcnt != 0 is beacuse if a C pre-processor
        !           108: **     line follows an equel line, and equate_lines() puts out no
        !           109: **     newline, the initial '#' will not be on the beginning of 
        !           110: **     the line. As is, if this should happen, then the line
        !           111: **     with the '#' will be one line in the output ahead of 
        !           112: **     where it should be.
        !           113: */
        !           114: 
        !           115: 
        !           116: copy_c_code()
        !           117: {
        !           118:        char    ch [2];
        !           119: 
        !           120: 
        !           121:        ch [1] = 0;
        !           122:        equate_lines();
        !           123:        if (Pre_proc_flg)
        !           124:        {
        !           125:                if (Charcnt != 0)
        !           126:                        w_raw("\n");
        !           127:                w_raw("#");
        !           128:        }
        !           129:        do
        !           130:        {
        !           131:                if ((*ch = getch()) == EOF_TOK)
        !           132:                        return;
        !           133:                w_raw(ch);
        !           134:        } while (*ch != '\n');
        !           135: }
        !           136: /*
        !           137: **  IF_C_CODE -- Test to see if a line is C code
        !           138: **
        !           139: **     Sees if a line begins with "##" to see if it is equel.
        !           140: **
        !           141: **     Parameters:
        !           142: **             chr -- first char of line
        !           143: **
        !           144: **     Returns:
        !           145: **             0 -- Quel line
        !           146: **             1 -- C line
        !           147: **     
        !           148: **     Called By:
        !           149: **             yylex()
        !           150: */
        !           151: 
        !           152: 
        !           153: if_c_code(chr)
        !           154: char   chr;
        !           155: {
        !           156:        for ( ; ; )
        !           157:        {
        !           158:                if (chr != '#')
        !           159:                {
        !           160:                        backup(chr);
        !           161:                        return (1);
        !           162:                }
        !           163:                Pre_proc_flg = 1;
        !           164:                if ((chr = getch()) == EOF_TOK)
        !           165:                {
        !           166:                        return (0);
        !           167:                }
        !           168:                if (chr != '#')
        !           169:                {
        !           170:                        backup(chr);
        !           171:                        return (1);
        !           172:                }
        !           173:                else
        !           174:                {
        !           175:                        return (0);
        !           176:                }
        !           177:        }
        !           178: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.