| 1 | /* parser.h |
| 2 | * |
| 3 | * Copyright (c) 2006, 2007, Larry Wall and others |
| 4 | * |
| 5 | * You may distribute under the terms of either the GNU General Public |
| 6 | * License or the Artistic License, as specified in the README file. |
| 7 | * |
| 8 | * This file defines the layout of the parser object used by the parser |
| 9 | * and lexer (perly.c, toke,c). |
| 10 | */ |
| 11 | |
| 12 | #define YYEMPTY (-2) |
| 13 | |
| 14 | typedef struct { |
| 15 | YYSTYPE val; /* semantic value */ |
| 16 | short state; |
| 17 | I32 savestack_ix; /* size of savestack at this state */ |
| 18 | CV *compcv; /* value of PL_compcv when this value was created */ |
| 19 | #ifdef DEBUGGING |
| 20 | const char *name; /* token/rule name for -Dpv */ |
| 21 | #endif |
| 22 | } yy_stack_frame; |
| 23 | |
| 24 | typedef struct yy_parser { |
| 25 | |
| 26 | /* parser state */ |
| 27 | |
| 28 | struct yy_parser *old_parser; /* previous value of PL_parser */ |
| 29 | YYSTYPE yylval; /* value of lookahead symbol, set by yylex() */ |
| 30 | int yychar; /* The lookahead symbol. */ |
| 31 | |
| 32 | /* Number of tokens to shift before error messages enabled. */ |
| 33 | int yyerrstatus; |
| 34 | |
| 35 | int stack_size; |
| 36 | int yylen; /* length of active reduction */ |
| 37 | yy_stack_frame *stack; /* base of stack */ |
| 38 | yy_stack_frame *ps; /* current stack frame */ |
| 39 | |
| 40 | /* lexer state */ |
| 41 | |
| 42 | I32 lex_brackets; /* square and curly bracket count */ |
| 43 | I32 lex_casemods; /* casemod count */ |
| 44 | char *lex_brackstack;/* what kind of brackets to pop */ |
| 45 | char *lex_casestack; /* what kind of case mods in effect */ |
| 46 | U8 lex_defer; /* state after determined token */ |
| 47 | bool lex_dojoin; /* doing an array interpolation */ |
| 48 | U8 lex_expect; /* expect after determined token */ |
| 49 | U8 expect; /* how to interpret ambiguous tokens */ |
| 50 | I32 lex_formbrack; /* bracket count at outer format level */ |
| 51 | OP *lex_inpat; /* in pattern $) and $| are special */ |
| 52 | OP *lex_op; /* extra info to pass back on op */ |
| 53 | SV *lex_repl; /* runtime replacement from s/// */ |
| 54 | U16 lex_inwhat; /* what kind of quoting are we in */ |
| 55 | OPCODE last_lop_op; /* last list operator */ |
| 56 | I32 lex_starts; /* how many interps done on level */ |
| 57 | SV *lex_stuff; /* runtime pattern from m// or s/// */ |
| 58 | I32 multi_start; /* 1st line of multi-line string */ |
| 59 | I32 multi_end; /* last line of multi-line string */ |
| 60 | char multi_open; /* delimiter of said string */ |
| 61 | char multi_close; /* delimiter of said string */ |
| 62 | char pending_ident; /* pending identifier lookup */ |
| 63 | bool preambled; |
| 64 | I32 lex_allbrackets;/* (), [], {}, ?: bracket count */ |
| 65 | SUBLEXINFO sublex_info; |
| 66 | SV *linestr; /* current chunk of src text */ |
| 67 | char *bufptr; |
| 68 | char *oldbufptr; |
| 69 | char *oldoldbufptr; |
| 70 | char *bufend; |
| 71 | char *linestart; /* beginning of most recently read line */ |
| 72 | char *last_uni; /* position of last named-unary op */ |
| 73 | char *last_lop; /* position of last list operator */ |
| 74 | line_t copline; /* current line number */ |
| 75 | U16 in_my; /* we're compiling a "my"/"our" declaration */ |
| 76 | U8 lex_state; /* next token is determined */ |
| 77 | U8 error_count; /* how many compile errors so far, max 10 */ |
| 78 | HV *in_my_stash; /* declared class of this "my" declaration */ |
| 79 | PerlIO *rsfp; /* current source file pointer */ |
| 80 | AV *rsfp_filters; /* holds chain of active source filters */ |
| 81 | |
| 82 | #ifdef PERL_MAD |
| 83 | SV *endwhite; |
| 84 | I32 faketokens; |
| 85 | I32 lasttoke; |
| 86 | SV *nextwhite; |
| 87 | I32 realtokenstart; |
| 88 | SV *skipwhite; |
| 89 | SV *thisclose; |
| 90 | MADPROP * thismad; |
| 91 | SV *thisopen; |
| 92 | SV *thisstuff; |
| 93 | SV *thistoken; |
| 94 | SV *thiswhite; |
| 95 | |
| 96 | /* What we know when we're in LEX_KNOWNEXT state. */ |
| 97 | NEXTTOKE nexttoke[5]; /* value of next token, if any */ |
| 98 | I32 curforce; |
| 99 | #else |
| 100 | YYSTYPE nextval[5]; /* value of next token, if any */ |
| 101 | I32 nexttype[5]; /* type of next token */ |
| 102 | I32 nexttoke; |
| 103 | #endif |
| 104 | |
| 105 | COP *saved_curcop; /* the previous PL_curcop */ |
| 106 | char tokenbuf[256]; |
| 107 | |
| 108 | bool in_pod; /* lexer is within a =pod section */ |
| 109 | U8 lex_fakeeof; /* precedence at which to fake EOF */ |
| 110 | U32 lex_flags; |
| 111 | } yy_parser; |
| 112 | |
| 113 | /* flags for lexer API */ |
| 114 | #define LEX_STUFF_UTF8 0x00000001 |
| 115 | #define LEX_KEEP_PREVIOUS 0x00000002 |
| 116 | |
| 117 | #ifdef PERL_CORE |
| 118 | # define LEX_START_SAME_FILTER 0x00000001 |
| 119 | #endif |
| 120 | #define LEX_IGNORE_UTF8_HINTS 0x00000002 |
| 121 | |
| 122 | /* flags for parser API */ |
| 123 | #define PARSE_OPTIONAL 0x00000001 |
| 124 | |
| 125 | /* values for lex_fakeeof */ |
| 126 | enum { |
| 127 | LEX_FAKEEOF_NEVER, /* don't fake EOF */ |
| 128 | LEX_FAKEEOF_CLOSING, /* fake EOF at unmatched closing punctuation */ |
| 129 | LEX_FAKEEOF_NONEXPR, /* ... and at token that can't be in expression */ |
| 130 | LEX_FAKEEOF_LOWLOGIC, /* ... and at low-precedence logic operator */ |
| 131 | LEX_FAKEEOF_COMMA, /* ... and at comma */ |
| 132 | LEX_FAKEEOF_ASSIGN, /* ... and at assignment operator */ |
| 133 | LEX_FAKEEOF_IFELSE, /* ... and at ?: operator */ |
| 134 | LEX_FAKEEOF_RANGE, /* ... and at range operator */ |
| 135 | LEX_FAKEEOF_LOGIC, /* ... and at logic operator */ |
| 136 | LEX_FAKEEOF_BITWISE, /* ... and at bitwise operator */ |
| 137 | LEX_FAKEEOF_COMPARE, /* ... and at comparison operator */ |
| 138 | LEX_FAKEEOF_MAX |
| 139 | }; |
| 140 | |
| 141 | /* |
| 142 | * Local variables: |
| 143 | * c-indentation-style: bsd |
| 144 | * c-basic-offset: 4 |
| 145 | * indent-tabs-mode: t |
| 146 | * End: |
| 147 | * |
| 148 | * ex: set ts=8 sts=4 sw=4 noet: |
| 149 | */ |