Cadabra
Computer algebra system for field theory problems
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Parser.hh
Go to the documentation of this file.
1 /*
2 
3  Cadabra: a field-theory motivated computer algebra system.
4  Copyright (C) 2001-2014 Kasper Peeters <kasper.peeters@phi-sci.com>
5 
6  This program is free software: you can redistribute it and/or
7  modify it under the terms of the GNU General Public License as
8  published by the Free Software Foundation, either version 3 of the
9  License, or (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 
19 */
20 
21 #pragma once
22 
23 #include <string>
24 #include <vector>
25 #include <iostream>
26 
27 #include "Storage.hh"
28 
35 
36 
37 
38 namespace cadabra {
39 
40 class Parser {
41  public:
42  Parser();
43  Parser(std::shared_ptr<Ex>);
44  Parser(std::shared_ptr<Ex>, const std::string&);
45 
46  void erase();
47 
48  void remove_empty_nodes();
49 
50  // Finalise the parsed expression. This function should be
51  // called when no further operator>> calls are going to be made,
52  // and is necessary to ensure that the tree is consistent.
53  void finalise();
54  bool string2tree(const std::string& inp);
55 
56  std::shared_ptr<Ex> tree;
57  private:
58  Ex::iterator parts;
59  std::string str;
60 
64 
65  void advance(unsigned int& i);
66  unsigned char get_token(unsigned int i);
67  bool is_number(const std::string& str) const;
68  str_node::bracket_t is_closing_bracket(const unsigned char& br) const;
69  str_node::bracket_t is_opening_bracket(const unsigned char& br) const;
70  str_node::parent_rel_t is_link(const unsigned char& ln) const;
71 
72  std::vector<mode_t> current_mode;
73  std::vector<str_node::bracket_t> current_bracket;
74  std::vector<str_node::parent_rel_t> current_parent_rel;
75 };
76 
77 }
78 
79 std::istream& operator>>(std::istream&, cadabra::Parser&);
80 
81 
82 //std::ostream& operator<<(std::ostream&, Parser&);
unsigned char get_token(unsigned int i)
Definition: Parser.cc:146
Definition: Parser.hh:63
void finalise()
Definition: Parser.cc:130
std::string str
Definition: Parser.hh:59
Definition: Parser.hh:63
mode_t
Definition: Parser.hh:61
bool is_number(const std::string &str) const
Definition: Parser.cc:371
std::vector< str_node::parent_rel_t > current_parent_rel
Definition: Parser.hh:74
Parser()
Definition: Parser.cc:82
Definition: Parser.hh:61
bool string2tree(const std::string &inp)
Definition: Parser.cc:154
Ex::iterator parts
Definition: Parser.hh:58
Definition: Parser.hh:62
str_node::bracket_t is_opening_bracket(const unsigned char &br) const
Definition: Parser.cc:63
std::istream & operator>>(std::istream &, cadabra::Parser &)
Definition: Parser.cc:27
Definition: Parser.hh:63
Definition: Parser.hh:63
Definition: Parser.hh:40
Definition: Parser.hh:62
Definition: Parser.hh:61
void remove_empty_nodes()
Definition: Parser.cc:118
str_node::bracket_t is_closing_bracket(const unsigned char &br) const
Definition: Parser.cc:53
std::shared_ptr< Ex > tree
Definition: Parser.hh:56
std::vector< mode_t > current_mode
Definition: Parser.hh:72
parent_rel_t
Child nodes are related to their parent node by a so-called parent relation, which can be one of thes...
Definition: Storage.hh:61
str_node::parent_rel_t is_link(const unsigned char &ln) const
Definition: Parser.cc:73
void erase()
Definition: Parser.cc:107
bracket_t
Definition: Storage.hh:57
void advance(unsigned int &i)
Definition: Parser.cc:140
std::vector< str_node::bracket_t > current_bracket
Definition: Parser.hh:73
Definition: Parser.hh:61