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

📄 ctkparser.cpp

📁 C-Talk is interpreted scripting language with C-like syntax and dynamic type checking. Variables in
💻 CPP
📖 第 1 页 / 共 4 页
字号:

/*  A Bison parser, made from parser.y with Bison version GNU Bison version 1.24
  */

#define YYBISON 1  /* Identify Bison output.  */

#define	BREAK	258
#define	CASE	259
#define	CATCH	260
#define	CONTINUE	261
#define	DEFAULT	262
#define	DO	263
#define	ELSE	264
#define	FOR	265
#define	FUNCTION	266
#define	IDENT	267
#define	IF	268
#define	IMPORT	269
#define	NULLLITERAL	270
#define	PAR	271
#define	RETURN	272
#define	THROW	273
#define	TRY	274
#define	SYNCHRONIZED	275
#define	SWITCH	276
#define	WHILE	277
#define	ILITERAL	278
#define	RLITERAL	279
#define	SLITERAL	280
#define	SET_ADD	281
#define	SET_SUB	282
#define	SET_DIV	283
#define	SET_MOD	284
#define	SET_MUL	285
#define	SET_AND	286
#define	SET_OR	287
#define	SET_XOR	288
#define	SET_SHL	289
#define	SET_SHR	290
#define	LOR	291
#define	LAND	292
#define	EQ	293
#define	NE	294
#define	LE	295
#define	GE	296
#define	SHL	297
#define	SHR	298
#define	UPLUS	299
#define	UMINUS	300
#define	INC	301
#define	DEC	302

#line 1 "parser.y"


#include "compiler.h"
#include <malloc.h>

void yyerror(char* msg) 
{
    CtkScanner::instance.error(msg);
}


#line 14 "parser.y"
typedef union {
    CtkToken*         tok;
    CtkProgram*       prog;
    CtkTokenList*     toks;
    CtkStmt*          stmt;
    CtkExpr*          expr;
    CtkCaseStmt*      cass;
    CtkArrayElemExpr* pair;
    ctk_integer       ival;
    ctk_real          rval;
    char*             sval;  
} YYSTYPE;

#ifndef YYLTYPE
typedef
  struct yyltype
    {
      int timestamp;
      int first_line;
      int first_column;
      int last_line;
      int last_column;
      char *text;
   }
  yyltype;

#define YYLTYPE yyltype
#endif

#include <stdio.h>

#ifndef __cplusplus
#ifndef __STDC__
#define const
#endif
#endif



#define	YYFINAL		225
#define	YYFLAG		-32768
#define	YYNTBASE	73

#define YYTRANSLATE(x) ((unsigned)(x) <= 302 ? yytranslate[x] : 106)

static const char yytranslate[] = {     0,
     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,    65,     2,     2,    67,    60,    49,     2,    70,
    25,    61,    58,    23,    59,    72,    62,     2,     2,     2,
     2,     2,     2,     2,     2,     2,     2,    44,    24,    52,
    32,    54,    43,     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,
    71,     2,    26,    48,     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,    27,    47,    28,    66,     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,     2,     3,     4,     5,
     6,     7,     8,     9,    10,    11,    12,    13,    14,    15,
    16,    17,    18,    19,    20,    21,    22,    29,    30,    31,
    33,    34,    35,    36,    37,    38,    39,    40,    41,    42,
    45,    46,    50,    51,    53,    55,    56,    57,    63,    64,
    68,    69
};

#if YYDEBUG != 0
static const short yyprhs[] = {     0,
     0,     3,     4,     8,     9,    12,    14,    16,    18,    20,
    22,    24,    26,    28,    30,    32,    34,    36,    38,    40,
    42,    49,    50,    52,    54,    58,    65,    66,    69,    79,
    80,    82,    90,    96,   104,   105,   108,   113,   117,   120,
   123,   126,   130,   134,   142,   146,   149,   151,   157,   159,
   163,   167,   171,   175,   179,   183,   187,   191,   195,   199,
   203,   207,   211,   215,   219,   223,   227,   231,   235,   239,
   243,   247,   251,   255,   259,   263,   267,   271,   275,   281,
   287,   289,   291,   295,   298,   301,   304,   307,   310,   313,
   316,   319,   322,   326,   331,   336,   340,   341,   343,   345,
   349,   353,   355,   357,   359,   361,   363,   364,   366,   368
};

static const short yyrhs[] = {    74,
    75,     0,     0,    14,    78,    24,     0,     0,    76,    75,
     0,    77,     0,    80,     0,    82,     0,    84,     0,    85,
     0,    86,     0,    89,     0,    90,     0,    97,     0,    91,
     0,    92,     0,    93,     0,    94,     0,    95,     0,    96,
     0,    11,    12,    70,    78,    25,    94,     0,     0,    79,
     0,    12,     0,    12,    23,    79,     0,    13,    70,    98,
    25,    76,    81,     0,     0,     9,    76,     0,    10,    70,
    83,    24,    83,    24,    83,    25,    76,     0,     0,    98,
     0,     8,    76,    22,    70,    98,    25,    24,     0,    22,
    70,    98,    25,    76,     0,    21,    70,    98,    25,    27,
    87,    28,     0,     0,    88,    87,     0,     4,    98,    44,
    76,     0,     7,    44,    76,     0,     6,    24,     0,     3,
    24,     0,    17,    24,     0,    17,    98,    24,     0,    18,
    98,    24,     0,    19,    76,     5,    70,    12,    25,    76,
     0,    27,    75,    28,     0,    98,    24,     0,    24,     0,
    20,    70,    98,    25,    76,     0,    99,     0,    98,    58,
    98,     0,    98,    59,    98,     0,    98,    62,    98,     0,
    98,    60,    98,     0,    98,    61,    98,     0,    98,    47,
    98,     0,    98,    49,    98,     0,    98,    48,    98,     0,
    98,    56,    98,     0,    98,    57,    98,     0,    98,    50,
    98,     0,    98,    51,    98,     0,    98,    54,    98,     0,
    98,    55,    98,     0,    98,    52,    98,     0,    98,    53,
    98,     0,    98,    46,    98,     0,    98,    45,    98,     0,
    98,    32,    98,     0,    98,    33,    98,     0,    98,    34,
    98,     0,    98,    35,    98,     0,    98,    36,    98,     0,
    98,    37,    98,     0,    98,    39,    98,     0,    98,    40,
    98,     0,    98,    38,    98,     0,    98,    41,    98,     0,
    98,    42,    98,     0,    98,    43,    98,    44,    98,     0,
    16,    99,    70,   104,    25,     0,    12,     0,   103,     0,
    70,    98,    25,     0,    58,    99,     0,    59,    99,     0,
    69,    99,     0,    68,    99,     0,    99,    69,     0,    99,
    68,     0,    65,    99,     0,    66,    99,     0,    67,    99,
     0,    71,   100,    26,     0,    99,    70,   104,    25,     0,
    99,    71,    98,    26,     0,    99,    72,    12,     0,     0,
   101,     0,   102,     0,   102,    23,   100,     0,    98,    44,
    98,     0,    98,     0,    31,     0,    29,     0,    30,     0,
    15,     0,     0,   105,     0,    98,     0,    98,    23,   105,
     0
};

#endif

#if YYDEBUG != 0
static const short yyrline[] = { 0,
   120,   125,   125,   127,   127,   129,   129,   129,   129,   129,
   130,   130,   130,   130,   131,   131,   131,   131,   131,   131,
   133,   137,   137,   139,   140,   142,   146,   146,   148,   152,
   152,   154,   158,   162,   166,   166,   168,   171,   175,   179,
   183,   186,   190,   194,   198,   200,   202,   204,   208,   209,
   210,   211,   212,   213,   214,   215,   216,   217,   218,   220,
   221,   222,   223,   224,   225,   227,   228,   230,   231,   232,
   233,   234,   235,   236,   237,   238,   239,   240,   241,   242,
   244,   245,   246,   247,   248,   249,   250,   251,   252,   253,
   254,   255,   256,   257,   258,   259,   263,   263,   265,   266,
   268,   269,   271,   272,   273,   274,   276,   276,   278,   279
};

static const char * const yytname[] = {   "$","error","$undefined.","BREAK",
"CASE","CATCH","CONTINUE","DEFAULT","DO","ELSE","FOR","FUNCTION","IDENT","IF",
"IMPORT","NULLLITERAL","PAR","RETURN","THROW","TRY","SYNCHRONIZED","SWITCH",
"WHILE","','","';'","')'","']'","'{'","'}'","ILITERAL","RLITERAL","SLITERAL",
"'='","SET_ADD","SET_SUB","SET_DIV","SET_MOD","SET_MUL","SET_AND","SET_OR","SET_XOR",
"SET_SHL","SET_SHR","'?'","':'","LOR","LAND","'|'","'^'","'&'","EQ","NE","'<'",
"LE","'>'","GE","SHL","SHR","'+'","'-'","'%'","'*'","'/'","UPLUS","UMINUS","'!'",
"'~'","'$'","INC","DEC","'('","'['","'.'","program","import_list","statements",
"stmt","func_def_stmt","ident_list","not_empty_ident_list","if_stmt","else_branch",
"for_stmt","opt_expr","do_while_stmt","while_stmt","switch_stmt","case_node_list",
"case_node","continue_stmt","break_stmt","return_stmt","throw_stmt","try_stmt",
"block","expr_stmt","empty_stmt","sync_stmt","expr","unary_expr","array_initializer_list",
"not_empty_array_initializer_list","array_initializer","literal","expr_list",
"not_empty_expr_list",""
};
#endif

static const short yyr1[] = {     0,
    73,    74,    74,    75,    75,    76,    76,    76,    76,    76,
    76,    76,    76,    76,    76,    76,    76,    76,    76,    76,
    77,    78,    78,    79,    79,    80,    81,    81,    82,    83,
    83,    84,    85,    86,    87,    87,    88,    88,    89,    90,
    91,    91,    92,    93,    94,    95,    96,    97,    98,    98,
    98,    98,    98,    98,    98,    98,    98,    98,    98,    98,
    98,    98,    98,    98,    98,    98,    98,    98,    98,    98,
    98,    98,    98,    98,    98,    98,    98,    98,    98,    98,
    99,    99,    99,    99,    99,    99,    99,    99,    99,    99,
    99,    99,    99,    99,    99,    99,   100,   100,   101,   101,
   102,   102,   103,   103,   103,   103,   104,   104,   105,   105
};

static const short yyr2[] = {     0,
     2,     0,     3,     0,     2,     1,     1,     1,     1,     1,
     1,     1,     1,     1,     1,     1,     1,     1,     1,     1,
     6,     0,     1,     1,     3,     6,     0,     2,     9,     0,
     1,     7,     5,     7,     0,     2,     4,     3,     2,     2,
     2,     3,     3,     7,     3,     2,     1,     5,     1,     3,
     3,     3,     3,     3,     3,     3,     3,     3,     3,     3,
     3,     3,     3,     3,     3,     3,     3,     3,     3,     3,
     3,     3,     3,     3,     3,     3,     3,     3,     5,     5,
     1,     1,     3,     2,     2,     2,     2,     2,     2,     2,
     2,     2,     3,     4,     4,     3,     0,     1,     1,     3,
     3,     1,     1,     1,     1,     1,     0,     1,     1,     3
};

static const short yydefact[] = {     2,
    22,     4,    24,     0,    23,     0,     0,     0,     0,     0,
    81,     0,   106,     0,     0,     0,     0,     0,     0,     0,
    47,     4,   104,   105,   103,     0,     0,     0,     0,     0,
     0,     0,     0,    97,     1,     4,     6,     7,     8,     9,
    10,    11,    12,    13,    15,    16,    17,    18,    19,    20,
    14,     0,    49,    82,     0,     3,    40,    39,     0,    30,
     0,     0,     0,    41,     0,     0,     0,     0,     0,     0,
     0,    84,    85,    90,    91,    92,    87,    86,     0,   102,
     0,    98,    99,     5,    46,     0,     0,     0,     0,     0,
     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
     0,     0,     0,     0,     0,    89,    88,   107,     0,     0,
    25,     0,     0,    31,    22,     0,   107,    42,    43,     0,
     0,     0,     0,    45,    83,     0,    93,    97,    68,    69,
    70,    71,    72,    73,    76,    74,    75,    77,    78,     0,
    67,    66,    55,    57,    56,    60,    61,    64,    65,    62,
    63,    58,    59,    50,    51,    53,    54,    52,   109,     0,
   108,     0,    96,     0,    30,     0,     0,     0,     0,     0,
     0,     0,   101,   100,     0,     0,    94,    95,     0,     0,
     0,    27,    80,     0,    48,    35,    33,    79,   110,     0,
    30,    21,     0,    26,     0,     0,     0,     0,    35,    32,
     0,    28,    44,     0,     0,    34,    36,     0,     0,    38,
    29,    37,     0,     0,     0
};

static const short yydefgoto[] = {   223,
     2,    35,    36,    37,     4,     5,    38,   204,    39,   123,
    40,    41,    42,   208,   209,    43,    44,    45,    46,    47,
    48,    49,    50,    51,    52,    53,    81,    82,    83,    54,
   170,   171
};

static const short yypact[] = {   -11,
    -2,   119,   -19,    23,-32768,    25,    29,   119,   -48,    45,
-32768,   -14,-32768,   206,    -4,   186,   119,     5,    36,    37,
-32768,   119,-32768,-32768,-32768,   206,   206,   206,   206,   206,
   206,   206,   186,   186,-32768,   119,-32768,-32768,-32768,-32768,
-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
-32768,   285,    42,-32768,    -2,-32768,-32768,-32768,    93,   186,
    46,   186,   111,-32768,   324,   363,   116,   186,   186,   186,
    95,    42,    42,    42,    42,    42,    42,    42,   401,   659,
    98,-32768,   110,-32768,-32768,   186,   186,   186,   186,   186,
   186,   186,   186,   186,   186,   186,   186,   186,   186,   186,
   186,   186,   186,   186,   186,   186,   186,   186,   186,   186,
   186,   186,   186,   186,   186,-32768,-32768,   186,   186,   130,
-32768,    74,   121,   752,    -2,   439,   186,-32768,-32768,    77,
   477,   515,   553,-32768,-32768,   186,-32768,   186,   752,   752,
   752,   752,   752,   752,   752,   752,   752,   752,   752,   690,
   769,   785,   800,   814,   101,   170,   170,    12,    12,    12,
    12,   180,   180,    58,    58,-32768,-32768,-32768,   246,   141,
-32768,   628,-32768,   186,   186,   142,   119,   143,   158,   119,
   144,   119,   752,-32768,   186,   186,-32768,-32768,   591,   149,
   165,   184,   178,   169,-32768,    44,-32768,   -16,-32768,   175,
   186,-32768,   119,-32768,   119,   186,   156,   176,    44,-32768,
   181,-32768,-32768,   721,   119,-32768,-32768,   119,   119,-32768,
-32768,-32768,   203,   205,-32768
};

static const short yypgoto[] = {-32768,
-32768,   -15,    -8,-32768,    83,   154,-32768,-32768,-32768,  -173,
-32768,-32768,-32768,     3,-32768,-32768,-32768,-32768,-32768,-32768,
    22,-32768,-32768,-32768,   -10,   -13,    76,-32768,-32768,-32768,
    92,    34
};


#define	YYLAST		876


static const short yytable[] = {    59,
    63,   190,     1,    55,    65,    66,    71,    11,    67,     3,
    13,    14,    72,    73,    74,    75,    76,    77,    78,    64,
    84,    60,    79,    80,    23,    24,    25,   211,    98,    99,
   100,   101,   102,   103,   104,   105,   106,   107,   108,   109,
   110,   111,   112,   113,   114,   115,    56,   206,    57,   124,
   207,   126,    58,    26,    27,    62,    61,   131,   132,   133,
    28,    29,    30,    31,    32,    33,    34,   109,   110,   111,
   112,   113,   114,   115,    68,   139,   140,   141,   142,   143,
   144,   145,   146,   147,   148,   149,   150,   151,   152,   153,
   154,   155,   156,   157,   158,   159,   160,   161,   162,   163,
   164,   165,   166,   167,   168,    69,    70,   169,   172,   116,
   117,   118,   119,   120,   122,   125,   169,   113,   114,   115,
   130,     6,   134,   137,     7,   183,     8,    80,     9,    10,
    11,    12,   138,    13,    14,    15,    16,    17,    18,    19,
    20,   173,    21,   174,   175,    22,   179,    23,    24,    25,
   103,   104,   105,   106,   107,   108,   109,   110,   111,   112,
   113,   114,   115,   189,   124,   187,   191,   193,   192,   194,
   196,   195,   201,   197,   198,   169,    26,    27,   116,   117,
   127,   119,   120,    28,    29,    30,    31,    32,    33,    34,
   124,    22,   203,   205,   212,   214,   213,    11,   210,   215,
    13,    14,   224,   216,   225,   218,   220,   176,   121,   221,
   222,   217,   202,   184,    23,    24,    25,    11,   178,   199,
    13,   105,   106,   107,   108,   109,   110,   111,   112,   113,
   114,   115,     0,     0,    23,    24,    25,   111,   112,   113,
   114,   115,     0,    26,    27,   -94,   -94,   -94,   -94,   -94,
    28,    29,    30,    31,    32,    33,    34,     0,     0,     0,
     0,     0,     0,    26,    27,     0,     0,     0,   186,     0,
    28,    29,    30,    31,    32,    33,    34,    86,    87,    88,
    89,    90,    91,    92,    93,    94,    95,    96,    97,     0,
    98,    99,   100,   101,   102,   103,   104,   105,   106,   107,
   108,   109,   110,   111,   112,   113,   114,   115,    85,     0,
     0,     0,     0,     0,     0,     0,    86,    87,    88,    89,
    90,    91,    92,    93,    94,    95,    96,    97,     0,    98,
    99,   100,   101,   102,   103,   104,   105,   106,   107,   108,
   109,   110,   111,   112,   113,   114,   115,   128,     0,     0,
     0,     0,     0,     0,     0,    86,    87,    88,    89,    90,
    91,    92,    93,    94,    95,    96,    97,     0,    98,    99,
   100,   101,   102,   103,   104,   105,   106,   107,   108,   109,
   110,   111,   112,   113,   114,   115,   129,     0,     0,     0,
     0,     0,     0,     0,    86,    87,    88,    89,    90,    91,
    92,    93,    94,    95,    96,    97,     0,    98,    99,   100,
   101,   102,   103,   104,   105,   106,   107,   108,   109,   110,
   111,   112,   113,   114,   115,   135,     0,     0,     0,     0,
     0,     0,    86,    87,    88,    89,    90,    91,    92,    93,
    94,    95,    96,    97,     0,    98,    99,   100,   101,   102,
   103,   104,   105,   106,   107,   108,   109,   110,   111,   112,
   113,   114,   115,   177,     0,     0,     0,     0,     0,     0,
    86,    87,    88,    89,    90,    91,    92,    93,    94,    95,
    96,    97,     0,    98,    99,   100,   101,   102,   103,   104,
   105,   106,   107,   108,   109,   110,   111,   112,   113,   114,
   115,   180,     0,     0,     0,     0,     0,     0,    86,    87,
    88,    89,    90,    91,    92,    93,    94,    95,    96,    97,
     0,    98,    99,   100,   101,   102,   103,   104,   105,   106,
   107,   108,   109,   110,   111,   112,   113,   114,   115,   181,
     0,     0,     0,     0,     0,     0,    86,    87,    88,    89,
    90,    91,    92,    93,    94,    95,    96,    97,     0,    98,
    99,   100,   101,   102,   103,   104,   105,   106,   107,   108,
   109,   110,   111,   112,   113,   114,   115,   182,     0,     0,
     0,     0,     0,     0,    86,    87,    88,    89,    90,    91,
    92,    93,    94,    95,    96,    97,     0,    98,    99,   100,
   101,   102,   103,   104,   105,   106,   107,   108,   109,   110,
   111,   112,   113,   114,   115,   200,     0,     0,     0,     0,
     0,     0,    86,    87,    88,    89,    90,    91,    92,    93,
    94,    95,    96,    97,     0,    98,    99,   100,   101,   102,
   103,   104,   105,   106,   107,   108,   109,   110,   111,   112,
   113,   114,   115,   188,     0,     0,     0,     0,     0,    86,
    87,    88,    89,    90,    91,    92,    93,    94,    95,    96,
    97,     0,    98,    99,   100,   101,   102,   103,   104,   105,

⌨️ 快捷键说明

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