diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index d139c1001..7d90f90b2 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -436,13 +436,21 @@ static void compileTerm(Token *& tok, std::stack &op) name->next()->astOperand1(name); tok = tok->next(); } else { - compileExpression(tok,op); - tok = tok->next(); // skip ')' or ']' - if (!op.empty()) { - name->next()->astOperand2(op.top()); - op.pop(); + Token *prev = name; + tok = tok->previous(); + while (Token::Match(tok, "(|[")) { + Token *tok1 = tok; + tok = tok->next(); + compileExpression(tok, op); + if (!op.empty()) { + tok1->astOperand2(op.top()); + op.pop(); + } + tok1->astOperand1(prev); + prev = tok1; + if (Token::Match(tok, "]|)")) + tok = tok->next(); } - name->next()->astOperand1(name); } op.push(name->next()); } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 4b6e09174..4ddfea6f2 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -9985,6 +9985,7 @@ private: void astbrackets() const { // [] ASSERT_EQUALS("a23+[4+", testAst("a[2+3]+4")); + ASSERT_EQUALS("a1[0[", testAst("a[1][0]")); } void astunaryop() const { // unary operators