diff options
Diffstat (limited to 'gen')
| -rw-r--r-- | gen/gen_parser.c | 190 | 
1 files changed, 164 insertions, 26 deletions
diff --git a/gen/gen_parser.c b/gen/gen_parser.c index 173e6c1..7375732 100644 --- a/gen/gen_parser.c +++ b/gen/gen_parser.c @@ -276,7 +276,39 @@ enum yysymbol_kind_t    YYSYMBOL_PRINT = 35,                     /* "print"  */    YYSYMBOL_END = 36,                       /* "end"  */    YYSYMBOL_YYACCEPT = 37,                  /* $accept  */ -  YYSYMBOL_input = 38                      /* input  */ +  YYSYMBOL_statement_list = 38,            /* statement_list  */ +  YYSYMBOL_definitions = 39,               /* definitions  */ +  YYSYMBOL_variable_definition = 40,       /* variable_definition  */ +  YYSYMBOL_variable_definitions = 41,      /* variable_definitions  */ +  YYSYMBOL_opt_variable_definitions = 42,  /* opt_variable_definitions  */ +  YYSYMBOL_return = 43,                    /* return  */ +  YYSYMBOL_opt_return = 44,                /* opt_return  */ +  YYSYMBOL_function_definition = 45,       /* function_definition  */ +  YYSYMBOL_procedure_definition = 46,      /* procedure_definition  */ +  YYSYMBOL_formals = 47,                   /* formals  */ +  YYSYMBOL_opt_formals = 48,               /* opt_formals  */ +  YYSYMBOL_formal_arg = 49,                /* formal_arg  */ +  YYSYMBOL_procedure_call = 50,            /* procedure_call  */ +  YYSYMBOL_arguments = 51,                 /* arguments  */ +  YYSYMBOL_opt_arguments = 52,             /* opt_arguments  */ +  YYSYMBOL_assignment = 53,                /* assignment  */ +  YYSYMBOL_lvalue = 54,                    /* lvalue  */ +  YYSYMBOL_rvalue = 55,                    /* rvalue  */ +  YYSYMBOL_print_statement = 56,           /* print_statement  */ +  YYSYMBOL_print_items = 57,               /* print_items  */ +  YYSYMBOL_print_item = 58,                /* print_item  */ +  YYSYMBOL_statement = 59,                 /* statement  */ +  YYSYMBOL_until_statement = 60,           /* until_statement  */ +  YYSYMBOL_unless_statement = 61,          /* unless_statement  */ +  YYSYMBOL_expression = 62,                /* expression  */ +  YYSYMBOL_simple_expr = 63,               /* simple_expr  */ +  YYSYMBOL_term = 64,                      /* term  */ +  YYSYMBOL_factor = 65,                    /* factor  */ +  YYSYMBOL_atom = 66,                      /* atom  */ +  YYSYMBOL_function_call = 67,             /* function_call  */ +  YYSYMBOL_unless_expression = 68,         /* unless_expression  */ +  YYSYMBOL_opt_definitions = 69,           /* opt_definitions  */ +  YYSYMBOL_program = 70                    /* program  */  };  typedef enum yysymbol_kind_t yysymbol_kind_t; @@ -322,7 +354,7 @@ static void yyerror(YYLTYPE *yylloc, void *lexer,  		struct parser *parser, const char *msg); -#line 326 "gen/gen_parser.c" +#line 358 "gen/gen_parser.c"  #ifdef short @@ -435,7 +467,7 @@ typedef int yytype_uint16;  /* Stored state numbers (used for stacks). */ -typedef yytype_int8 yy_state_t; +typedef yytype_uint8 yy_state_t;  /* State numbers in computations.  */  typedef int yy_state_fast_t; @@ -647,18 +679,18 @@ union yyalloc  #endif /* !YYCOPY_NEEDED */  /* YYFINAL -- State number of the termination state.  */ -#define YYFINAL  2 +#define YYFINAL  26  /* YYLAST -- Last index in YYTABLE.  */ -#define YYLAST   0 +#define YYLAST   140  /* YYNTOKENS -- Number of terminals.  */  #define YYNTOKENS  37  /* YYNNTS -- Number of nonterminals.  */ -#define YYNNTS  2 +#define YYNNTS  34  /* YYNRULES -- Number of rules.  */ -#define YYNRULES  2 +#define YYNRULES  69  /* YYNSTATES -- Number of states.  */ -#define YYNSTATES  3 +#define YYNSTATES  132  /* YYMAXUTOK -- Last valid token kind.  */  #define YYMAXUTOK   291 @@ -709,9 +741,15 @@ static const yytype_int8 yytranslate[] =  #if YYDEBUG  /* YYRLINE[YYN] -- Source line where rule number YYN was defined.  */ -static const yytype_uint8 yyrline[] = +static const yytype_int16 yyrline[] =  { -       0,   147,   147 +       0,   148,   148,   149,   152,   153,   154,   157,   160,   161, +     164,   165,   168,   171,   172,   175,   179,   184,   185,   188, +     189,   192,   195,   198,   199,   202,   203,   206,   209,   210, +     213,   214,   217,   220,   221,   224,   225,   228,   229,   230, +     231,   232,   233,   236,   239,   240,   243,   244,   245,   248, +     249,   250,   253,   254,   255,   258,   259,   260,   263,   264, +     265,   266,   267,   268,   269,   272,   275,   278,   279,   282  };  #endif @@ -733,7 +771,15 @@ static const char *const yytname[] =    "\",\"", "\".\"", "\"=\"", "\"<\"", "\"+\"", "\"-\"", "\"*\"", "\"/\"",    "\"var\"", "\"is\"", "\"unless\"", "\"otherwise\"", "\"until\"",    "\"do\"", "\"done\"", "\"procedure\"", "\"function\"", "\"return\"", -  "\"print\"", "\"end\"", "$accept", "input", YY_NULLPTR +  "\"print\"", "\"end\"", "$accept", "statement_list", "definitions", +  "variable_definition", "variable_definitions", +  "opt_variable_definitions", "return", "opt_return", +  "function_definition", "procedure_definition", "formals", "opt_formals", +  "formal_arg", "procedure_call", "arguments", "opt_arguments", +  "assignment", "lvalue", "rvalue", "print_statement", "print_items", +  "print_item", "statement", "until_statement", "unless_statement", +  "expression", "simple_expr", "term", "factor", "atom", "function_call", +  "unless_expression", "opt_definitions", "program", YY_NULLPTR  };  static const char * @@ -743,7 +789,7 @@ yysymbol_name (yysymbol_kind_t yysymbol)  }  #endif -#define YYPACT_NINF (-1) +#define YYPACT_NINF (-17)  #define yypact_value_is_default(Yyn) \    ((Yyn) == YYPACT_NINF) @@ -757,7 +803,20 @@ yysymbol_name (yysymbol_kind_t yysymbol)     STATE-NUM.  */  static const yytype_int8 yypact[] =  { -      -1,     0,    -1 +       1,    -4,    27,    -1,   -17,   -17,   -17,   -17,    -3,    47, +      31,    62,    60,    61,    84,    -3,    83,    77,   -17,   -17, +     -17,    75,   -17,    79,   -17,   -17,   -17,    83,    95,    95, +      96,    83,   -16,   -17,   -17,    88,    98,    83,    59,    59, +     -17,     5,    17,    22,   -17,   -17,   -17,   -17,   -17,    94, +       5,    48,    -3,     5,   100,   -17,    99,    97,   101,   -17, +     -17,   106,    23,    83,    83,   111,    83,    -2,   -17,   -17, +      83,    83,    83,    83,    83,    83,    77,    83,   -17,     5, +     -17,   -17,   112,    85,    95,    85,   -17,    83,    -5,     5, +     -17,   110,   -17,    17,    17,    22,    22,   -17,   -17,   -17, +      10,   109,   116,   -17,   102,   -17,   102,     5,    -3,   -17, +      83,   -17,   -17,   102,   -17,   103,   104,    92,     0,   -17, +      -3,    48,   -17,    83,    89,    90,   -10,   105,    91,   -17, +     -17,   -17  };  /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. @@ -765,51 +824,123 @@ static const yytype_int8 yypact[] =     means the default is an error.  */  static const yytype_int8 yydefact[] =  { -       2,     0,     1 +      68,     0,     0,     0,    67,     6,     4,     5,     0,     0, +       0,     0,     0,    28,     0,     0,     0,     0,    69,    37, +      38,     0,    39,     3,    40,    41,     1,     0,    20,    20, +       0,    26,     0,    61,    60,    58,     0,     0,     0,     0, +      63,    42,    46,    49,    52,    57,    62,    35,    32,    34, +      36,     0,     0,     7,     0,    19,     0,    18,     0,    29, +      25,     0,    24,     0,     0,     0,    26,     0,    55,    56, +       0,     0,     0,     0,     0,     0,     0,     0,    27,    30, +      31,     2,     0,    14,     0,     0,    22,     0,    44,    43, +      59,     0,    64,    47,    48,    50,    51,    53,    54,    33, +       0,     0,     0,    13,    11,    17,    11,    23,     0,    65, +       0,    21,    12,     9,    10,     0,     0,     0,     0,     8, +       0,     0,    45,     0,     0,     0,     0,     0,     0,    66, +      16,    15  };  /* YYPGOTO[NTERM-NUM].  */ -static const yytype_int8 yypgoto[] = +static const yytype_int16 yypgoto[] =  { -      -1,    -1 +     -17,   -11,   -17,   128,    18,    26,    49,   -17,   -17,   -17, +     -17,   107,    51,    -8,   -17,    67,   -17,   -17,    19,   -17, +      63,   -17,   -17,   -17,   -17,   -15,   -12,     2,   -14,    38, +     -17,   -17,   -17,   -17  };  /* YYDEFGOTO[NTERM-NUM].  */  static const yytype_int8 yydefgoto[] =  { -       0,     1 +       0,    18,     4,   113,   114,   115,   103,   104,     6,     7, +      55,    56,    57,    40,    60,    61,    20,    21,    78,    22, +      48,    49,    23,    24,    25,    50,    42,    43,    44,    45, +      46,    80,     8,     9  };  /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM.  If     positive, shift that token.  If negative, reduce the rule whose     number is the opposite.  If YYTABLE_NINF, syntax error.  */ -static const yytype_int8 yytable[] = +static const yytype_uint8 yytable[] =  { -       2 +      19,    41,    10,    13,    32,    14,    12,    19,    92,    70, +      71,    63,    53,    64,    70,    71,    62,    70,    71,    70, +      71,   129,    67,   108,    70,    71,     1,    15,   123,    70, +      71,    16,    17,     2,     3,    11,    79,   110,    72,    73, +      87,    81,    70,    71,    19,    74,    75,    26,    88,    89, +      27,    62,    33,    34,    35,    36,    14,    37,    93,    94, +      97,    98,   100,    33,    34,    35,    36,    14,    37,    38, +      39,    28,   107,    29,    95,    96,    68,    69,    77,    30, +      47,    33,    34,    35,    36,    14,    37,    33,    34,    35, +      36,    14,    37,    31,    51,   118,    52,   117,    38,    39, +      19,    54,    59,    65,    38,    39,    79,    66,   126,   124, +      76,    82,    19,    83,    84,    85,    86,    90,   101,   102, +     109,   111,   112,   122,   131,   127,   128,     1,     5,   120, +     121,   119,   116,    91,   106,   105,    58,   130,     0,    99, +     125  };  static const yytype_int8 yycheck[] =  { -       0 +       8,    16,     6,     6,    15,     8,     7,    15,    10,    19, +      20,    27,    27,    29,    19,    20,    31,    19,    20,    19, +      20,    31,    37,    28,    19,    20,    25,    30,    28,    19, +      20,    34,    35,    32,    33,     8,    51,    27,    21,    22, +      17,    52,    19,    20,    52,    23,    24,     0,    63,    64, +      19,    66,     4,     5,     6,     7,     8,     9,    70,    71, +      74,    75,    77,     4,     5,     6,     7,     8,     9,    21, +      22,     9,    87,    13,    72,    73,    38,    39,    30,    18, +       3,     4,     5,     6,     7,     8,     9,     4,     5,     6, +       7,     8,     9,     9,    19,   110,    17,   108,    21,    22, +     108,     6,     6,    15,    21,    22,   121,     9,   123,   120, +      16,    11,   120,    14,    17,    14,    10,     6,     6,    34, +      10,    12,     6,    31,    33,    36,    36,    25,     0,    26, +      26,   113,   106,    66,    85,    84,    29,    32,    -1,    76, +     121  };  /* YYSTOS[STATE-NUM] -- The symbol kind of the accessing symbol of     state STATE-NUM.  */  static const yytype_int8 yystos[] =  { -       0,    38,     0 +       0,    25,    32,    33,    39,    40,    45,    46,    69,    70, +       6,     8,     7,     6,     8,    30,    34,    35,    38,    50, +      53,    54,    56,    59,    60,    61,     0,    19,     9,    13, +      18,     9,    38,     4,     5,     6,     7,     9,    21,    22, +      50,    62,    63,    64,    65,    66,    67,     3,    57,    58, +      62,    19,    17,    62,     6,    47,    48,    49,    48,     6, +      51,    52,    62,    27,    29,    15,     9,    62,    66,    66, +      19,    20,    21,    22,    23,    24,    16,    30,    55,    62, +      68,    38,    11,    14,    17,    14,    10,    17,    62,    62, +       6,    52,    10,    63,    63,    64,    64,    65,    65,    57, +      62,     6,    34,    43,    44,    49,    43,    62,    28,    10, +      27,    12,     6,    40,    41,    42,    42,    38,    62,    41, +      26,    26,    31,    28,    38,    55,    62,    36,    36,    31, +      32,    33  };  /* YYR1[RULE-NUM] -- Symbol kind of the left-hand side of rule RULE-NUM.  */  static const yytype_int8 yyr1[] =  { -       0,    37,    38 +       0,    37,    38,    38,    39,    39,    39,    40,    41,    41, +      42,    42,    43,    44,    44,    45,    46,    47,    47,    48, +      48,    49,    50,    51,    51,    52,    52,    53,    54,    54, +      55,    55,    56,    57,    57,    58,    58,    59,    59,    59, +      59,    59,    59,    60,    61,    61,    62,    62,    62,    63, +      63,    63,    64,    64,    64,    65,    65,    65,    66,    66, +      66,    66,    66,    66,    66,    67,    68,    69,    69,    70  };  /* YYR2[RULE-NUM] -- Number of symbols on the right-hand side of rule RULE-NUM.  */  static const yytype_int8 yyr2[] =  { -       0,     2,     0 +       0,     2,     3,     1,     1,     1,     1,     4,     2,     1, +       1,     0,     2,     1,     0,    11,    11,     3,     1,     1, +       0,     4,     4,     3,     1,     1,     0,     3,     1,     3, +       1,     1,     2,     3,     1,     1,     1,     1,     1,     1, +       1,     1,     2,     4,     4,     7,     1,     3,     3,     1, +       3,     3,     1,     3,     3,     2,     2,     1,     1,     3, +       1,     1,     1,     1,     3,     4,     7,     1,     0,     2  }; @@ -1668,8 +1799,14 @@ yyreduce:    YY_REDUCE_PRINT (yyn);    switch (yyn)      { +  case 68: /* opt_definitions: %empty  */ +#line 279 "src/parser.y" +          {} +#line 1806 "gen/gen_parser.c" +    break; -#line 1673 "gen/gen_parser.c" + +#line 1810 "gen/gen_parser.c"        default: break;      } @@ -1898,7 +2035,7 @@ yyreturnlab:    return yyresult;  } -#line 149 "src/parser.y" +#line 284 "src/parser.y"  #include "gen_lexer.inc" @@ -1992,5 +2129,6 @@ void parse(struct parser *p, const char *fname, const char *buf)  	// runs  	dump_lex(p); -	// yyparse(p->lexer, p); +	yy_scan_string(buf, p->lexer); +	yyparse(p->lexer, p);  }  | 
