]> www.ginac.de Git - ginac.git/blobdiff - ginac/parser/parser.cpp
Parser can now read GiNaC lists (lst) defined by braces.
[ginac.git] / ginac / parser / parser.cpp
index 6c4ebea62563da64dc76983d3b8be83b3128242b..de6b269ac1ac934209d16989e2d836b431e0db8d 100644 (file)
@@ -3,7 +3,7 @@
  *  Implementation of GiNaC's parser. */
 
 /*
- *  GiNaC Copyright (C) 1999-2010 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2011 Johannes Gutenberg University Mainz, Germany
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -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();