📄 parser.cpp
字号:
/* A Bison parser, made from parser.y
by GNU Bison version 1.28 */
#define YYBISON 1 /* Identify Bison output. */
#define LEX_ERROR 257
#define FOO 258
#define BARE_HTML 259
#define BARE_HTML_EOF 260
#define HTML_AND_PRINT 261
#define IDENT 262
#define OBJECT_IDENT 263
#define NUMBER 264
#define _FLOAT 265
#define STRING 266
#define IF 267
#define THEN 268
#define ELSE 269
#define ALL 270
#define END 271
#define PRINT 272
#define PRINTLN 273
#define GRID 274
#define WHILE 275
#define BREAK 276
#define CONTINUE 277
#define FOR 278
#define TO 279
#define K_RETURN 280
#define FUNCTION 281
#define K_NULL 282
#define INCLUDE 283
#define JUMP 284
#define LOCAL 285
#define AS 286
#define FOREACH 287
#define MIN 288
#define MAX 289
#define LOWER_THAN_ELSE 290
#define ELSEIF 291
#define EQL 292
#define OR 293
#define AND 294
#define EQ 295
#define NE 296
#define LE 297
#define GE 298
#define NOT 299
#define UNOT 300
#define COMPARE 301
#define HIGHER_THAN_EXPRESSION 302
#define UMINUS 303
#define K_NEW 304
///////////////////////////////////////////////////////////////////////////////
// $Header: /shorthand/src/parser.cpp 7 2/08/03 6:40a Arm $
//-----------------------------------------------------------------------------
// Project: ShortHand interpreter
// Author: Andrei Remenchuk <andrei@remenchuk.com>
//-----------------------------------------------------------------------------
// parsery.y: ShortHand grammar
///////////////////////////////////////////////////////////////////////////////
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#ifdef WIN32
#include <windows.h>
#endif
#include "shorthand.h"
#include "yydef.h"
#include "module.h"
#include "nodes.h"
//
// parser_module is a pointer to the ShhModule object passed as parameter
// to yyparse() function
//
#define MODULE ((ShhModule*)parser_module)
// we redefined yylex() as module's method instead of stanalone function
#define yylex MODULE->module_yylex
#define yyerror MODULE->module_yyerror
// this defines lexer object
#define LEXER MODULE->m_lexer
// macros for constructing AST nodes
#define NEW0(T) (T*) MODULE->include(new T())
#define NEW(T,arg1) (T*) MODULE->include(new T(arg1))
#define NEW2(T,arg1,arg2) (T*) MODULE->include(new T(arg1,arg2))
#define NEW3(T,arg1,arg2,arg3) (T*) MODULE->include(new T(arg1,arg2,arg3))
#define NEW4(T,arg1,arg2,arg3,arg4) (T*) MODULE->include(new T(arg1,arg2,arg3,arg4))
typedef union {
int num;
double fnum;
const char* str;
ShhVariable* var;
ShhExecutable* exec;
ShhExpression* exp;
ShhPredicate* pred;
ShhBatch* batch;
ShhQualifier* qualifier;
ShhExpressionList* explist;
ShhFunctionCall* call;
ShhParameterList* params;
} YYSTYPE;
#include <stdio.h>
#ifndef __cplusplus
#ifndef __STDC__
#define const
#endif
#endif
#define YYFINAL 197
#define YYFLAG -32768
#define YYNTBASE 71
#define YYTRANSLATE(x) ((unsigned)(x) <= 304 ? yytranslate[x] : 90)
static const char yytranslate[] = { 0,
2, 2, 2, 2, 2, 2, 2, 2, 2, 69,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 58, 2, 2, 2, 55, 52, 2, 66,
68, 56, 53, 70, 54, 60, 57, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 67, 45,
49, 46, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
62, 2, 63, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 64, 2, 65, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 1, 3, 4, 5, 6,
7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
37, 38, 39, 40, 41, 42, 43, 44, 47, 48,
50, 51, 59, 61
};
#if YYDEBUG != 0
static const short yyprhs[] = { 0,
0, 2, 3, 5, 7, 9, 11, 13, 15, 18,
20, 23, 25, 27, 29, 31, 35, 42, 45, 48,
51, 54, 56, 65, 68, 70, 73, 75, 78, 80,
84, 86, 90, 95, 103, 113, 125, 131, 141, 149,
159, 160, 162, 164, 168, 169, 171, 173, 177, 179,
181, 183, 185, 190, 192, 196, 203, 207, 211, 215,
219, 223, 227, 230, 234, 237, 240, 245, 250, 254,
258, 262, 266, 270, 274, 278, 282, 286, 289, 291,
297, 302, 305, 310
};
static const short yyrhs[] = { 72,
0, 0, 74, 0, 77, 0, 76, 0, 75, 0,
67, 0, 73, 0, 74, 73, 0, 5, 0, 7,
86, 0, 88, 0, 81, 0, 22, 0, 23, 0,
86, 49, 86, 0, 86, 60, 8, 66, 82, 68,
0, 18, 86, 0, 19, 86, 0, 29, 86, 0,
30, 86, 0, 80, 0, 27, 8, 66, 84, 68,
74, 17, 27, 0, 26, 86, 0, 26, 0, 31,
79, 0, 69, 0, 77, 69, 0, 8, 0, 8,
49, 86, 0, 78, 0, 79, 70, 78, 0, 8,
66, 82, 68, 0, 20, 66, 8, 68, 74, 17,
20, 0, 20, 66, 8, 70, 86, 68, 74, 17,
20, 0, 20, 66, 8, 70, 86, 70, 86, 68,
74, 17, 20, 0, 21, 87, 74, 17, 21, 0,
24, 8, 49, 86, 25, 86, 74, 17, 24, 0,
33, 86, 32, 86, 74, 17, 24, 0, 33, 86,
32, 86, 38, 86, 74, 17, 24, 0, 0, 85,
0, 8, 0, 83, 70, 8, 0, 0, 83, 0,
86, 0, 85, 70, 86, 0, 10, 0, 11, 0,
28, 0, 12, 0, 8, 66, 82, 68, 0, 8,
0, 86, 60, 8, 0, 86, 60, 8, 66, 82,
68, 0, 66, 86, 68, 0, 86, 53, 86, 0,
86, 54, 86, 0, 86, 56, 86, 0, 86, 57,
86, 0, 86, 55, 86, 0, 54, 86, 0, 86,
52, 86, 0, 61, 9, 0, 61, 80, 0, 86,
62, 86, 63, 0, 86, 64, 86, 65, 0, 86,
45, 86, 0, 86, 46, 86, 0, 86, 49, 86,
0, 86, 43, 86, 0, 86, 44, 86, 0, 86,
42, 86, 0, 66, 87, 68, 0, 87, 40, 87,
0, 87, 39, 87, 0, 47, 87, 0, 86, 0,
13, 87, 14, 74, 89, 0, 13, 87, 14, 89,
0, 17, 13, 0, 15, 74, 17, 13, 0, 37,
87, 14, 74, 89, 0
};
#endif
#if YYDEBUG != 0
static const short yyrline[] = { 0,
134, 157, 159, 164, 167, 170, 173, 179, 182, 188,
191, 199, 202, 205, 208, 211, 217, 220, 223, 226,
229, 232, 235, 238, 241, 244, 251, 252, 256, 259,
264, 266, 271, 275, 278, 281, 284, 287, 290, 293,
300, 302, 307, 309, 313, 315, 319, 321, 326, 329,
332, 335, 338, 341, 344, 347, 350, 353, 356, 359,
362, 365, 368, 371, 374, 377, 380, 383, 388, 391,
394, 397, 400, 403, 406, 409, 412, 415, 418, 422,
424, 428, 430, 432
};
#endif
#define YYNTOKENS 71
#define YYNNTS 19
#define YYNRULES 84
#define YYNSTATES 198
#define YYMAXUTOK 304
static const char * const yytname[] = { "$","error","$undefined.","LEX_ERROR",
"FOO","BARE_HTML","BARE_HTML_EOF","HTML_AND_PRINT","IDENT","OBJECT_IDENT","NUMBER",
"_FLOAT","STRING","IF","THEN","ELSE","ALL","END","PRINT","PRINTLN","GRID","WHILE",
"BREAK","CONTINUE","FOR","TO","K_RETURN","FUNCTION","K_NULL","INCLUDE","JUMP",
"LOCAL","AS","FOREACH","MIN","MAX","LOWER_THAN_ELSE","ELSEIF","EQL","OR","AND",
"EQ","NE","LE","GE","'<'","'>'","NOT","UNOT","'='","COMPARE","HIGHER_THAN_EXPRESSION",
"'&'","'+'","'-'","'%'","'*'","'/'","'!'","UMINUS","'.'","K_NEW","'['","']'",
"'{'","'}'","'('","';'","')'","'\\n'","','","input","content","subst","statements",
"super_statement","statement","newlines","local","locals","call","loop","arguments",
"paramlist","params","arglist","expression","condition","if_block","else_block", NULL
};
static const short yytoknum[] = { 0,
256, 2, 257, 258, 259, 260, 261, 262, 263, 264,
265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
275, 276, 277, 278, 279, 280, 281, 282, 283, 284,
285, 286, 287, 288, 289, 290, 291, 292, 293, 294,
295, 296, 297, 298, 60, 62, 299, 300, 61, 301,
302, 38, 43, 45, 37, 42, 47, 33, 303, 46,
304, 91, 93, 123, 125, 40, 59, 41, 10, 44,
0
};
static const short yyr1[] = { 0,
71, 72, 72, 73, 73, 73, 73, 74, 74, 75,
75, 76, 76, 76, 76, 76, 76, 76, 76, 76,
76, 76, 76, 76, 76, 76, 77, 77, 78, 78,
79, 79, 80, 81, 81, 81, 81, 81, 81, 81,
82, 82, 83, 83, 84, 84, 85, 85, 86, 86,
86, 86, 86, 86, 86, 86, 86, 86, 86, 86,
86, 86, 86, 86, 86, 86, 86, 86, 87, 87,
87, 87, 87, 87, 87, 87, 87, 87, 87, 88,
88, 89, 89, 89
};
static const short yyr2[] = { 0,
1, 0, 1, 1, 1, 1, 1, 1, 2, 1,
2, 1, 1, 1, 1, 3, 6, 2, 2, 2,
2, 1, 8, 2, 1, 2, 1, 2, 1, 3,
1, 3, 4, 7, 9, 11, 5, 9, 7, 9,
0, 1, 1, 3, 0, 1, 1, 3, 1, 1,
1, 1, 4, 1, 3, 6, 3, 3, 3, 3,
3, 3, 2, 3, 2, 2, 4, 4, 3, 3,
3, 3, 3, 3, 3, 3, 3, 2, 1, 5,
4, 2, 4, 5
};
static const short yydefact[] = { 2,
10, 0, 54, 49, 50, 52, 0, 0, 0, 0,
0, 14, 15, 0, 25, 0, 51, 0, 0, 0,
0, 0, 0, 0, 7, 27, 1, 8, 3, 6,
5, 4, 22, 13, 0, 12, 54, 11, 41, 0,
0, 79, 0, 18, 19, 0, 0, 0, 24, 0,
20, 21, 29, 31, 26, 0, 63, 0, 65, 66,
0, 9, 28, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 41, 0, 0, 42, 47, 78, 79,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 45, 0, 0, 0, 41, 57, 16,
64, 58, 59, 62, 60, 61, 55, 0, 0, 0,
55, 33, 0, 75, 74, 72, 73, 69, 70, 71,
0, 0, 0, 0, 81, 77, 76, 0, 0, 0,
0, 43, 46, 0, 30, 32, 0, 0, 41, 67,
68, 53, 41, 48, 0, 82, 0, 80, 0, 0,
37, 0, 0, 0, 0, 0, 0, 33, 0, 0,
0, 0, 0, 0, 0, 0, 44, 0, 0, 59,
0, 17, 56, 83, 0, 34, 0, 0, 0, 0,
0, 39, 84, 0, 0, 0, 23, 0, 35, 0,
38, 40, 0, 36, 0, 0, 0
};
static const short yydefgoto[] = { 195,
27, 28, 29, 30, 31, 32, 54, 55, 33, 34,
76, 133, 134, 77, 35, 43, 36, 125
};
static const short yypact[] = { 809,
-32768, 49, -58,-32768,-32768,-32768, 840, 49, 49, -54,
840,-32768,-32768, 10, 49, 34,-32768, 49, 49, 40,
49, 49, 36, 49,-32768,-32768,-32768,-32768, 809,-32768,
-32768, -20,-32768,-32768, 158,-32768, -16, 828, 49, 840,
840, 892, 7, 828, 828, 43, 349, 5, 828, 3,
828, 828, 25,-32768, 6, -29, -28, 9,-32768,-32768,
338,-32768,-32768, 49, 49, 49, 49, 49, 49, 49,
70, 49, 49, 49, 71, 18, 22, 828,-32768, 865,
-25, 49, 49, 49, 49, 49, 49, 297, 840, 840,
-66, 412, 49, 89, 49, 40, 49, 49,-32768, 828,
904, 512, 512, 604, -28, -28, 38, 802, 708, 32,
47, 526, 49,-32768, 828, 828, 828, 828, 828, 828,
809, 93, 840, 297,-32768, 62,-32768, 809, 49, 96,
218,-32768, 48, 51, 828,-32768, 171, 54, 49,-32768,
-32768,-32768, 49, 828, 441,-32768, 16,-32768, 504, 285,
-32768, 49, 112, 809, 49, 49, 533,-32768, 56, 57,
115, 809, 109, 809, 49, 234,-32768, 596, 234, 52,
107, 618,-32768,-32768, 297,-32768, 625, 430, 688, 106,
717,-32768,-32768, 114, 809, 111,-32768, 116,-32768, 780,
-32768,-32768, 122,-32768, 136, 143,-32768
};
static const short yypgoto[] = {-32768,
-32768, -19, 11,-32768,-32768,-32768, 50,-32768, 121,-32768,
-45,-32768,-32768,-32768, -2, 0,-32768, -123
};
#define YYLAST 968
static const short yytable[] = { 38,
148, 128, 97, 129, 42, 44, 45, 39, 42, 62,
47, 46, 49, 89, 90, 51, 52, 48, 56, 57,
88, 61, 65, 66, 67, 68, 69, 70, 110, 162,
75, 75, 72, 72, 73, 73, 78, 42, 80, 79,
81, 50, 114, 58, 59, 89, 90, 53, 63, 74,
91, 183, 138, 93, 89, 90, 37, 92, 4, 5,
6, 100, 101, 102, 103, 104, 105, 106, 94, 108,
109, 78, 62, 95, 98, 96, 17, 107, 111, 115,
116, 117, 118, 119, 120, 112, 42, 42, 126, 127,
131, 113, 135, 159, 137, 78, 132, 160, 124, 142,
-63, 90, 22, 139, 62, 146, -63, -63, -63, 23,
144, 75, 143, 72, 24, 73, 151, 153, 154, 167,
42, 158, 147, 172, 173, 62, 150, 174, 176, 62,
182, 145, 187, 189, 191, 196, 78, 62, 149, 192,
78, 194, 197, 60, 0, 136, 0, 157, 62, 166,
0, 0, 169, 170, 0, 62, 0, 62, 0, 62,
0, 62, 178, 0, 168, 0, 0, 0, 0, 0,
62, 0, 175, 0, 177, 1, 179, 2, 3, 181,
4, 5, 6, 7, 0, 0, 0, 0, 8, 9,
10, 11, 12, 13, 14, 190, 15, 16, 17, 18,
19, 20, 0, 21, 0, 0, 64, 0, 155, 65,
66, 67, 68, 69, 70, 0, 0, 71, 0, 72,
0, 73, 65, 66, 156, 68, 69, 70, 0, 0,
75, 23, 72, 0, 73, 0, 24, 25, 1, 26,
2, 3, 152, 4, 5, 6, 7, 0, 0, 0,
0, 8, 9, 10, 11, 12, 13, 14, 0, 15,
16, 17, 18, 19, 20, 0, 21, 0, 0, 65,
66, 67, 68, 69, 70, 0, 0, 75, 0, 72,
0, 73, 0, 0, 0, 65, 66, 156, 68, 69,
70, 0, 0, 75, 23, 72, 0, 73, 0, 24,
25, 1, 26, 2, 3, 0, 4, 5, 6, 7,
0, 121, 0, 122, 8, 9, 10, 11, 12, 13,
14, 0, 15, 16, 17, 18, 19, 20, 0, 21,
0, 0, 0, 123, 0, 0, 65, 66, 67, 68,
69, 70, 0, 0, 75, 0, 72, 0, 73, 0,
22, 0, 164, 1, 165, 2, 3, 23, 4, 5,
6, 7, 24, 25, 0, 26, 8, 9, 10, 11,
12, 13, 14, 0, 15, 16, 17, 18, 19, 20,
0, 21, 0, 0, 0, 0, 0, 89, 90, 65,
66, 67, 68, 69, 70, 0, 0, 75, 0, 72,
0, 73, 22, 0, 0, 99, 0, 0, 0, 23,
0, 0, 0, 0, 24, 25, 1, 26, 2, 3,
0, 4, 5, 6, 7, 0, 0, 0, 130, 8,
9, 10, 11, 12, 13, 14, 0, 15, 16, 17,
18, 19, 20, 0, 21, 1, 0, 2, 3, 0,
4, 5, 6, 7, 0, 0, 0, 161, 8, 9,
10, 11, 12, 13, 14, 22, 15, 16, 17, 18,
19, 20, 23, 21, 0, 0, 0, 24, 25, 0,
26, 65, 66, 67, 68, 69, 70, 0, 0, 75,
0, 72, 0, 73, 22, 0, 0, 185, 0, 0,
0, 23, 0, 0, 0, 0, 24, 25, 1, 26,
2, 3, 0, 4, 5, 6, 7, 0, 0, 0,
163, 8, 9, 10, 11, 12, 13, 14, 0, 15,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -