This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Sync Module-CoreList version with CPAN
[perl5.git] / parser.h
CommitLineData
5912531f
DM
1/* parser.h
2 *
2eee27d7 3 * Copyright (c) 2006, 2007, 2009, 2010, 2011 Larry Wall and others
5912531f
DM
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
6cded92d 9 * and lexer (perly.c, toke.c).
5912531f
DM
10 */
11
acdf0a21
DM
12#define YYEMPTY (-2)
13
5912531f
DM
14typedef struct {
15 YYSTYPE val; /* semantic value */
16 short state;
33703721 17 I32 savestack_ix; /* size of savestack at this state */
8c63ea58 18 CV *compcv; /* value of PL_compcv when this value was created */
5912531f
DM
19#ifdef DEBUGGING
20 const char *name; /* token/rule name for -Dpv */
21#endif
22} yy_stack_frame;
23
22735491 24typedef struct yy_parser {
199e78b7
DM
25
26 /* parser state */
27
22735491 28 struct yy_parser *old_parser; /* previous value of PL_parser */
5912531f 29 YYSTYPE yylval; /* value of lookahead symbol, set by yylex() */
9bd87817 30 int yychar; /* The lookahead symbol. */
5912531f
DM
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 */
22735491 37 yy_stack_frame *stack; /* base of stack */
5912531f 38 yy_stack_frame *ps; /* current stack frame */
199e78b7
DM
39
40 /* lexer state */
41
78cdf107 42 I32 lex_brackets; /* square and curly bracket count */
199e78b7
DM
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 */
651b5b28
NC
46 U8 lex_defer; /* state after determined token */
47 bool lex_dojoin; /* doing an array interpolation */
48 U8 lex_expect; /* expect after determined token */
53a7735b 49 U8 expect; /* how to interpret ambiguous tokens */
199e78b7
DM
50 I32 lex_formbrack; /* bracket count at outer format level */
51 OP *lex_inpat; /* in pattern $) and $| are special */
199e78b7
DM
52 OP *lex_op; /* extra info to pass back on op */
53 SV *lex_repl; /* runtime replacement from s/// */
651b5b28 54 U16 lex_inwhat; /* what kind of quoting are we in */
5ed5d9db 55 OPCODE last_lop_op; /* last named list or unary operator */
199e78b7
DM
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 */
670a9cb2 59 I32 multi_end; /* last line of multi-line string */
651b5b28
NC
60 char multi_open; /* delimiter of said string */
61 char multi_close; /* delimiter of said string */
199e78b7
DM
62 char pending_ident; /* pending identifier lookup */
63 bool preambled;
78cdf107 64 I32 lex_allbrackets;/* (), [], {}, ?: bracket count */
199e78b7 65 SUBLEXINFO sublex_info;
bdc0bf6f 66 SV *linestr; /* current chunk of src text */
a0dffe9b
FC
67 char *bufptr; /* carries the cursor (current parsing
68 position) from one invocation of yylex
69 to the next */
70 char *oldbufptr; /* in yylex, beginning of current token */
71 char *oldoldbufptr; /* in yylex, beginning of previous token */
f06b5848
DM
72 char *bufend;
73 char *linestart; /* beginning of most recently read line */
74 char *last_uni; /* position of last named-unary op */
75 char *last_lop; /* position of last list operator */
12bd6ede
DM
76 line_t copline; /* current line number */
77 U16 in_my; /* we're compiling a "my"/"our" declaration */
bc177e6b 78 U8 lex_state; /* next token is determined */
1f0c31d7 79 U8 error_count; /* how many compile errors so far, max 10 */
12bd6ede 80 HV *in_my_stash; /* declared class of this "my" declaration */
2f9285f8 81 PerlIO *rsfp; /* current source file pointer */
5486870f 82 AV *rsfp_filters; /* holds chain of active source filters */
583c9d5c 83 U8 form_lex_state; /* remember lex_state when parsing fmt */
199e78b7
DM
84
85#ifdef PERL_MAD
86 SV *endwhite;
87 I32 faketokens;
88 I32 lasttoke;
89 SV *nextwhite;
90 I32 realtokenstart;
91 SV *skipwhite;
92 SV *thisclose;
93 MADPROP * thismad;
94 SV *thisopen;
95 SV *thisstuff;
96 SV *thistoken;
97 SV *thiswhite;
fb205e7a
DM
98
99/* What we know when we're in LEX_KNOWNEXT state. */
100 NEXTTOKE nexttoke[5]; /* value of next token, if any */
101 I32 curforce;
102#else
103 YYSTYPE nextval[5]; /* value of next token, if any */
104 I32 nexttype[5]; /* type of next token */
105 I32 nexttoke;
199e78b7 106#endif
fb205e7a 107
7c4baf47 108 COP *saved_curcop; /* the previous PL_curcop */
14047fc9 109 char tokenbuf[256];
7c4baf47 110
78cdf107 111 U8 lex_fakeeof; /* precedence at which to fake EOF */
286a76ab 112 U8 lex_flags;
7ad221d3
FC
113 PERL_BITFIELD16 in_pod:1; /* lexer is within a =pod section */
114 PERL_BITFIELD16 filtered:1; /* source filters in evalbytes */
5912531f 115} yy_parser;
5912531f 116
f0e67a1d
Z
117/* flags for lexer API */
118#define LEX_STUFF_UTF8 0x00000001
119#define LEX_KEEP_PREVIOUS 0x00000002
17e00314 120
27fcb6ee
FC
121#ifdef PERL_CORE
122# define LEX_START_SAME_FILTER 0x00000001
60d63348
FC
123# define LEX_IGNORE_UTF8_HINTS 0x00000002
124# define LEX_EVALBYTES 0x00000004
0abcdfa4 125# define LEX_START_COPIED 0x00000008
87606032 126# define LEX_DONT_CLOSE_RSFP 0x00000010
60d63348 127# define LEX_START_FLAGS \
0abcdfa4 128 (LEX_START_SAME_FILTER|LEX_START_COPIED \
87606032 129 |LEX_IGNORE_UTF8_HINTS|LEX_EVALBYTES|LEX_DONT_CLOSE_RSFP)
27fcb6ee 130#endif
f0e67a1d 131
361d9b55
Z
132/* flags for parser API */
133#define PARSE_OPTIONAL 0x00000001
134
78cdf107
Z
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
e9a8c099
MHM
151/*
152 * Local variables:
153 * c-indentation-style: bsd
154 * c-basic-offset: 4
14d04a33 155 * indent-tabs-mode: nil
e9a8c099
MHM
156 * End:
157 *
14d04a33 158 * ex: set ts=8 sts=4 sw=4 et:
e9a8c099 159 */