home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / NGAWK1.ZIP / AWK.C next >
C/C++ Source or Header  |  1988-07-17  |  57KB  |  1,841 lines

  1.  
  2. /*  A Bison parser, made from awk.y  */
  3.  
  4. #define    NAME    258
  5. #define    REGEXP    259
  6. #define    YSTRING    260
  7. #define    ERROR    261
  8. #define    INCDEC    262
  9. #define    NUMBER    263
  10. #define    ASSIGNOP    264
  11. #define    RELOP    265
  12. #define    MATCHOP    266
  13. #define    NEWLINE    267
  14. #define    REDIRECT_OP    268
  15. #define    CONCAT_OP    269
  16. #define    LEX_BEGIN    270
  17. #define    LEX_END    271
  18. #define    LEX_IF    272
  19. #define    LEX_ELSE    273
  20. #define    LEX_WHILE    274
  21. #define    LEX_FOR    275
  22. #define    LEX_BREAK    276
  23. #define    LEX_CONTINUE    277
  24. #define    LEX_GETLINE    278
  25. #define    LEX_PRINT    279
  26. #define    LEX_PRINTF    280
  27. #define    LEX_NEXT    281
  28. #define    LEX_EXIT    282
  29. #define    LEX_IN    283
  30. #define    LEX_AND    284
  31. #define    LEX_OR    285
  32. #define    INCREMENT    286
  33. #define    DECREMENT    287
  34. #define    LEX_BUILTIN    288
  35. #define    LEX_SUB    289
  36. #define    UNARY    290
  37.  
  38. #line 28 "awk.y"
  39.  
  40. #define YYDEBUG 12
  41.  
  42. #include <stdio.h>
  43. #include <string.h>
  44. #include "awk.h"
  45.  
  46.   static int yylex ();
  47.  
  48.  
  49.   /*
  50.    * The following variable is used for a very sickening thing.
  51.    * The awk language uses white space as the string concatenation
  52.    * operator, but having a white space token that would have to appear
  53.    * everywhere in all the grammar rules would be unbearable.
  54.    * It turns out we can return CONCAT_OP exactly when there really
  55.    * is one, just from knowing what kinds of other tokens it can appear
  56.    * between (namely, constants, variables, or close parentheses).
  57.    * This is because concatenation has the lowest priority of all
  58.    * operators.  want_concat_token is used to remember that something
  59.    * that could be the left side of a concat has just been returned.
  60.    *
  61.    * If anyone knows a cleaner way to do this (don't look at the Un*x
  62.    * code to find one, though), please suggest it.
  63.    */
  64.   static int want_concat_token;
  65.  
  66.   /* Two more horrible kludges.  The same comment applies to these two too */
  67.   static int want_regexp;    /* lexical scanning kludge */
  68.   static int want_redirect; /* similarly */
  69.   int lineno = 1;    /* JF for error msgs */
  70.  
  71.   /* Speaking of kludges.  We don't want to treat arguments as filenames
  72.   ** if there are no pattern action pairs to perform; sooo I am creating
  73.   ** a counter for patterns and actions. -ADE */
  74.   int patterns = 0;
  75.   int actions = 0;
  76. /* During parsing of a gawk program, the pointer to the next character
  77.    is in this variable.  */
  78.   char *lexptr;        /* JF moved it up here */
  79.   char *lexptr_begin;    /* JF for error msgs */
  80.  
  81. #line 71 "awk.y"
  82. typedef union {
  83.   long lval;
  84.   AWKNUM fval;
  85.   NODE *nodeval;
  86.   NODETYPE nodetypeval;
  87.   char *sval;
  88.   NODE *(*ptrval)();
  89. } YYSTYPE;
  90.  
  91. #ifndef YYLTYPE
  92. typedef
  93.   struct yyltype
  94.     {
  95.       int timestamp;
  96.       int first_line;
  97.       int first_column;
  98.       int last_line;
  99.       int last_column;
  100.       char *text;
  101.    }
  102.   yyltype;
  103.  
  104. #define YYLTYPE yyltype
  105. #endif
  106.  
  107. #define    YYACCEPT    return(0)
  108. #define    YYABORT    return(1)
  109. #define    YYERROR    return(1)
  110. #include <stdio.h>
  111.  
  112.  
  113.  
  114. #define    YYFINAL        204
  115. #define    YYFLAG        -32768
  116. #define    YYNTBASE    54
  117.  
  118. #define YYTRANSLATE(x) (yytranslate[x])
  119.  
  120. static char yytranslate[] = {     0,
  121.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  122.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  123.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  124.      2,     2,    43,     2,     2,    51,    40,     2,     2,    44,
  125.     45,    38,    36,    35,    37,     2,    39,     2,     2,     2,
  126.      2,     2,     2,     2,     2,     2,     2,    53,    48,     2,
  127.      2,     2,    52,     2,     2,     2,     2,     2,     2,     2,
  128.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  129.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  130.     49,     2,    50,    41,     2,     2,     2,     2,     2,     2,
  131.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  132.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  133.      2,     2,    46,     2,    47,     2,     2,     2,     2,     2,
  134.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  135.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  136.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  137.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  138.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  139.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  140.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  141.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  142.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  143.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  144.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  145.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  146.      2,     2,     2,     2,     2,     1,     2,     3,     4,     5,
  147.      6,     7,     8,     9,    10,    11,    12,    13,    14,    15,
  148.     16,    17,    18,    19,    20,    21,    22,    23,    24,    25,
  149.     26,    27,    28,    29,    30,    31,    32,    33,    34,    42
  150. };
  151.  
  152. static short yyrline[] = {     0,
  153.    118,   124,   126,   132,   142,   144,   150,   152,   157,   159,
  154.    162,   164,   166,   168,   173,   175,   177,   183,   185,   191,
  155.    193,   195,   197,   199,   204,   209,   211,   217,   219,   225,
  156.    228,   236,   238,   240,   242,   244,   246,   249,   251,   254,
  157.    257,   259,   261,   263,   269,   271,   277,   279,   285,   288,
  158.    297,   298,   303,   305,   310,   312,   320,   322,   329,   331,
  159.    336,   338,   343,   345,   347,   349,   351,   353,   356,   358,
  160.    363,   367,   370,   372,   374,   379,   381,   387,   389,   391,
  161.    393,   395,   400,   402,   404,   406,   408,   413,   415,   417,
  162.    422,   424,   426,   431,   433,   438,   440,   445,   447,   452,
  163.    454,   459,   464,   466,   467,   468,   469
  164. };
  165.  
  166. static char * yytname[] = {     0,
  167. "error","$illegal.","NAME","REGEXP","YSTRING","ERROR","INCDEC","NUMBER","ASSIGNOP","RELOP",
  168. "MATCHOP","NEWLINE","REDIRECT_OP","CONCAT_OP","LEX_BEGIN","LEX_END","LEX_IF","LEX_ELSE","LEX_WHILE","LEX_FOR",
  169. "LEX_BREAK","LEX_CONTINUE","LEX_GETLINE","LEX_PRINT","LEX_PRINTF","LEX_NEXT","LEX_EXIT","LEX_IN","LEX_AND","LEX_OR",
  170. "INCREMENT","DECREMENT","LEX_BUILTIN","LEX_SUB","','","'+'","'-'","'*'","'/'","'%'",
  171. "'^'","UNARY","'!'","'('","')'","'{'","'}'","';'","'['","']'",
  172. "'$'","'?'","':'","start"
  173. };
  174.  
  175. static short yyr1[] = {     0,
  176.     54,    55,    55,    56,    57,    57,    57,    57,    58,    58,
  177.     58,    58,    58,    58,    58,    58,    58,    59,    59,    60,
  178.     60,    60,    60,    60,    61,    62,    62,    63,    63,    64,
  179.     64,    66,    65,    67,    65,    68,    65,    69,    65,    65,
  180.     65,    65,    65,    65,    71,    70,    72,    70,    73,    70,
  181.     74,    74,    75,    75,    77,    76,    78,    78,    79,    79,
  182.     80,    80,    81,    81,    81,    81,    81,    81,    82,    81,
  183.     81,    83,    83,    83,    83,    84,    84,    85,    85,    85,
  184.     85,    85,    86,    86,    86,    86,    86,    87,    87,    87,
  185.     88,    88,    88,    89,    89,    90,    90,    91,    91,    92,
  186.     92,    93,    94,    94,    94,    94,    94
  187. };
  188.  
  189. static short yyr2[] = {     0,
  190.      2,     1,     2,     4,     0,     1,     1,     1,     1,     1,
  191.      2,     3,     3,     3,     3,     3,     3,     0,     1,     2,
  192.      1,     1,     1,     1,     4,     1,     2,     2,     2,     6,
  193.      9,     0,     7,     0,    11,     0,    10,     0,    10,     2,
  194.      2,     2,     2,     5,     0,     5,     0,     5,     0,     7,
  195.      0,     2,     2,     2,     0,     4,     0,     2,     0,     1,
  196.      0,     1,     1,     1,     1,     4,     1,     6,     0,     4,
  197.      3,     1,     4,     2,     2,     1,     4,     1,     2,     2,
  198.      2,     2,     1,     3,     3,     3,     3,     1,     3,     3,
  199.      1,     3,     3,     1,     3,     1,     3,     1,     5,     1,
  200.      3,     1,     0,     1,     1,     2,     2
  201. };
  202.  
  203. static short yydefact[] = {    51,
  204.      5,    63,    65,    64,    52,     6,     7,    69,     0,     0,
  205.     67,     0,     0,    55,     5,     5,     0,     5,     2,     9,
  206.     18,    10,    72,    78,    83,    88,    91,    94,    96,    98,
  207.    100,   102,     8,     0,    59,     0,    79,    80,    61,     0,
  208.     81,     0,    11,     0,     8,    82,     3,     5,     5,     5,
  209.      5,    51,     0,    19,    74,    75,     0,     0,     0,     0,
  210.      0,     0,     0,     0,     0,     0,     0,     0,     0,    57,
  211.     60,     0,     0,    62,    76,     0,     0,    14,    71,    12,
  212.     13,    16,    15,    17,     0,    51,    86,    87,    85,    84,
  213.     89,    90,    93,    92,   101,    95,    94,    97,     0,    73,
  214.      0,    70,    66,    51,     0,    56,     0,     0,     0,     0,
  215.      0,    45,    47,     0,     0,    51,    26,    51,     0,    21,
  216.     22,    23,    24,     0,     4,     0,    58,     0,     0,     0,
  217.      0,    59,    51,    51,    40,    41,    61,     0,    61,    42,
  218.      0,    43,    28,    20,    25,    27,    29,    99,    77,    68,
  219.      0,     0,    63,     0,    53,    54,    57,     0,    57,     0,
  220.     51,    32,     0,     0,     0,    49,     0,     0,     0,    51,
  221.      0,    59,     0,    46,    57,    48,    44,    30,     0,     0,
  222.      0,    59,     0,    51,    33,    38,    36,     0,    50,     0,
  223.     51,    51,    34,    31,     0,     0,    51,    39,    37,     0,
  224.     35,     0,     0,     0
  225. };
  226.  
  227. static short yydefgoto[] = {   202,
  228.     18,    19,    20,    21,    53,   117,   118,   119,   120,   121,
  229.    122,   170,   197,   192,   191,   123,   137,   139,   175,     1,
  230.    135,    22,    42,   102,    70,    73,    23,    35,    24,    74,
  231.     25,    26,    27,    28,    29,    30,    31,    32,   124,    -1
  232. };
  233.  
  234. static short yypact[] = {-32768,
  235.    250,   -33,-32768,-32768,-32768,-32768,-32768,-32768,   409,   409,
  236.    -31,   -25,   409,-32768,   349,   283,   409,   143,-32768,    68,
  237.     41,-32768,-32768,    75,    55,    73,    18,    29,     1,     7,
  238. -32768,-32768,-32768,   409,   409,   409,-32768,-32768,   409,    -2,
  239. -32768,    63,-32768,    44,    45,-32768,-32768,   283,   283,   316,
  240.    283,-32768,    62,-32768,-32768,-32768,   409,   409,   409,   409,
  241.    409,   409,   409,   409,   409,   409,   409,   409,    49,   104,
  242. -32768,    45,    76,    87,-32768,    88,    85,-32768,-32768,   114,
  243.    114,-32768,-32768,   114,   180,-32768,-32768,-32768,-32768,-32768,
  244. -32768,-32768,-32768,-32768,-32768,-32768,    97,-32768,    74,-32768,
  245.    409,-32768,-32768,-32768,   409,-32768,    84,    89,    91,    -8,
  246.     -8,-32768,    92,    -8,    -5,-32768,-32768,-32768,   213,-32768,
  247. -32768,-32768,-32768,    -8,   120,   409,-32768,   365,   -15,   409,
  248.    409,   425,-32768,-32768,-32768,-32768,   409,   409,   409,-32768,
  249.    409,-32768,   120,   120,-32768,-32768,-32768,-32768,-32768,-32768,
  250.     93,    94,    -4,    96,   120,   120,   104,    25,   104,   100,
  251. -32768,-32768,   109,   387,    -8,-32768,    -8,    -8,   180,-32768,
  252.    146,   409,   102,-32768,   104,-32768,-32768,   134,   180,   108,
  253.    110,   409,    -8,-32768,-32768,-32768,-32768,   111,-32768,   180,
  254. -32768,-32768,-32768,-32768,   180,   180,-32768,-32768,-32768,   180,
  255. -32768,   154,   157,-32768
  256. };
  257.  
  258. static short yypgoto[] = {-32768,
  259. -32768,   142,     3,    -7,-32768,  -118,   140,-32768,-32768,-32768,
  260. -32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,   -50,
  261.   -103,    31,-32768,   -84,  -126,   -51,-32768,-32768,-32768,   -81,
  262.     95,    56,    57,   -41,    98,   -63,-32768,   -36,    -1,-32768
  263. };
  264.  
  265.  
  266. #define    YYLAST        476
  267.  
  268.  
  269. static short yytable[] = {    33,
  270.    146,    85,    75,   133,    99,   154,   133,   136,    44,   163,
  271.    140,   142,    39,    33,    45,    34,    33,    43,    40,   104,
  272.    147,    93,    94,   129,    96,    97,    97,    63,    95,   150,
  273.     67,    64,    69,    71,    72,   125,    14,    65,   141,   134,
  274.     80,    81,   134,    84,    34,   181,    33,    33,    33,    33,
  275.    178,    50,    82,   128,    50,   188,   158,    66,    68,   104,
  276.    185,   174,   148,   176,   177,   143,    77,   144,    75,   166,
  277.     76,   194,   165,    86,   167,    51,   198,   199,    51,   189,
  278.     83,   201,   155,   156,    97,   157,    52,   159,    78,    79,
  279.    183,   149,    57,    58,    59,    60,    48,    49,   100,   127,
  280.     75,    75,    75,    37,    38,    55,    56,    41,    61,    62,
  281.    169,    46,    87,    88,    89,    90,   101,    91,    92,   179,
  282.    103,   104,   105,   106,    50,    66,   126,   130,   151,   152,
  283.     71,     5,   131,   190,   132,   138,   171,   161,   162,   160,
  284.    195,   196,    -1,   164,   168,     2,   200,     3,   180,   182,
  285.      4,   184,   186,   203,   187,   193,   204,     6,     7,    47,
  286.     54,     0,   173,     0,    98,     8,     0,     0,     0,     0,
  287.     71,     0,     0,     9,    10,    11,    12,     0,     0,    13,
  288.     71,    14,     2,     0,     3,    15,    16,     4,     0,     0,
  289.      0,     5,     0,    17,     0,     0,   107,     0,   108,   109,
  290.    110,   111,     8,   112,   113,   114,   115,     0,     0,     0,
  291.      9,    10,    11,    12,     0,     2,    13,     3,     0,     0,
  292.      4,     0,     0,    36,     0,    52,     0,   116,     0,   107,
  293.     17,   108,   109,   110,   111,     8,   112,   113,   114,   115,
  294.      0,     0,     0,     9,    10,    11,    12,     0,     0,    13,
  295.      0,     0,     2,     0,     3,     0,    36,     4,    52,   145,
  296.    116,     5,     0,    17,     6,     7,     0,     0,     0,     0,
  297.      0,     0,     8,     0,     0,     0,     0,     0,     0,     0,
  298.      9,    10,    11,    12,     0,     2,    13,     3,    14,     0,
  299.      4,     0,    15,    16,     0,     0,     0,     6,     7,     0,
  300.     17,     0,     0,     0,     0,     8,     0,     0,     0,     0,
  301.      0,     0,     0,     9,    10,    11,    12,     0,     2,    13,
  302.      3,    14,     0,     4,     0,    15,    16,     0,     0,     0,
  303.      6,     7,     0,    17,     0,     0,     0,     0,     8,     0,
  304.      0,     0,     0,     0,     0,     0,     9,    10,    11,    12,
  305.      0,     2,    13,     3,    14,     0,     4,     0,     0,    36,
  306.      0,     0,     0,     6,     7,     0,    17,     2,     0,     3,
  307.      0,     8,     4,     0,     0,     0,     5,     0,     0,     9,
  308.     10,    11,    12,     0,     0,    13,     0,     8,     0,     2,
  309.      0,     3,    36,     0,     4,     9,    10,    11,    12,    17,
  310.      0,    13,     0,     0,     0,     0,     0,     0,    36,     8,
  311.      0,     2,     0,     3,     0,    17,     4,     9,    10,    11,
  312.     12,     0,     0,    13,     0,     0,     0,   153,     0,     3,
  313.     36,     8,     4,     0,   172,     0,     0,    17,     0,     9,
  314.     10,    11,    12,     0,     0,    13,     0,     8,     0,     0,
  315.      0,     0,    36,     0,     0,     9,    10,    11,    12,    17,
  316.      0,    13,     0,     0,     0,     0,     0,     0,    36,     0,
  317.      0,     0,     0,     0,     0,    17
  318. };
  319.  
  320. static short yycheck[] = {     1,
  321.    119,    52,    39,    12,    68,   132,    12,   111,    16,    14,
  322.    114,   115,    44,    15,    16,    49,    18,    15,    44,    35,
  323.    124,    63,    64,   105,    66,    67,    68,    10,    65,    45,
  324.     30,    14,    34,    35,    36,    86,    39,     9,    44,    48,
  325.     48,    49,    48,    51,    49,   172,    48,    49,    50,    51,
  326.    169,    11,    50,   104,    11,   182,   138,    29,    52,    35,
  327.    179,   165,   126,   167,   168,   116,     4,   118,   105,    45,
  328.     40,   190,   157,    12,   159,    35,   195,   196,    35,   183,
  329.     50,   200,   133,   134,   126,   137,    46,   139,    45,    45,
  330.    175,   128,    38,    39,    40,    41,    29,    30,    50,   101,
  331.    137,   138,   139,     9,    10,    31,    32,    13,    36,    37,
  332.    161,    17,    57,    58,    59,    60,    13,    61,    62,   170,
  333.     45,    35,    35,    39,    11,    29,    53,    44,   130,   131,
  334.    132,    12,    44,   184,    44,    44,    28,    45,    45,   141,
  335.    191,   192,     0,    48,    45,     3,   197,     5,     3,    48,
  336.      8,    18,    45,     0,    45,    45,     0,    15,    16,    18,
  337.     21,    -1,   164,    -1,    67,    23,    -1,    -1,    -1,    -1,
  338.    172,    -1,    -1,    31,    32,    33,    34,    -1,    -1,    37,
  339.    182,    39,     3,    -1,     5,    43,    44,     8,    -1,    -1,
  340.     -1,    12,    -1,    51,    -1,    -1,    17,    -1,    19,    20,
  341.     21,    22,    23,    24,    25,    26,    27,    -1,    -1,    -1,
  342.     31,    32,    33,    34,    -1,     3,    37,     5,    -1,    -1,
  343.      8,    -1,    -1,    44,    -1,    46,    -1,    48,    -1,    17,
  344.     51,    19,    20,    21,    22,    23,    24,    25,    26,    27,
  345.     -1,    -1,    -1,    31,    32,    33,    34,    -1,    -1,    37,
  346.     -1,    -1,     3,    -1,     5,    -1,    44,     8,    46,    47,
  347.     48,    12,    -1,    51,    15,    16,    -1,    -1,    -1,    -1,
  348.     -1,    -1,    23,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
  349.     31,    32,    33,    34,    -1,     3,    37,     5,    39,    -1,
  350.      8,    -1,    43,    44,    -1,    -1,    -1,    15,    16,    -1,
  351.     51,    -1,    -1,    -1,    -1,    23,    -1,    -1,    -1,    -1,
  352.     -1,    -1,    -1,    31,    32,    33,    34,    -1,     3,    37,
  353.      5,    39,    -1,     8,    -1,    43,    44,    -1,    -1,    -1,
  354.     15,    16,    -1,    51,    -1,    -1,    -1,    -1,    23,    -1,
  355.     -1,    -1,    -1,    -1,    -1,    -1,    31,    32,    33,    34,
  356.     -1,     3,    37,     5,    39,    -1,     8,    -1,    -1,    44,
  357.     -1,    -1,    -1,    15,    16,    -1,    51,     3,    -1,     5,
  358.     -1,    23,     8,    -1,    -1,    -1,    12,    -1,    -1,    31,
  359.     32,    33,    34,    -1,    -1,    37,    -1,    23,    -1,     3,
  360.     -1,     5,    44,    -1,     8,    31,    32,    33,    34,    51,
  361.     -1,    37,    -1,    -1,    -1,    -1,    -1,    -1,    44,    23,
  362.     -1,     3,    -1,     5,    -1,    51,     8,    31,    32,    33,
  363.     34,    -1,    -1,    37,    -1,    -1,    -1,     3,    -1,     5,
  364.     44,    23,     8,    -1,    48,    -1,    -1,    51,    -1,    31,
  365.     32,    33,    34,    -1,    -1,    37,    -1,    23,    -1,    -1,
  366.     -1,    -1,    44,    -1,    -1,    31,    32,    33,    34,    51,
  367.     -1,    37,    -1,    -1,    -1,    -1,    -1,    -1,    44,    -1,
  368.     -1,    -1,    -1,    -1,    -1,    51
  369. };
  370. #define YYPURE 1
  371.  
  372. #line 1 "bison.sim"
  373.  
  374. /* Skeleton output parser for bison,
  375.    copyright (C) 1984 Bob Corbett and Richard Stallman
  376.  
  377.    Permission is granted to anyone to make or distribute verbatim copies of this program
  378.    provided that the copyright notice and this permission notice are preserved;
  379.    and provided that the recipient is not asked to waive or limit his right to
  380.    redistribute copies as permitted by this permission notice;
  381.    and provided that anyone possessing an executable copy
  382.    is granted access to copy the source code, in machine-readable form,
  383.    in some reasonable manner.
  384.  
  385.    Permission is granted to distribute derived works or enhanced versions of
  386.    this program under the above conditions with the additional condition
  387.    that the entire derivative or enhanced work
  388.    must be covered by a permission notice identical to this one.
  389.  
  390.    Anything distributed as part of a package containing portions derived
  391.    from this program, which cannot in current practice perform its function usefully
  392.    in the absense of what was derived directly from this program,
  393.    is to be considered as forming, together with the latter,
  394.    a single work derived from this program,
  395.    which must be entirely covered by a permission notice identical to this one
  396.    in order for distribution of the package to be permitted.
  397.  
  398.  In other words, you are welcome to use, share and improve this program.
  399.  You are forbidden to forbid anyone else to use, share and improve
  400.  what you give them.   Help stamp out software-hoarding!  */
  401.  
  402. /* This is the parser code that is written into each bison parser
  403.   when the %semantic_parser declaration is not specified in the grammar.
  404.   It was written by Richard Stallman by simplifying the hairy parser
  405.   used when %semantic_parser is specified.  */
  406.  
  407. /* Note: there must be only one dollar sign in this file.
  408.    It is replaced by the list of actions, each action
  409.    as one case of the switch.  */
  410.  
  411. /* #include <malloc.h>    */ /* WG */
  412. #include <string.h>    /* WG */
  413.  
  414. #define yyerrok        (yyerrstatus = 0)
  415. #define yyclearin    (yychar = YYEMPTY)
  416. #define YYEMPTY        -2
  417. #define YYEOF        0
  418. #define YYFAIL        goto yyerrlab;
  419.  
  420. #define YYTERROR    1
  421.  
  422. #ifndef YYIMPURE
  423. #define YYLEX        yylex()
  424. int yylex(void);    /* WG */
  425. #endif
  426.  
  427. #ifndef YYPURE
  428. #define YYLEX        yylex(&yylval, &yylloc)
  429. int yylex(int, int);    /* WG */
  430. #endif
  431.  
  432. /* If nonreentrant, generate the variables here */
  433.  
  434. #ifndef YYIMPURE
  435.  
  436. int    yychar;            /*  the lookahead symbol        */
  437. YYSTYPE    yylval;            /*  the semantic value of the        */
  438.                 /*  lookahead symbol            */
  439.  
  440. YYLTYPE yylloc;            /*  location data for the lookahead    */
  441.                 /*  symbol                */
  442.  
  443. int yydebug = 0;        /*  nonzero means print parse trace    */
  444.  
  445. #endif  /* YYIMPURE */
  446.  
  447.  
  448. /*  YYMAXDEPTH indicates the initial size of the parser's stacks    */
  449.  
  450. #ifndef    YYMAXDEPTH
  451. #define YYMAXDEPTH 200
  452. #endif
  453.  
  454. /*  YYMAXLIMIT is the maximum size the stacks can grow to
  455.     (effective only if the built-in stack extension method is used).  */
  456.  
  457. #ifndef YYMAXLIMIT
  458. #define YYMAXLIMIT 10000
  459. #endif
  460.  
  461.  
  462. #line 91 "bison.sim"
  463. int
  464. yyparse()
  465. {
  466.   register int yystate;
  467.   register int yyn;
  468.   register short *yyssp;
  469.   register YYSTYPE *yyvsp;
  470.   void yyerror(char *,...); /* WG  [ ',...' - added ADE ]*/
  471.   YYLTYPE *yylsp;
  472.   int yyerrstatus;    /*  number of tokens to shift before error messages enabled */
  473.   int yychar1;        /*  lookahead token as an internal (translated) token number */
  474.  
  475.   short    yyssa[YYMAXDEPTH];    /*  the state stack            */
  476.   YYSTYPE yyvsa[YYMAXDEPTH];    /*  the semantic value stack        */
  477.   YYLTYPE yylsa[YYMAXDEPTH];    /*  the location stack            */
  478.  
  479.   short *yyss = yyssa;        /*  refer to the stacks thru separate pointers */
  480.   YYSTYPE *yyvs = yyvsa;    /*  to allow yyoverflow to reallocate them elsewhere */
  481.   YYLTYPE *yyls = yylsa;
  482.  
  483.   int yymaxdepth = YYMAXDEPTH;
  484.  
  485. #ifndef YYPURE
  486.  
  487.   int yychar;
  488.   YYSTYPE yylval;
  489.   YYLTYPE yylloc;
  490.  
  491.   extern int yydebug;
  492.  
  493. #endif
  494.  
  495.  
  496.   YYSTYPE yyval;        /*  the variable used to return        */
  497.                 /*  semantic values from the action    */
  498.                 /*  routines                */
  499.  
  500.   int yylen;
  501.  
  502.   if (yydebug)
  503.     fprintf(stderr, "Starting parse\n");
  504.  
  505.   yystate = 0;
  506.   yyerrstatus = 0;
  507.   yychar = YYEMPTY;        /* Cause a token to be read.  */
  508.  
  509.   /* Initialize stack pointers.
  510.      Waste one element of value and location stack
  511.      so that they stay on the same level as the state stack.  */
  512.  
  513.   yyssp = yyss - 1;
  514.   yyvsp = yyvs;
  515.   yylsp = yyls;
  516.  
  517. /* Push a new state, which is found in  yystate  .  */
  518. /* In all cases, when you get here, the value and location stacks
  519.    have just been pushed. so pushing a state here evens the stacks.  */
  520. yynewstate:
  521.  
  522.   *++yyssp = yystate;
  523.  
  524.   if (yyssp >= yyss + yymaxdepth - 1)
  525.     {
  526.       /* Give user a chance to reallocate the stack */
  527.       /* Use copies of these so that the &'s don't force the real ones into memory. */
  528.       YYSTYPE *yyvs1 = yyvs;
  529.       YYLTYPE *yyls1 = yyls;
  530.       short *yyss1 = yyss;
  531.  
  532.       /* Get the current used size of the three stacks, in elements.  */
  533.       int size = yyssp - yyss + 1;
  534.  
  535. #ifdef yyoverflow
  536.       /* Each stack pointer address is followed by the size of
  537.      the data in use in that stack, in bytes.  */
  538.       yyoverflow("parser stack overflow",
  539.          &yyss1, size * sizeof (*yyssp),
  540.          &yyvs1, size * sizeof (*yyvsp),
  541.          &yyls1, size * sizeof (*yylsp),
  542.          &yymaxdepth);
  543.  
  544.       yyss = yyss1; yyvs = yyvs1; yyls = yyls1;
  545. #else /* no yyoverflow */
  546.       /* Extend the stack our own way.  */
  547.       if (yymaxdepth >= YYMAXLIMIT)
  548.     yyerror("parser stack overflow");
  549.       yymaxdepth *= 2;
  550.       if (yymaxdepth > YYMAXLIMIT)
  551.     yymaxdepth = YYMAXLIMIT;
  552.       yyss = (short *) alloca (yymaxdepth * sizeof (*yyssp));
  553.       memcpy ((char *)yyss, (char *)yyss1, size * sizeof (*yyssp));    /* WG */
  554.       yyls = (YYLTYPE *) alloca (yymaxdepth * sizeof (*yylsp));
  555.       memcpy ( (char *)yyls, (char *)yyls1,size * sizeof (*yylsp));    /* WG */
  556.       yyvs = (YYSTYPE *) alloca (yymaxdepth * sizeof (*yyvsp));
  557.       memcpy ( (char *)yyvs, (char *)yyvs1, size * sizeof (*yyvsp));    /* WG */
  558. #endif /* no yyoverflow */
  559.  
  560.       yyssp = yyss + size - 1;
  561.       yylsp = yyls + size - 1;
  562.       yyvsp = yyvs + size - 1;
  563.  
  564.       if (yydebug)
  565.     fprintf(stderr, "Stack size increased to %d\n", yymaxdepth);
  566.  
  567.       if (yyssp >= yyss + yymaxdepth - 1)
  568.     YYERROR;
  569.     }
  570.  
  571.   if (yydebug)
  572.     fprintf(stderr, "Entering state %d\n", yystate);
  573.  
  574. /* Do appropriate processing given the current state.  */
  575. /* Read a lookahead token if we need one and don't already have one.  */
  576. yyresume:
  577.  
  578.   /* First try to decide what to do without reference to lookahead token.  */
  579.  
  580.   yyn = (int)yypact[yystate];    /* WG */
  581.   if (yyn == YYFLAG)
  582.     goto yydefault;
  583.  
  584.   /* Not known => get a lookahead token if don't already have one.  */
  585.  
  586.   /* yychar is either YYEMPTY or YYEOF
  587.      or a valid token in external form.  */
  588.  
  589.   if (yychar == YYEMPTY)
  590.     {
  591.       yychar = YYLEX;
  592.     }
  593.  
  594.   /* Convert token to internal form (in yychar1) for indexing tables with */
  595.  
  596.   if (yychar <= 0)        /* This means end of input. */
  597.     {
  598.       yychar1 = 0;
  599.       yychar = YYEOF;        /* Don't call YYLEX any more */
  600.  
  601.       if (yydebug)
  602.     fprintf(stderr, "Now at end of input.\n");
  603.     }
  604.   else
  605.     {
  606.       yychar1 = YYTRANSLATE(yychar);
  607.  
  608.       if (yydebug)
  609.     fprintf(stderr, "Parsing next token; it is %d (%s)\n", yychar, yytname[yychar1]);
  610.     }
  611.  
  612.   yyn += yychar1;
  613.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
  614.     goto yydefault;
  615.  
  616.   yyn = yytable[yyn];
  617.  
  618.   /* yyn is what to do for this token type in this state.
  619.      Negative => reduce, -yyn is rule number.
  620.      Positive => shift, yyn is new state.
  621.        New state is final state => don't bother to shift,
  622.        just return success.
  623.      0, or most negative number => error.  */
  624.  
  625.   if (yyn < 0)
  626.     {
  627.       if (yyn == (int)YYFLAG)    /* WG */
  628.     goto yyerrlab;
  629.       yyn = -yyn;
  630.       goto yyreduce;
  631.     }
  632.   else if (yyn == 0)
  633.     goto yyerrlab;
  634.  
  635.   if (yyn == YYFINAL)
  636.     YYACCEPT;
  637.  
  638.   /* Shift the lookahead token.  */
  639.  
  640.   if (yydebug)
  641.     fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
  642.  
  643.   /* Discard the token being shifted unless it is eof.  */
  644.   if (yychar != YYEOF)
  645.     yychar = YYEMPTY;
  646.  
  647.   *++yyvsp = yylval;
  648.   *++yylsp = yylloc;
  649.  
  650.   /* count tokens shifted since error; after three, turn off error status.  */
  651.   if (yyerrstatus) yyerrstatus--;
  652.  
  653.   yystate = yyn;
  654.   goto yynewstate;
  655.  
  656. /* Do the default action for the current state.  */
  657. yydefault:
  658.  
  659.   yyn = yydefact[yystate];
  660.   if (yyn == 0)
  661.     goto yyerrlab;
  662.  
  663. /* Do a reduction.  yyn is the number of a rule to reduce with.  */
  664. yyreduce:
  665.   yylen = yyr2[yyn];
  666.   yyval = yyvsp[1-yylen]; /* implement default value of the action */
  667.  
  668.   if (yydebug)
  669.     {
  670.       if (yylen == 1)
  671.     fprintf (stderr, "Reducing 1 value via line %d, ",
  672.          yyrline[yyn]);
  673.       else
  674.     fprintf (stderr, "Reducing %d values via line %d, ",
  675.          yylen, yyrline[yyn]);
  676.     }
  677. /* the action file follows */
  678.  
  679.   switch (yyn) {
  680.  
  681. case 1:
  682. #line 119 "awk.y"
  683. { expression_value = yyvsp[0].nodeval; ;
  684.     break;}
  685. case 2:
  686. #line 125 "awk.y"
  687. { yyval.nodeval = node (yyvsp[0].nodeval, Node_rule_list,(NODE *) NULL); ;
  688.     break;}
  689. case 3:
  690. #line 128 "awk.y"
  691. { yyval.nodeval = append_right (yyvsp[-1].nodeval, node(yyvsp[0].nodeval, Node_rule_list,(NODE *) NULL)); ;
  692.     break;}
  693. case 4:
  694. #line 133 "awk.y"
  695. {
  696.             ++patterns;
  697.             ++actions;
  698.             yyval.nodeval = node (yyvsp[-3].nodeval, Node_rule_node, yyvsp[-2].nodeval);
  699.             ;
  700.     break;}
  701. case 5:
  702. #line 143 "awk.y"
  703. { yyval.nodeval = NULL; ;
  704.     break;}
  705. case 6:
  706. #line 145 "awk.y"
  707. {
  708.               --patterns;
  709.               --actions;
  710.               yyval.nodeval = node ((NODE *)NULL, Node_K_BEGIN,(NODE *) NULL);
  711.             ;
  712.     break;}
  713. case 7:
  714. #line 151 "awk.y"
  715. {  yyval.nodeval = node ((NODE *)NULL, Node_K_END,(NODE *) NULL); ;
  716.     break;}
  717. case 8:
  718. #line 153 "awk.y"
  719. { yyval.nodeval = yyvsp[0].nodeval; ;
  720.     break;}
  721. case 9:
  722. #line 158 "awk.y"
  723. { yyval.nodeval = yyvsp[0].nodeval; ;
  724.     break;}
  725. case 10:
  726. #line 160 "awk.y"
  727. { yyval.nodeval = node (node (make_number((AWKNUM)0), Node_field_spec,
  728.                     (NODE *)NULL), Node_match, yyvsp[0].nodeval); ;
  729.     break;}
  730. case 11:
  731. #line 163 "awk.y"
  732. { yyval.nodeval = node (yyvsp[0].nodeval, Node_not,(NODE *) NULL); ;
  733.     break;}
  734. case 12:
  735. #line 165 "awk.y"
  736. { yyval.nodeval = node (yyvsp[-2].nodeval, Node_and, yyvsp[0].nodeval); ;
  737.     break;}
  738. case 13:
  739. #line 167 "awk.y"
  740. { yyval.nodeval = node (yyvsp[-2].nodeval, Node_or, yyvsp[0].nodeval); ;
  741.     break;}
  742. case 14:
  743. #line 169 "awk.y"
  744. {
  745.               yyval.nodeval = yyvsp[-1].nodeval;
  746.               want_concat_token = 0;
  747.             ;
  748.     break;}
  749. case 15:
  750. #line 174 "awk.y"
  751. { yyval.nodeval = node(yyvsp[-2].nodeval, Node_match, yyvsp[0].nodeval); ;
  752.     break;}
  753. case 16:
  754. #line 176 "awk.y"
  755. { yyval.nodeval = node(yyvsp[-2].nodeval, Node_match, yyvsp[0].nodeval); ;
  756.     break;}
  757. case 17:
  758. #line 178 "awk.y"
  759. { yyval.nodeval = mkrangenode ( node(yyvsp[-2].nodeval, Node_cond_pair, yyvsp[0].nodeval) ); ;
  760.     break;}
  761. case 18:
  762. #line 184 "awk.y"
  763. { --actions; yyval.nodeval = NULL; ;
  764.     break;}
  765. case 19:
  766. #line 186 "awk.y"
  767. { yyval.nodeval = yyvsp[0].nodeval; ;
  768.     break;}
  769. case 20:
  770. #line 192 "awk.y"
  771. { yyval.nodeval = yyvsp[-1].nodeval; ;
  772.     break;}
  773. case 21:
  774. #line 194 "awk.y"
  775. { yyval.nodeval = yyvsp[0].nodeval; ;
  776.     break;}
  777. case 22:
  778. #line 196 "awk.y"
  779. { yyval.nodeval = yyvsp[0].nodeval; ;
  780.     break;}
  781. case 23:
  782. #line 198 "awk.y"
  783. { yyval.nodeval = yyvsp[0].nodeval; ;
  784.     break;}
  785. case 24:
  786. #line 200 "awk.y"
  787. { yyval.nodeval = yyvsp[0].nodeval; ;
  788.     break;}
  789. case 25:
  790. #line 205 "awk.y"
  791. { yyval.nodeval = node (yyvsp[-1].nodeval, Node_statement_list, (NODE *)NULL); ;
  792.     break;}
  793. case 26:
  794. #line 210 "awk.y"
  795. { yyval.nodeval = node (yyvsp[0].nodeval, Node_statement_list, (NODE *)NULL); ;
  796.     break;}
  797. case 27:
  798. #line 212 "awk.y"
  799. { yyval.nodeval = append_right(yyvsp[-1].nodeval,
  800.                 node(yyvsp[0].nodeval, Node_statement_list, (NODE *)NULL)); ;
  801.     break;}
  802. case 28:
  803. #line 218 "awk.y"
  804. { yyval.nodeval = (NODE *)NULL; ;
  805.     break;}
  806. case 29:
  807. #line 220 "awk.y"
  808. { yyval.nodeval = node (yyvsp[-1].nodeval, Node_statement_list, (NODE *)NULL); ;
  809.     break;}
  810. case 30:
  811. #line 226 "awk.y"
  812. { yyval.nodeval = node (yyvsp[-3].nodeval, Node_K_if,
  813.                 node (yyvsp[0].nodeval, Node_if_branches, (NODE *)NULL)); ;
  814.     break;}
  815. case 31:
  816. #line 230 "awk.y"
  817. { yyval.nodeval = node (yyvsp[-6].nodeval, Node_K_if,
  818.                 node (yyvsp[-3].nodeval, Node_if_branches, yyvsp[0].nodeval)); ;
  819.     break;}
  820. case 32:
  821. #line 237 "awk.y"
  822. { want_concat_token = 0; ;
  823.     break;}
  824. case 33:
  825. #line 239 "awk.y"
  826. { yyval.nodeval = node (yyvsp[-4].nodeval, Node_K_while, yyvsp[0].nodeval); ;
  827.     break;}
  828. case 34:
  829. #line 241 "awk.y"
  830. { want_concat_token = 0; ;
  831.     break;}
  832. case 35:
  833. #line 243 "awk.y"
  834. { yyval.nodeval = node (yyvsp[0].nodeval, Node_K_for, (NODE *)make_for_loop (yyvsp[-8].nodeval, yyvsp[-6].nodeval, yyvsp[-4].nodeval)); ;
  835.     break;}
  836. case 36:
  837. #line 245 "awk.y"
  838. { want_concat_token = 0; ;
  839.     break;}
  840. case 37:
  841. #line 247 "awk.y"
  842. { yyval.nodeval = node (yyvsp[0].nodeval, Node_K_for,
  843.                 (NODE *)make_for_loop (yyvsp[-7].nodeval, (NODE *)NULL, yyvsp[-4].nodeval)); ;
  844.     break;}
  845. case 38:
  846. #line 250 "awk.y"
  847. { want_concat_token = 0; ;
  848.     break;}
  849. case 39:
  850. #line 252 "awk.y"
  851. { yyval.nodeval = node (yyvsp[0].nodeval, Node_K_arrayfor,
  852.                 (NODE *)make_for_loop(variable(yyvsp[-7].sval), (NODE *)NULL, variable(yyvsp[-4].sval))); ;
  853.     break;}
  854. case 40:
  855. #line 256 "awk.y"
  856. { yyval.nodeval = node ((NODE *)NULL, Node_K_break, (NODE *)NULL); ;
  857.     break;}
  858. case 41:
  859. #line 258 "awk.y"
  860. { yyval.nodeval = node ((NODE *)NULL, Node_K_continue, (NODE *)NULL); ;
  861.     break;}
  862. case 42:
  863. #line 260 "awk.y"
  864. { yyval.nodeval = node ((NODE *)NULL, Node_K_next, (NODE *)NULL); ;
  865.     break;}
  866. case 43:
  867. #line 262 "awk.y"
  868. { yyval.nodeval = node ((NODE *)NULL, Node_K_exit, (NODE *)NULL); ;
  869.     break;}
  870. case 44:
  871. #line 264 "awk.y"
  872. { yyval.nodeval = node (yyvsp[-2].nodeval, Node_K_exit, (NODE *)NULL); ;
  873.     break;}
  874. case 45:
  875. #line 270 "awk.y"
  876. { ++want_redirect; want_concat_token = 0; ;
  877.     break;}
  878. case 46:
  879. #line 272 "awk.y"
  880. {
  881.               want_redirect = 0;
  882.               /* $4->lnode = NULL; */
  883.               yyval.nodeval = node (yyvsp[-2].nodeval, Node_K_print, yyvsp[-1].nodeval);
  884.             ;
  885.     break;}
  886. case 47:
  887. #line 278 "awk.y"
  888. { ++want_redirect; want_concat_token = 0;
  889.     break;}
  890. case 48:
  891. #line 280 "awk.y"
  892. {
  893.               want_redirect = 0;
  894.               /* $4->lnode = NULL; */
  895.               yyval.nodeval = node (yyvsp[-2].nodeval, Node_K_printf, yyvsp[-1].nodeval);
  896.             ;
  897.     break;}
  898. case 49:
  899. #line 286 "awk.y"
  900. { ++want_redirect;
  901.             want_concat_token = 0; ;
  902.     break;}
  903. case 50:
  904. #line 289 "awk.y"
  905. {
  906.               want_redirect = 0;
  907.               yyval.nodeval = node (yyvsp[-4].nodeval, Node_K_printf, yyvsp[-1].nodeval);
  908.             ;
  909.     break;}
  910. case 52:
  911. #line 299 "awk.y"
  912. { yyval.nodetypeval = Node_illegal; ;
  913.     break;}
  914. case 53:
  915. #line 304 "awk.y"
  916. { yyval.nodetypeval = Node_illegal; ;
  917.     break;}
  918. case 54:
  919. #line 306 "awk.y"
  920. { yyval.nodetypeval = Node_illegal; ;
  921.     break;}
  922. case 55:
  923. #line 311 "awk.y"
  924. { ++want_regexp; ;
  925.     break;}
  926. case 56:
  927. #line 313 "awk.y"
  928. {
  929.                 want_regexp = 0;
  930.                 yyval.nodeval = make_regex(yyvsp[-1].sval);
  931.             ;
  932.     break;}
  933. case 57:
  934. #line 321 "awk.y"
  935. { yyval.nodeval = NULL; /* node (NULL, Node_redirect_nil, NULL); */ ;
  936.     break;}
  937. case 58:
  938. #line 323 "awk.y"
  939. { yyval.nodeval = node (yyvsp[0].nodeval, yyvsp[-1].nodetypeval, (NODE *)NULL); ;
  940.     break;}
  941. case 59:
  942. #line 330 "awk.y"
  943. { yyval.nodeval = NULL; /* node(NULL, Node_builtin, NULL); */ ;
  944.     break;}
  945. case 60:
  946. #line 332 "awk.y"
  947. { yyval.nodeval = yyvsp[0].nodeval; ;
  948.     break;}
  949. case 61:
  950. #line 337 "awk.y"
  951. { yyval.nodeval = NULL; ;
  952.     break;}
  953. case 62:
  954. #line 339 "awk.y"
  955. { yyval.nodeval = yyvsp[0].nodeval; ;
  956.     break;}
  957. case 63:
  958. #line 344 "awk.y"
  959. { yyval.nodeval = variable (yyvsp[0].sval); ;
  960.     break;}
  961. case 64:
  962. #line 346 "awk.y"
  963. { yyval.nodeval = make_number(yyvsp[0].fval); ;
  964.     break;}
  965. case 65:
  966. #line 348 "awk.y"
  967. { yyval.nodeval = make_string (yyvsp[0].sval, -1); ;
  968.     break;}
  969. case 66:
  970. #line 350 "awk.y"
  971. { ++want_concat_token; yyval.nodeval = snode (yyvsp[-1].nodeval, Node_builtin, yyvsp[-3].ptrval); ;
  972.     break;}
  973. case 67:
  974. #line 352 "awk.y"
  975. { ++want_concat_token; yyval.nodeval = snode ((NODE *)NULL, Node_builtin, yyvsp[0].ptrval); ;
  976.     break;}
  977. case 68:
  978. #line 354 "awk.y"
  979. { want_concat_token;
  980.             yyval.nodeval = snode(node(yyvsp[-3].nodeval, Node_expression_list, yyvsp[-1].nodeval), Node_builtin, yyvsp[-5].ptrval); ;
  981.     break;}
  982. case 69:
  983. #line 357 "awk.y"
  984. { ++want_redirect; ;
  985.     break;}
  986. case 70:
  987. #line 359 "awk.y"
  988. {
  989.                 want_redirect = 0;
  990.                 yyval.nodeval = node(yyvsp[-1].nodeval, Node_K_getline, yyvsp[0].nodeval);
  991.             ;
  992.     break;}
  993. case 71:
  994. #line 364 "awk.y"
  995. { yyval.nodeval = yyvsp[-1].nodeval; ;
  996.     break;}
  997. case 72:
  998. #line 369 "awk.y"
  999. { yyval.nodeval = yyvsp[0].nodeval; ;
  1000.     break;}
  1001. case 73:
  1002. #line 371 "awk.y"
  1003. { yyval.nodeval = node (variable(yyvsp[-3].sval), Node_subscript, yyvsp[-1].nodeval); ;
  1004.     break;}
  1005. case 74:
  1006. #line 373 "awk.y"
  1007. { yyval.nodeval = node (yyvsp[-1].nodeval, Node_postincrement, (NODE *)NULL); ;
  1008.     break;}
  1009. case 75:
  1010. #line 375 "awk.y"
  1011. { yyval.nodeval = node (yyvsp[-1].nodeval, Node_postdecrement, (NODE *)NULL); ;
  1012.     break;}
  1013. case 76:
  1014. #line 380 "awk.y"
  1015. { yyval.nodeval = node (yyvsp[0].nodeval, Node_expression_list, (NODE *)NULL); ;
  1016.     break;}
  1017. case 77:
  1018. #line 382 "awk.y"
  1019. { yyval.nodeval = append_right(yyvsp[-3].nodeval,
  1020.                 node (yyvsp[0].nodeval, Node_expression_list, (NODE *)NULL)); ;
  1021.     break;}
  1022. case 78:
  1023. #line 388 "awk.y"
  1024. { yyval.nodeval = yyvsp[0].nodeval; ;
  1025.     break;}
  1026. case 79:
  1027. #line 390 "awk.y"
  1028. { yyval.nodeval = node (yyvsp[0].nodeval, Node_preincrement, (NODE *)NULL); ;
  1029.     break;}
  1030. case 80:
  1031. #line 392 "awk.y"
  1032. { yyval.nodeval = node (yyvsp[0].nodeval, Node_predecrement, (NODE *)NULL); ;
  1033.     break;}
  1034. case 81:
  1035. #line 394 "awk.y"
  1036. { yyval.nodeval = node (yyvsp[0].nodeval, Node_unary_minus, (NODE *)NULL); ;
  1037.     break;}
  1038. case 82:
  1039. #line 396 "awk.y"
  1040. { yyval.nodeval = node (yyvsp[0].nodeval, Node_field_spec, (NODE *)NULL); ;
  1041.     break;}
  1042. case 83:
  1043. #line 401 "awk.y"
  1044. { yyval.nodeval = yyvsp[0].nodeval; ;
  1045.     break;}
  1046. case 84:
  1047. #line 403 "awk.y"
  1048. { yyval.nodeval = node (yyvsp[-2].nodeval, Node_pow, yyvsp[0].nodeval); ;
  1049.     break;}
  1050. case 85:
  1051. #line 405 "awk.y"
  1052. { yyval.nodeval = node (yyvsp[-2].nodeval, Node_mod, yyvsp[0].nodeval); ;
  1053.     break;}
  1054. case 86:
  1055. #line 407 "awk.y"
  1056. { yyval.nodeval = node (yyvsp[-2].nodeval, Node_times, yyvsp[0].nodeval); ;
  1057.     break;}
  1058. case 87:
  1059. #line 409 "awk.y"
  1060. { yyval.nodeval = node (yyvsp[-2].nodeval, Node_quotient, yyvsp[0].nodeval); ;
  1061.     break;}
  1062. case 88:
  1063. #line 414 "awk.y"
  1064. { yyval.nodeval = yyvsp[0].nodeval; ;
  1065.     break;}
  1066. case 89:
  1067. #line 416 "awk.y"
  1068. { yyval.nodeval = node (yyvsp[-2].nodeval, Node_plus, yyvsp[0].nodeval); ;
  1069.     break;}
  1070. case 90:
  1071. #line 418 "awk.y"
  1072. { yyval.nodeval = node (yyvsp[-2].nodeval, Node_minus, yyvsp[0].nodeval); ;
  1073.     break;}
  1074. case 91:
  1075. #line 423 "awk.y"
  1076. { yyval.nodeval = yyvsp[0].nodeval; ;
  1077.     break;}
  1078. case 92:
  1079. #line 425 "awk.y"
  1080. { yyval.nodeval = node(yyvsp[-2].nodeval, Node_concat, yyvsp[0].nodeval); ;
  1081.     break;}
  1082. case 93:
  1083. #line 427 "awk.y"
  1084. { yyval.nodeval = node(yyvsp[-2].nodeval, yyvsp[-1].nodetypeval, yyvsp[0].nodeval); ;
  1085.     break;}
  1086. case 94:
  1087. #line 432 "awk.y"
  1088. { yyval.nodeval = yyvsp[0].nodeval; ;
  1089.     break;}
  1090. case 95:
  1091. #line 434 "awk.y"
  1092. { yyval.nodeval = node (yyvsp[-2].nodeval, Node_and, yyvsp[0].nodeval); ;
  1093.     break;}
  1094. case 96:
  1095. #line 439 "awk.y"
  1096. { yyval.nodeval = yyvsp[0].nodeval; ;
  1097.     break;}
  1098. case 97:
  1099. #line 441 "awk.y"
  1100. { yyval.nodeval = node (yyvsp[-2].nodeval, Node_or, yyvsp[0].nodeval); ;
  1101.     break;}
  1102. case 98:
  1103. #line 446 "awk.y"
  1104. { yyval.nodeval = yyvsp[0].nodeval; ;
  1105.     break;}
  1106. case 99:
  1107. #line 448 "awk.y"
  1108. { yyval.nodeval = node (yyvsp[-4].nodeval, Node_cond_exp, node(yyvsp[-2].nodeval, Node_illegal, yyvsp[0].nodeval)); ;
  1109.     break;}
  1110. case 100:
  1111. #line 453 "awk.y"
  1112. { yyval.nodeval = yyvsp[0].nodeval; ;
  1113.     break;}
  1114. case 101:
  1115. #line 455 "awk.y"
  1116. { yyval.nodeval = node (yyvsp[-2].nodeval, yyvsp[-1].nodetypeval, yyvsp[0].nodeval); ;
  1117.     break;}
  1118. case 102:
  1119. #line 460 "awk.y"
  1120. { yyval.nodeval = yyvsp[0].nodeval; ;
  1121.     break;}
  1122. case 103:
  1123. #line 465 "awk.y"
  1124. { yyval.nodetypeval = Node_illegal; ;
  1125.     break;}
  1126. }
  1127.    /* the action file gets copied in in place of this dollarsign */
  1128. /* the action file ends */
  1129. #line 308 "bison.sim"
  1130.  
  1131.   yyvsp -= yylen;
  1132.   yylsp -= yylen;
  1133.   yyssp -= yylen;
  1134.  
  1135.   if (yydebug)
  1136.     {
  1137.       short *ssp1 = yyss - 1;
  1138.       fprintf (stderr, "state stack now", yyssp-yyss);
  1139.       while (ssp1 != yyssp)
  1140.     fprintf (stderr, " %d", *++ssp1);
  1141.       fprintf (stderr, "\n");
  1142.     }
  1143.  
  1144.   *++yyvsp = yyval;
  1145.  
  1146.   yylsp++;
  1147.   if (yylen == 0)
  1148.     {
  1149.       yylsp->first_line = yylloc.first_line;
  1150.       yylsp->first_column = yylloc.first_column;
  1151.       yylsp->last_line = (yylsp-1)->last_line;
  1152.       yylsp->last_column = (yylsp-1)->last_column;
  1153.       yylsp->text = 0;
  1154.     }
  1155.   else
  1156.     {
  1157.       yylsp->last_line = (yylsp+yylen-1)->last_line;
  1158.       yylsp->last_column = (yylsp+yylen-1)->last_column;
  1159.     }
  1160.  
  1161.   /* Now "shift" the result of the reduction.
  1162.      Determine what state that goes to,
  1163.      based on the state we popped back to
  1164.      and the rule number reduced by.  */
  1165.  
  1166.   yyn = yyr1[yyn];
  1167.  
  1168.   yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
  1169.   if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
  1170.     yystate = yytable[yystate];
  1171.   else
  1172.     yystate = yydefgoto[yyn - YYNTBASE];
  1173.  
  1174.   goto yynewstate;
  1175.  
  1176. yyerrlab:   /* here on detecting error */
  1177.  
  1178.   if (! yyerrstatus)
  1179.     /* If not already recovering from an error, report this error.  */
  1180.     {
  1181.       yyerror("parse error");
  1182.     }
  1183.  
  1184.   if (yyerrstatus == 3)
  1185.     {
  1186.       /* if just tried and failed to reuse lookahead token after an error, discard it.  */
  1187.  
  1188.       /* return failure if at end of input */
  1189.       if (yychar == YYEOF)
  1190.     YYERROR;
  1191.  
  1192.       if (yydebug)
  1193.     fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
  1194.  
  1195.       yychar = YYEMPTY;
  1196.     }
  1197.  
  1198.   /* Else will try to reuse lookahead token
  1199.      after shifting the error token.  */
  1200.  
  1201.   yyerrstatus = 3;        /* Each real token shifted decrements this */
  1202.  
  1203.   goto yyerrhandle;
  1204.  
  1205. yyerrdefault:  /* current state does not do anything special for the error token. */
  1206.  
  1207.   yyn = yydefact[yystate];  /* If its default is to accept any token, ok.  Otherwise pop it.*/
  1208.   if (yyn) goto yydefault;
  1209.  
  1210. yyerrpop:   /* pop the current state because it cannot handle the error token */
  1211.  
  1212.   if (yyssp == yyss) YYERROR;
  1213.   yyvsp--;
  1214.   yylsp--;
  1215.   yystate = *--yyssp;
  1216.  
  1217.   if (yydebug)
  1218.     {
  1219.       short *ssp1 = yyss - 1;
  1220.       fprintf (stderr, "Error: state stack now", yyssp-yyss);
  1221.       while (ssp1 != yyssp)
  1222.     fprintf (stderr, " %d", *++ssp1);
  1223.       fprintf (stderr, "\n");
  1224.     }
  1225.  
  1226. yyerrhandle:
  1227.  
  1228.   yyn = yypact[yystate];
  1229.   if (yyn == (int)YYFLAG)    /* WG */
  1230.     goto yyerrdefault;
  1231.  
  1232.   yyn += YYTERROR;
  1233.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
  1234.     goto yyerrdefault;
  1235.  
  1236.   yyn = yytable[yyn];
  1237.   if (yyn < 0)
  1238.     {
  1239.       if (yyn == YYFLAG)
  1240.     goto yyerrpop;
  1241.       yyn = -yyn;
  1242.       goto yyreduce;
  1243.     }
  1244.   else if (yyn == 0)
  1245.     goto yyerrpop;
  1246.  
  1247.   if (yyn == YYFINAL)
  1248.     YYACCEPT;
  1249.  
  1250.   if (yydebug)
  1251.     fprintf(stderr, "Shifting error token, ");
  1252.  
  1253.   *++yyvsp = yylval;
  1254.   *++yylsp = yylloc;
  1255.  
  1256.   yystate = yyn;
  1257.   goto yynewstate;
  1258. }
  1259. #line 472 "awk.y"
  1260.  
  1261.  
  1262.  
  1263. struct token {
  1264.   char *operator;
  1265.   NODETYPE value;
  1266.   int class;
  1267.   NODE *(*ptr)();
  1268. };
  1269.  
  1270. #ifndef NULL
  1271.  
  1272. #define NULL 0
  1273.  
  1274. #endif
  1275.  
  1276. NODE    *do_atan2(),*do_close(), *do_cos(), *do_exp(),    *do_getline(),
  1277.     *do_gsub(), *do_index(), *do_length(), *do_log(), *do_match(),
  1278.     *do_rand(), *do_sin(), *do_sqrt(),
  1279.     *do_srand(), *do_sprintf(), *do_sub(), *do_substr(),  *do_system(),
  1280.     *do_split(), *do_int();
  1281.  
  1282.     /* Special functions for debugging */
  1283. #ifndef FAST
  1284. NODE    *do_prvars(),    *do_bp();
  1285. #endif
  1286.  
  1287. /* Tokentab is sorted ascii ascending order, so it can be binary searched. */
  1288. /* (later.  Right now its just sort of linear search (SLOW!!) */
  1289.  
  1290. #define END(s) (s-1 + sizeof(s)/sizeof(s[0]))
  1291.  
  1292. static struct token tokentab[] = {
  1293.   {"BEGIN",    Node_illegal,        LEX_BEGIN,    0},
  1294.   {"END",    Node_illegal,        LEX_END,    0},
  1295.   {"atan2", Node_builtin,        LEX_BUILTIN,    do_atan2},
  1296. #ifndef FAST
  1297.   {"bp",    Node_builtin,        LEX_BUILTIN,    do_bp},
  1298. #endif
  1299.   {"break", Node_K_break,        LEX_BREAK,    0},
  1300.   {"close", Node_builtin,        LEX_BUILTIN, do_close},
  1301.   {"continue",    Node_K_continue,    LEX_CONTINUE,    0},
  1302.   {"cos",    Node_builtin,        LEX_BUILTIN,    do_cos},
  1303.   {"else",    Node_illegal,        LEX_ELSE,    0},
  1304.   {"exit",    Node_K_exit,        LEX_EXIT,    0},
  1305.   {"exp",    Node_builtin,        LEX_BUILTIN,    do_exp},
  1306.   {"for",    Node_K_for,        LEX_FOR,    0},
  1307.   {"getline",    Node_K_getline,   LEX_GETLINE,      do_getline},
  1308.   {"gsub",    Node_builtin,        LEX_SUB,    do_gsub},
  1309.   {"if",    Node_K_if,        LEX_IF,        0},
  1310.   {"in",    Node_illegal,        LEX_IN,     0},
  1311.   {"index",    Node_builtin,        LEX_BUILTIN,    do_index},
  1312.   {"int",    Node_builtin,        LEX_BUILTIN,    do_int},
  1313.   {"length",    Node_builtin,        LEX_BUILTIN,    do_length},
  1314.   {"log",    Node_builtin,        LEX_BUILTIN,    do_log},
  1315.   {"match", Node_builtin,        LEX_BUILTIN,    do_match},
  1316.   {"next",    Node_K_next,        LEX_NEXT,    0},
  1317.   {"print",    Node_K_print,        LEX_PRINT,    0},
  1318.   {"printf",    Node_K_printf,        LEX_PRINTF,    0},
  1319. #ifndef FAST
  1320.   {"prvars",    Node_builtin,        LEX_BUILTIN,    do_prvars},
  1321. #endif
  1322.   {"rand", Node_builtin,        LEX_BUILTIN,    do_rand},
  1323.   {"sin", Node_builtin,         LEX_BUILTIN,    do_sin},
  1324.   {"split",    Node_builtin,        LEX_BUILTIN,    do_split},
  1325.   {"sprintf",    Node_builtin,        LEX_BUILTIN,    do_sprintf},
  1326.   {"srand", Node_builtin,        LEX_BUILTIN,    do_srand},
  1327.   {"sqrt",    Node_builtin,        LEX_BUILTIN,    do_sqrt},
  1328.   {"sub",    Node_builtin,        LEX_SUB,    do_sub},
  1329.   {"substr",    Node_builtin,        LEX_BUILTIN,    do_substr},
  1330.   {"system",    Node_builtin,    LEX_BUILTIN,    do_system},
  1331.   {"while",    Node_K_while,        LEX_WHILE,    0},
  1332.   {NULL,    Node_illegal,        ERROR,        0}
  1333. };
  1334.  
  1335. /* Read one token, getting characters through lexptr.  */
  1336.  
  1337. static int
  1338. yylex ()
  1339. {
  1340.   register int c;
  1341.   register int namelen;
  1342.   register char *tokstart;
  1343.   register struct token *toktab, *low, *high, *mid;
  1344.   int dif;
  1345.   double atof();    /* JF know what happens if you forget this? */
  1346.  
  1347.   static did_newline = 0; /* JF the grammar insists that actions end
  1348.             with newlines. This was easier than hacking
  1349.             the grammar. */
  1350.   int do_concat;
  1351.  
  1352.   int    seen_e = 0;        /* These are for numbers */
  1353.   int    seen_point = 0;
  1354.  
  1355.   retry:
  1356.  
  1357.   if(!lexptr)
  1358.     return 0;
  1359.  
  1360.   if (want_regexp) {
  1361.     want_regexp = 0;
  1362.     /* there is a potential bug if a regexp is followed by an equal sign:
  1363.        "/foo/=bar" would result in assign_quotient being returned as the
  1364.        next token.  Nothing is done about it since it is not valid awk,
  1365.        but maybe something should be done anyway. */
  1366.  
  1367.     tokstart = lexptr;
  1368.     while (c = *lexptr++) {
  1369.       switch (c) {
  1370.       case '\\':
  1371.     if (*lexptr++ == '\0') {
  1372.       yyerror ("unterminated regexp ends with \\");
  1373.       return ERROR;
  1374.     }
  1375.     break;
  1376.       case '/':            /* end of the regexp */
  1377.     lexptr--;
  1378.     yylval.sval = tokstart;
  1379.     return REGEXP;
  1380.       case '\n':
  1381.       case '\0':
  1382.     yyerror ("unterminated regexp");
  1383.     return ERROR;
  1384.       }
  1385.     }
  1386.   }
  1387.   do_concat=want_concat_token;
  1388.   want_concat_token=0;
  1389.  
  1390.   if(*lexptr=='\0') {
  1391.     lexptr=0;
  1392.     return NEWLINE;
  1393.   }
  1394.  
  1395.   /* if lexptr is at white space between two terminal tokens or parens,
  1396.      it is a concatenation operator. */
  1397.   if(do_concat && (*lexptr==' ' || *lexptr=='\t')) {
  1398.     while (*lexptr == ' ' || *lexptr == '\t')
  1399.       lexptr++;
  1400.     if (isalnum(*lexptr) || *lexptr == '\"' || *lexptr == '('
  1401.         || *lexptr == '.' || *lexptr == '$') /* the '.' is for decimal pt */
  1402.       return CONCAT_OP;
  1403.   }
  1404.  
  1405.   while (*lexptr == ' ' || *lexptr == '\t')
  1406.     lexptr++;
  1407.  
  1408.   tokstart = lexptr;    /* JF */
  1409.  
  1410.   switch (c = *lexptr++) {
  1411.   case 0:
  1412.     return 0;
  1413.  
  1414.   case '\n':
  1415.     lineno++;
  1416.     return NEWLINE;
  1417.  
  1418.   case '#':            /* it's a comment */
  1419.     while (*lexptr != '\n' && *lexptr != '\0')
  1420.       lexptr++;
  1421.     goto retry;
  1422.  
  1423.   case '\\':
  1424.     if(*lexptr=='\n') {
  1425.       lexptr++;
  1426.       goto retry;
  1427.     } else break;
  1428.   case ')':
  1429.   case ']':
  1430.     ++want_concat_token;
  1431.     /* fall through */
  1432.   case '(':    /* JF these were above, but I don't see why they should turn on concat. . . &*/
  1433.   case '[':
  1434.  
  1435.   case '{':
  1436.   case ',':        /* JF */
  1437.   case '$':
  1438.   case ';':
  1439.   case ':':
  1440.   case '?':
  1441.     /* set node type to ILLEGAL because the action should set it to
  1442.        the right thing */
  1443.     yylval.nodetypeval = Node_illegal;
  1444.     return c;
  1445.  
  1446.   case '^':
  1447.     if (*lexptr=='=') {
  1448.       yylval.nodetypeval=Node_assign_pow;
  1449.       lexptr++;
  1450.       return ASSIGNOP;
  1451.     }
  1452.     yylval.nodetypeval=Node_illegal;
  1453.     return c;
  1454.  
  1455.   case '*':
  1456.     if(*lexptr=='=') {
  1457.       yylval.nodetypeval=Node_assign_times;
  1458.       lexptr++;
  1459.       return ASSIGNOP;
  1460.     }
  1461.     yylval.nodetypeval=Node_illegal;
  1462.     return c;
  1463.  
  1464.   case '/':
  1465.     if(*lexptr=='=') {
  1466.       yylval.nodetypeval=Node_assign_quotient;
  1467.       lexptr++;
  1468.       return ASSIGNOP;
  1469.     }
  1470.     yylval.nodetypeval=Node_illegal;
  1471.     return c;
  1472.  
  1473.   case '%':
  1474.     if(*lexptr=='=') {
  1475.       yylval.nodetypeval=Node_assign_mod;
  1476.       lexptr++;
  1477.       return ASSIGNOP;
  1478.     }
  1479.     yylval.nodetypeval=Node_illegal;
  1480.     return c;
  1481.  
  1482.   case '+':
  1483.     if(*lexptr=='=') {
  1484.       yylval.nodetypeval=Node_assign_plus;
  1485.       lexptr++;
  1486.       return ASSIGNOP;
  1487.     }
  1488.     if(*lexptr=='+') {
  1489.       yylval.nodetypeval=Node_illegal;
  1490.       lexptr++;
  1491.       return INCREMENT;
  1492.     }
  1493.     yylval.nodetypeval=Node_illegal;
  1494.     return c;
  1495.  
  1496.   case '!':
  1497.     if(*lexptr=='=') {
  1498.       yylval.nodetypeval=Node_notequal;
  1499.       lexptr++;
  1500.       return RELOP;
  1501.     }
  1502.     if(*lexptr=='~') {
  1503.       yylval.nodetypeval=Node_nomatch;
  1504.       lexptr++;
  1505.       return MATCHOP;
  1506.     }
  1507.     yylval.nodetypeval=Node_illegal;
  1508.     return c;
  1509.  
  1510.   case '<':
  1511.     if (want_redirect) {
  1512.         yylval.nodetypeval = Node_redirect_input;
  1513.         return REDIRECT_OP;
  1514.         }
  1515.     if(*lexptr=='=') {
  1516.       yylval.nodetypeval=Node_leq;
  1517.       lexptr++;
  1518.       return RELOP;
  1519.     }
  1520.     yylval.nodetypeval=Node_less;
  1521.     return RELOP;
  1522.  
  1523.   case '=':
  1524.     if(*lexptr=='=') {
  1525.       yylval.nodetypeval=Node_equal;
  1526.       lexptr++;
  1527.       return RELOP;
  1528.     }
  1529.     yylval.nodetypeval=Node_assign;
  1530.     return ASSIGNOP;
  1531.  
  1532.   case '>':
  1533.     if(want_redirect) {
  1534.       if (*lexptr == '>') {
  1535.     yylval.nodetypeval = Node_redirect_append;
  1536.     lexptr++;
  1537.       } else
  1538.         yylval.nodetypeval = Node_redirect_output;
  1539.       return REDIRECT_OP;
  1540.     }
  1541.     if(*lexptr=='=') {
  1542.       yylval.nodetypeval=Node_geq;
  1543.       lexptr++;
  1544.       return RELOP;
  1545.     }
  1546.     yylval.nodetypeval=Node_greater;
  1547.     return RELOP;
  1548.  
  1549.   case '~':
  1550.     yylval.nodetypeval=Node_match;
  1551.     return MATCHOP;
  1552.  
  1553.   case '}':
  1554.     if (did_newline)
  1555.         {
  1556.         did_newline = 0;
  1557.         return c;
  1558.         }
  1559.     did_newline++;
  1560.     --lexptr;
  1561.     return NEWLINE;
  1562.  
  1563.   case '"':
  1564.     while (*lexptr != '\0') {
  1565.       switch (*lexptr++) {
  1566.           case '\\':
  1567.             if (*lexptr++ != '\0')
  1568.               break;
  1569.         /* fall through */
  1570.           case '\n':
  1571.             yyerror ("unterminated string");
  1572.             return ERROR;
  1573.           case '\"':
  1574.             yylval.sval = tokstart + 1; /* JF Skip the doublequote */
  1575.             ++want_concat_token;
  1576.             return YSTRING;
  1577.       }
  1578.     }
  1579.     return ERROR;    /* JF this was one level up, wrong? */
  1580.  
  1581.   case '-':
  1582.     if(*lexptr=='=') {
  1583.       yylval.nodetypeval=Node_assign_minus;
  1584.       lexptr++;
  1585.       return ASSIGNOP;
  1586.     }
  1587.     if(*lexptr=='-') {
  1588.       yylval.nodetypeval=Node_illegal;
  1589.       lexptr++;
  1590.       return DECREMENT;
  1591.     }
  1592.     /* JF I think space tab comma and newline are the legal places for
  1593.        a UMINUS.  Have I missed any? */
  1594.     if((!isdigit(*lexptr) && *lexptr!='.') || (lexptr>lexptr_begin+1 &&
  1595.  !index(" \t,\n",lexptr[-2]))) {
  1596.     /* set node type to ILLEGAL because the action should set it to
  1597.        the right thing */
  1598.       yylval.nodetypeval = Node_illegal;
  1599.       return c;
  1600.     }
  1601.       /* FALL through into number code */
  1602.   case '0':
  1603.   case '1':
  1604.   case '2':
  1605.   case '3':
  1606.   case '4':
  1607.   case '5':
  1608.   case '6':
  1609.   case '7':
  1610.   case '8':
  1611.   case '9':
  1612.   case '.':
  1613.     /* It's a number */
  1614.     if(c=='-') namelen=1;
  1615.     else namelen=0;
  1616.     for (; (c = tokstart[namelen]) != '\0'; namelen++) {
  1617.       switch (c) {
  1618.       case '.':
  1619.     if (seen_point)
  1620.       goto got_number;
  1621.     ++seen_point;
  1622.     break;
  1623.       case 'e':
  1624.       case 'E':
  1625.     if (seen_e)
  1626.       goto got_number;
  1627.     ++seen_e;
  1628.     if (tokstart[namelen+1] == '-' || tokstart[namelen+1] == '+')
  1629.       namelen++;
  1630.     break;
  1631.       case '0': case '1': case '2': case '3': case '4':
  1632.       case '5': case '6': case '7': case '8': case '9':
  1633.     break;
  1634.       default:
  1635.     goto got_number;
  1636.       }
  1637.     }
  1638.  
  1639. /*
  1640. ** There seems to be a bug (feature?) in the Microsoft Large Model
  1641. ** atof function.  If the string to convert is too long, atof returns a
  1642. ** zero without bothering to scan the string.  The following hack simply
  1643. ** truncates tokstart for the duration of the call. -ADE-
  1644. **/
  1645.  
  1646. got_number:
  1647.     lexptr = tokstart + namelen;
  1648.     *lexptr = '\0';
  1649.     yylval.fval = atof(tokstart);
  1650.     *lexptr = c;
  1651.     ++want_concat_token;
  1652.     return NUMBER;
  1653.  
  1654.   case '&':
  1655.     if(*lexptr=='&') {
  1656.       yylval.nodetypeval=Node_and;
  1657.       lexptr++;
  1658.       return LEX_AND;
  1659.     }
  1660.     return ERROR;
  1661.  
  1662.   case '|':
  1663.     if(want_redirect) {
  1664.       lexptr++;
  1665.       yylval.nodetypeval = Node_redirect_pipe;
  1666.       return REDIRECT_OP;
  1667.     }
  1668.     if(*lexptr=='|') {
  1669.       yylval.nodetypeval=Node_or;
  1670.       lexptr++;
  1671.       return LEX_OR;
  1672.     }
  1673.     return ERROR;
  1674.   }
  1675.  
  1676.   if (!(is_identchar(c))) {
  1677.     yyerror ("Invalid char '%c' in expression\n", c);
  1678.     return ERROR;
  1679.   }
  1680.  
  1681.   /* its some type of name-type-thing.  Find its length */
  1682.   for (namelen = 0; is_identchar(tokstart[namelen]); namelen++)
  1683.     ;
  1684.  
  1685.  
  1686.   /* See if it is a special token.    */
  1687.  
  1688.   low = tokentab;
  1689.   high = END(tokentab);
  1690.   while (low <= high)
  1691.     {
  1692.     mid = low + (high-low)/2;
  1693.     if(!(dif = strncmp(tokstart,mid->operator,namelen)) &&
  1694.        *tokstart==mid->operator[0] && mid->operator[namelen]=='\0')
  1695.       {
  1696.       lexptr=tokstart+namelen;
  1697.       if(mid->class == LEX_BUILTIN || mid->class == LEX_SUB)
  1698.         yylval.ptrval = mid->ptr;
  1699.       else
  1700.         yylval.nodetypeval = mid->value;
  1701.       return mid->class;
  1702.       }
  1703.     else if (dif > 0)
  1704.       low = mid+1;
  1705.     else
  1706.       high = mid-1;
  1707.     }
  1708.  
  1709. /*    for (toktab = tokentab; toktab->operator != NULL; toktab++) {
  1710. **      if(*tokstart==toktab->operator[0] &&
  1711. **         !strncmp(tokstart,toktab->operator,namelen) &&
  1712. **         toktab->operator[namelen]=='\0') {
  1713. **        lexptr=tokstart+namelen;
  1714. **        if(toktab->class == LEX_BUILTIN || toktab->class == LEX_SUB)
  1715. **          yylval.ptrval = toktab->ptr;
  1716. **        else
  1717. **          lexptr=tokstart+namelen;
  1718. **        if(toktab->class == LEX_BUILTIN || toktab->class == LEX_SUB)
  1719. **          yylval.ptrval = toktab->ptr;
  1720. **        else
  1721. **          yylval.nodetypeval = toktab->value;
  1722. **        return toktab->class;
  1723. **      }
  1724. **    }
  1725. /*
  1726.   /* It's a name.  See how long it is.  */
  1727.   yylval.sval = tokstart;
  1728.   lexptr = tokstart+namelen;
  1729.   ++want_concat_token;
  1730.   return NAME;
  1731. }
  1732.  
  1733. /*VARARGS1*/
  1734. void
  1735. yyerror (mesg,a1,a2,a3,a4,a5,a6,a7,a8)
  1736.      char *mesg;
  1737. {
  1738.   register char *ptr,*beg;
  1739.  
  1740.     /* Find the current line in the input file */
  1741.   if(!lexptr) {
  1742.     beg="(END OF FILE)";
  1743.     ptr=beg+13;
  1744.   } else {
  1745.     if (*lexptr == '\n' && lexptr!=lexptr_begin)
  1746.       --lexptr;
  1747.     for (beg = lexptr;beg!=lexptr_begin && *beg != '\n';--beg)
  1748.       ;
  1749.     for (ptr = lexptr;*ptr && *ptr != '\n';ptr++) /*jfw: NL isn't guaranteed*/
  1750.       ;
  1751.     if(beg!=lexptr_begin)
  1752.       beg++;
  1753.   }
  1754.   fprintf (stderr, "Error near line %d,  '%.*s'\n",lineno, ptr-beg, beg);
  1755.   /* figure out line number, etc. later */
  1756.   fprintf (stderr, mesg, a1, a2, a3, a4, a5, a6, a7, a8);
  1757.   fprintf (stderr,"\n");
  1758.   exit (1);
  1759. }
  1760.  
  1761. /* Parse a C escape sequence.  STRING_PTR points to a variable
  1762.    containing a pointer to the string to parse.  That pointer
  1763.    is updated past the characters we use.  The value of the
  1764.    escape sequence is returned.
  1765.  
  1766.    A negative value means the sequence \ newline was seen,
  1767.    which is supposed to be equivalent to nothing at all.
  1768.  
  1769.    If \ is followed by a null character, we return a negative
  1770.    value and leave the string pointer pointing at the null character.
  1771.  
  1772.    If \ is followed by 000, we return 0 and leave the string pointer
  1773.    after the zeros.  A value of 0 does not mean end of string.  */
  1774.  
  1775. static int
  1776. parse_escape (string_ptr)
  1777.      char **string_ptr;
  1778. {
  1779.   register int c = *(*string_ptr)++;
  1780.   switch (c)
  1781.     {
  1782.     case 'a':
  1783.       return '\a';
  1784.     case 'b':
  1785.       return '\b';
  1786.     case 'e':
  1787.       return 033;
  1788.     case 'f':
  1789.       return '\f';
  1790.     case 'n':
  1791.       return '\n';
  1792.     case 'r':
  1793.       return '\r';
  1794.     case 't':
  1795.       return '\t';
  1796.     case 'v':
  1797.       return '\v';
  1798.     case '\n':
  1799.       return -2;
  1800.     case 0:
  1801.       (*string_ptr)--;
  1802.       return 0;
  1803.     case '^':
  1804.       c = *(*string_ptr)++;
  1805.       if (c == '\\')
  1806.     c = parse_escape (string_ptr);
  1807.       if (c == '?')
  1808.     return 0177;
  1809.       return (c & 0200) | (c & 037);
  1810.  
  1811.     case '0':
  1812.     case '1':
  1813.     case '2':
  1814.     case '3':
  1815.     case '4':
  1816.     case '5':
  1817.     case '6':
  1818.     case '7':
  1819.       {
  1820.     register int i = c - '0';
  1821.     register int count = 0;
  1822.     while (++count < 3)
  1823.       {
  1824.         if ((c = *(*string_ptr)++) >= '0' && c <= '7')
  1825.           {
  1826.         i *= 8;
  1827.         i += c - '0';
  1828.           }
  1829.         else
  1830.           {
  1831.         (*string_ptr)--;
  1832.         break;
  1833.           }
  1834.       }
  1835.     return i;
  1836.       }
  1837.     default:
  1838.       return c;
  1839.     }
  1840. }
  1841.