From 99901bd5c74203caece07e3e2948780887a0e822 Mon Sep 17 00:00:00 2001 From: Jens Vollinga Date: Fri, 28 Oct 2011 21:09:33 +0200 Subject: [PATCH] Parser can now read GiNaC lists (lst) defined by braces. This commit completes the bug fix in commit 9a4f392521083d28e1c238e7898ab1d2ac5b73cd. --- ginac/parser/parser.cpp | 30 ++++++++++++++++++++++++++++++ ginac/parser/parser.h | 3 +++ 2 files changed, 33 insertions(+) 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(); -- 2.47.0