CBMC
lispexpr.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module:
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
9 // THIS HEADER IS DEPRECATED (since 2015-06-30) AND WILL GO AWAY
10 
11 #ifndef CPROVER_UTIL_LISPEXPR_H
12 #define CPROVER_UTIL_LISPEXPR_H
13 
14 #if defined(_WIN32) && !defined(__MINGW32__)
15 #include <cstring>
16 #define strcasecmp _strcmpi
17 #else
18 #include <strings.h>
19 #endif
20 
21 #include <string>
22 #include <vector>
23 #include <iosfwd>
24 
25 class lispsymbolt:public std::string
26 {
27  public:
28  // NOLINTNEXTLINE(runtime/explicit)
29  lispsymbolt(const char *a):std::string(a)
30  {
31  }
32 
33  lispsymbolt():std::string()
34  {
35  }
36 
37  // NOLINTNEXTLINE(runtime/explicit)
38  lispsymbolt(const std::string &a):std::string(a)
39  {
40  }
41 
42  bool operator== (const lispsymbolt &b) const
43  { return strcasecmp(c_str(), b.c_str())==0; }
44 
45  bool operator!= (const lispsymbolt &b) const
46  { return strcasecmp(c_str(), b.c_str())!=0; }
47 
48  bool operator== (const char *b) const
49  { return strcasecmp(c_str(), b)==0; }
50 
51  bool operator!= (const char *b) const
52  { return strcasecmp(c_str(), b)!=0; }
53 };
54 
55 inline bool operator== (const char *a, const lispsymbolt &b)
56 { return strcasecmp(a, b.c_str())==0; }
57 
58 inline bool operator!= (const char *a, const lispsymbolt &b)
59 { return strcasecmp(a, b.c_str())!=0; }
60 
61 inline bool operator== (const lispsymbolt &a, const std::string &b)
62 { return strcasecmp(a.c_str(), b.c_str())==0; }
63 
64 inline bool operator!= (const lispsymbolt &a, const std::string &b)
65 { return strcasecmp(a.c_str(), b.c_str())!=0; }
66 
67 inline bool operator== (const std::string &a, const lispsymbolt &b)
68 { return strcasecmp(a.c_str(), b.c_str())==0; }
69 
70 inline bool operator!= (const std::string &a, const lispsymbolt &b)
71 { return strcasecmp(a.c_str(), b.c_str())!=0; }
72 
73 class lispexprt:public std::vector<lispexprt>
74 {
75 public:
76  enum { String, Symbol, Number, List } type;
78  std::string expr2string() const;
79  bool parse(const std::string &s);
80  bool is_nil() const
81  { return type==Symbol && value=="nil"; }
82 
83  void make_nil()
84  {
85  clear();
86  type=Symbol;
87  value="nil";
88  }
89 
90 protected:
91  bool parse(const std::string &s, std::string::size_type &ptr);
92 };
93 
94 inline std::ostream &operator<<(
95  std::ostream &out,
96  const lispexprt &expr)
97 {
98  return out << expr.expr2string();
99 }
100 
101 int test_lispexpr();
102 
103 #endif // CPROVER_UTIL_LISPEXPR_H
@ Number
Definition: lispexpr.h:76
@ String
Definition: lispexpr.h:76
@ Symbol
Definition: lispexpr.h:76
lispsymbolt value
Definition: lispexpr.h:77
void make_nil()
Definition: lispexpr.h:83
bool is_nil() const
Definition: lispexpr.h:80
enum lispexprt::@7 type
std::string expr2string() const
Definition: lispexpr.cpp:15
bool parse(const std::string &s)
Definition: lispexpr.cpp:54
lispsymbolt()
Definition: lispexpr.h:33
bool operator!=(const lispsymbolt &b) const
Definition: lispexpr.h:45
bool operator==(const lispsymbolt &b) const
Definition: lispexpr.h:42
lispsymbolt(const char *a)
Definition: lispexpr.h:29
lispsymbolt(const std::string &a)
Definition: lispexpr.h:38
int test_lispexpr()
Definition: lispexpr.cpp:152
bool operator!=(const char *a, const lispsymbolt &b)
Definition: lispexpr.h:58
bool operator==(const char *a, const lispsymbolt &b)
Definition: lispexpr.h:55
std::ostream & operator<<(std::ostream &out, const lispexprt &expr)
Definition: lispexpr.h:94
int strcasecmp(const char *s1, const char *s2)
Definition: string.c:412
#define size_type
Definition: unistd.c:347