From: Jens Vollinga Date: Fri, 28 Oct 2011 19:09:33 +0000 (+0200) Subject: Parser can now read GiNaC lists (lst) defined by braces. X-Git-Tag: release_1-6-2~1 X-Git-Url: https://ginac.de/ginac.git//ginac.git?a=commitdiff_plain;h=99901bd5c742;p=ginac.git Parser can now read GiNaC lists (lst) defined by braces. This commit completes the bug fix in commit 9a4f392521083d28e1c238e7898ab1d2ac5b73cd. --- diff --git a/ginac/parser/parser.cpp b/ginac/parser/parser.cpp index 992b1510..de6b269a 100644 --- a/ginac/parser/parser.cpp +++ b/ginac/parser/parser.cpp @@ -120,6 +120,34 @@ ex parser::parse_paren_expr() return e; } +/// lst_expr: '{' expression { ',' expression } '}' +ex parser::parse_lst_expr() +{ + get_next_tok(); // eat {. + + lst list; + if (token != '}') { + while (true) { + ex e = parse_expression(); // expression(); + list.append(e); + + if (token == '}') { + break; + } + + if (token != ',') { + Parse_error("expected '}'"); + } + + get_next_tok(); // eat ','. + } + } + // Eat the '}'. + get_next_tok(); + + return list; +} + extern const ex _ex0; /// unary_expr: [+-] expression @@ -151,6 +179,8 @@ ex parser::parse_primary() return parse_number_expr(); case '(': return parse_paren_expr(); + case '{': + return parse_lst_expr(); case '-': case '+': return parse_unary_expr(); diff --git a/ginac/parser/parser.h b/ginac/parser/parser.h index ac57a798..cab02c39 100644 --- a/ginac/parser/parser.h +++ b/ginac/parser/parser.h @@ -67,6 +67,9 @@ class parser /// paren_expr: '(' expression ')' ex parse_paren_expr(); + /// lst_expr: '{' expression { ',' expression } '}' + ex parse_lst_expr(); + /// number_expr: number ex parse_number_expr();