]> www.ginac.de Git - ginac.git/blobdiff - ginac/parser/parser.cpp
Happy New Year!
[ginac.git] / ginac / parser / parser.cpp
index a3284fa4a6dd613fa6311073b3013047422b6b89..df616a41fcfe18307135234bf2cab0d1b95a3cb6 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-2020 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
  */
 
 #include "parser.h"
+#include "lst.h"
 #include "lexer.h"
 #include "debug.h"
 #include "mul.h"
 #include "constant.h"
 #include "function.h"
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
 
-#ifdef HAVE_STDINT_H
-#include <stdint.h> // for uintptr_t
-#endif
+#include <cstdint> // for uintptr_t
 #include <sstream>
 #include <stdexcept>
 
@@ -97,7 +93,7 @@ ex parser::parse_identifier_expr()
        // Eat the ')'.
        get_next_tok();
        prototype the_prototype = make_pair(name, args.size());
-       prototype_table::const_iterator reader = funcs.find(the_prototype);
+       auto reader = funcs.find(the_prototype);
        if (reader == funcs.end()) {
                Parse_error_("no function \"" << name << "\" with " <<
                             args.size() << " arguments");
@@ -120,8 +116,35 @@ ex parser::parse_paren_expr()
        return e;
 }
 
-extern numeric* _num_1_p;
-extern ex _ex0;
+/// 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
 ex parser::parse_unary_expr()
@@ -135,7 +158,7 @@ ex parser::parse_unary_expr()
        // -(a) 
        // +a
        // +(a)
-       // Delegete the work to parse_binop_rhs(), otherwise we end up
+       // Delegate the work to parse_binop_rhs(), otherwise we end up
        // duplicating it here. 
        ex lhs = _ex0; // silly trick
        ex e = parse_binop_rhs(0, lhs);
@@ -152,6 +175,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();