This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
op.c: Remove dVAR from newRANGE
[perl5.git] / parser.h
... / ...
CommitLineData
1/* parser.h
2 *
3 * Copyright (c) 2006, 2007, 2009, 2010, 2011 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
14typedef 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/* Fields that need to be shared with (i.e., visible to) inner lex-
25 ing scopes. */
26typedef struct yy_lexshared {
27 struct yy_lexshared *ls_prev;
28 SV *ls_linestr; /* mirrors PL_parser->linestr */
29 char *ls_bufptr; /* mirrors PL_parser->bufptr */
30 char *re_eval_start; /* start of "(?{..." text */
31 SV *re_eval_str; /* "(?{...})" text */
32} LEXSHARED;
33
34typedef struct yy_parser {
35
36 /* parser state */
37
38 struct yy_parser *old_parser; /* previous value of PL_parser */
39 YYSTYPE yylval; /* value of lookahead symbol, set by yylex() */
40 int yychar; /* The lookahead symbol. */
41
42 /* Number of tokens to shift before error messages enabled. */
43 int yyerrstatus;
44
45 int stack_size;
46 int yylen; /* length of active reduction */
47 yy_stack_frame *stack; /* base of stack */
48 yy_stack_frame *ps; /* current stack frame */
49
50 /* lexer state */
51
52 I32 lex_brackets; /* square and curly bracket count */
53 I32 lex_casemods; /* casemod count */
54 char *lex_brackstack;/* what kind of brackets to pop */
55 char *lex_casestack; /* what kind of case mods in effect */
56 U8 lex_defer; /* state after determined token */
57 U8 lex_dojoin; /* doing an array interpolation
58 1 = @{...} 2 = ->@ */
59 U8 lex_expect; /* UNUSED */
60 U8 expect; /* how to interpret ambiguous tokens */
61 I32 lex_formbrack; /* bracket count at outer format level */
62 OP *lex_inpat; /* in pattern $) and $| are special */
63 OP *lex_op; /* extra info to pass back on op */
64 SV *lex_repl; /* runtime replacement from s/// */
65 U16 lex_inwhat; /* what kind of quoting are we in */
66 OPCODE last_lop_op; /* last named list or unary operator */
67 I32 lex_starts; /* how many interps done on level */
68 SV *lex_stuff; /* runtime pattern from m// or s/// */
69 I32 multi_start; /* 1st line of multi-line string */
70 I32 multi_end; /* last line of multi-line string */
71 char multi_open; /* delimiter of said string */
72 char multi_close; /* delimiter of said string */
73 bool preambled;
74 bool lex_re_reparsing; /* we're doing G_RE_REPARSING */
75 I32 lex_allbrackets;/* (), [], {}, ?: bracket count */
76 SUBLEXINFO sublex_info;
77 LEXSHARED *lex_shared;
78 SV *linestr; /* current chunk of src text */
79 char *bufptr; /* carries the cursor (current parsing
80 position) from one invocation of yylex
81 to the next */
82 char *oldbufptr; /* in yylex, beginning of current token */
83 char *oldoldbufptr; /* in yylex, beginning of previous token */
84 char *bufend;
85 char *linestart; /* beginning of most recently read line */
86 char *last_uni; /* position of last named-unary op */
87 char *last_lop; /* position of last list operator */
88 /* copline is used to pass a specific line number to newSTATEOP. It
89 is a one-time line number, as newSTATEOP invalidates it (sets it to
90 NOLINE) after using it. The purpose of this is to report line num-
91 bers in multiline constructs using the number of the first line. */
92 line_t copline;
93 U16 in_my; /* we're compiling a "my"/"our" declaration */
94 U8 lex_state; /* next token is determined */
95 U8 error_count; /* how many compile errors so far, max 10 */
96 HV *in_my_stash; /* declared class of this "my" declaration */
97 PerlIO *rsfp; /* current source file pointer */
98 AV *rsfp_filters; /* holds chain of active source filters */
99 U8 form_lex_state; /* remember lex_state when parsing fmt */
100
101 YYSTYPE nextval[5]; /* value of next token, if any */
102 I32 nexttype[5]; /* type of next token */
103 I32 nexttoke;
104
105 COP *saved_curcop; /* the previous PL_curcop */
106 char tokenbuf[256];
107 line_t herelines; /* number of lines in here-doc */
108 line_t preambling; /* line # when processing $ENV{PERL5DB} */
109 U8 lex_fakeeof; /* precedence at which to fake EOF */
110 U8 lex_flags;
111 PERL_BITFIELD16 in_pod:1; /* lexer is within a =pod section */
112 PERL_BITFIELD16 filtered:1; /* source filters in evalbytes */
113 PERL_BITFIELD16 saw_infix_sigil:1; /* saw & or * or % operator */
114 PERL_BITFIELD16 parsed_sub:1; /* last thing parsed was a sub */
115} yy_parser;
116
117/* flags for lexer API */
118#define LEX_STUFF_UTF8 0x00000001
119#define LEX_KEEP_PREVIOUS 0x00000002
120
121#ifdef PERL_CORE
122# define LEX_START_SAME_FILTER 0x00000001
123# define LEX_IGNORE_UTF8_HINTS 0x00000002
124# define LEX_EVALBYTES 0x00000004
125# define LEX_START_COPIED 0x00000008
126# define LEX_DONT_CLOSE_RSFP 0x00000010
127# define LEX_START_FLAGS \
128 (LEX_START_SAME_FILTER|LEX_START_COPIED \
129 |LEX_IGNORE_UTF8_HINTS|LEX_EVALBYTES|LEX_DONT_CLOSE_RSFP)
130#endif
131
132/* flags for parser API */
133#define PARSE_OPTIONAL 0x00000001
134
135/* values for lex_fakeeof */
136enum {
137 LEX_FAKEEOF_NEVER, /* don't fake EOF */
138 LEX_FAKEEOF_CLOSING, /* fake EOF at unmatched closing punctuation */
139 LEX_FAKEEOF_NONEXPR, /* ... and at token that can't be in expression */
140 LEX_FAKEEOF_LOWLOGIC, /* ... and at low-precedence logic operator */
141 LEX_FAKEEOF_COMMA, /* ... and at comma */
142 LEX_FAKEEOF_ASSIGN, /* ... and at assignment operator */
143 LEX_FAKEEOF_IFELSE, /* ... and at ?: operator */
144 LEX_FAKEEOF_RANGE, /* ... and at range operator */
145 LEX_FAKEEOF_LOGIC, /* ... and at logic operator */
146 LEX_FAKEEOF_BITWISE, /* ... and at bitwise operator */
147 LEX_FAKEEOF_COMPARE, /* ... and at comparison operator */
148 LEX_FAKEEOF_MAX
149};
150
151/*
152 * Local variables:
153 * c-indentation-style: bsd
154 * c-basic-offset: 4
155 * indent-tabs-mode: nil
156 * End:
157 *
158 * ex: set ts=8 sts=4 sw=4 et:
159 */