diff --git a/src/macro/Expressions.hh b/src/macro/Expressions.hh index d77599a9..a570f48d 100644 --- a/src/macro/Expressions.hh +++ b/src/macro/Expressions.hh @@ -450,7 +450,7 @@ namespace macro { private: const string name; - ArrayPtr indices; // for strings/arrays + const ArrayPtr indices; // for indexing strings/arrays public: Variable(string name_arg, Environment &env_arg, Tokenizer::location location_arg) : @@ -458,10 +458,6 @@ namespace macro Variable(string name_arg, ArrayPtr indices_arg, Environment &env_arg, Tokenizer::location location_arg) : Expression(env_arg, move(location_arg)), name{move(name_arg)}, indices{move(indices_arg)} { } - inline void addIndexing(const vector indices_arg) - { - indices = make_shared(indices_arg, env); - } inline string to_string() const noexcept override { return name; } inline void print(ostream &output, bool matlab_output = false) const noexcept override { output << name; } BaseTypePtr eval() override; diff --git a/src/macro/Parser.yy b/src/macro/Parser.yy index 13244b40..5618b658 100644 --- a/src/macro/Parser.yy +++ b/src/macro/Parser.yy @@ -300,6 +300,11 @@ primary_expr : LPAREN expr RPAREN { $$ = $2; } | symbol { $$ = $1; } // Explicit rule needed for type conversion + | NAME LBRACKET comma_expr RBRACKET + { + $$ = make_shared($1, make_shared($3, driver.env, @3), + driver.env, @$); + } | NAME LPAREN comma_expr RPAREN { $$ = make_shared($1, $3, driver.env, @$); } | TRUE @@ -312,8 +317,6 @@ primary_expr : LPAREN expr RPAREN { $$ = make_shared($1, driver.env, @$); } | LBRACKET comma_expr RBRACKET { $$ = make_shared($2, driver.env, @$); } - | symbol LBRACKET comma_expr RBRACKET - { $1->addIndexing($3); $$ = $1; } | LPAREN tuple_comma_expr RPAREN { $$ = make_shared($2, driver.env, @$); } | LBRACKET expr IN expr WHEN expr RBRACKET