frontend/parse.c, allow nested `indexing', for example foo[bar[n]]

.control
compose ex1 values 111 222 333
compose ex2 values 1 2 3
print ex1 ex2 ex1[ex2[1]]
.endc
This commit is contained in:
Y.Niitsu 2014-03-25 12:07:48 +09:00 committed by rlar
parent 08ca40fe73
commit 6e3f60c6bd
2 changed files with 3 additions and 14 deletions

View File

@ -82,7 +82,7 @@
%token <num> TOK_NUM
%token <str> TOK_STR
%token TOK_LE TOK_GE TOK_NE TOK_LRANGE TOK_RRANGE
%token TOK_LE TOK_GE TOK_NE
%type <pnode> exp exp_list one_exp
@ -99,7 +99,6 @@
%left NEG /* negation--unary minus */
%right '^' /* exponentiation */
%left '[' ']'
%left TOK_LRANGE TOK_RRANGE
%initial-action /* initialize yylval */
{
@ -164,7 +163,7 @@ exp:
| exp '|' exp { $$ = mkbnode(PT_OP_OR, $1, $3); }
| exp '[' exp ']' { $$ = mkbnode(PT_OP_INDX, $1, $3); }
| exp TOK_LRANGE exp TOK_RRANGE { $$ = mkbnode(PT_OP_RANGE, $1, $3); }
| exp '[' '[' exp ']' ']' { $$ = mkbnode(PT_OP_RANGE, $1, $4); }
| exp '?' exp ':' exp { $$ = mkbnode(PT_OP_TERNARY,$1,
mkbnode(PT_OP_COMMA,$3,$5)); }
;

View File

@ -606,18 +606,8 @@ PPlex(YYSTYPE *lvalp, struct PPltype *llocp, char **line)
switch (*sbuf) {
case '[':
if (sbuf[1] == '[') {
lexer_return(TOK_LRANGE, 2);
} else {
lexer_return(*sbuf, 1);
}
case ']':
if (sbuf[1] == ']') {
lexer_return(TOK_RRANGE, 2);
} else {
lexer_return(*sbuf, 1);
}
lexer_return(*sbuf, 1);
case '>':
case '<':