2 * Copyright (C) 2003 Albert Davis
3 * Author: Albert Davis <aldavis@gnu.org>
5 * This file is part of "Gnucap", the Gnu Circuit Analysis Package
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 *------------------------------------------------------------------
26 /*--------------------------------------------------------------------------*/
30 /*--------------------------------------------------------------------------*/
39 void parse(CS
&) {unreachable();}
41 void dump(std::ostream
&out
)const;
42 void dump(OMSTREAM
& o
)const { untested();
48 explicit Token(const std::string Name
, const Base
* Data
, const std::string Args
)
49 : _name(Name
), _data(Data
), _aRgs(Args
) {}
50 explicit Token(const Token
& P
)
51 : Base(), _name(P
._name
), _data(P
._data
), _aRgs(P
._aRgs
) {assert(!_data
);}
53 virtual ~Token() {if (_data
) {
56 virtual Token
* clone()const = 0;
57 const std::string
& name()const {return _name
;}
58 const Base
* data()const {return _data
;}
59 const std::string
& aRgs()const {return _aRgs
;}
60 const std::string
full_name()const {return name() + aRgs();}
62 S
& full_dump(S
& s
)const {return _full_dump(s
);}
63 virtual void stack_op(Expression
*)const {unreachable();}
64 bool operator==(const Token
& P
) {return (typeid(*this)==typeid(P
))
65 && (data()==P
.data()) && (name()==P
.name()) && (aRgs()==P
.aRgs());}
67 virtual OMSTREAM
& _full_dump(OMSTREAM
& s
)const {return s
<< full_name();}
68 virtual std::ostream
& _full_dump(std::ostream
& s
)const {untested(); return s
<< full_name();}
70 /*--------------------------------------------------------------------------*/
72 inline S
& operator<<(S
& out
, const Token
& d
) {d
.dump(out
); return out
;}
73 /*--------------------------------------------------------------------------*/
74 class Token_SYMBOL
: public Token
77 explicit Token_SYMBOL(const std::string Name
, const std::string Args
)
78 : Token(Name
, NULL
, Args
) {}
79 explicit Token_SYMBOL(const Token_SYMBOL
& P
) : Token(P
) {untested();}
80 Token
* clone()const {untested();return new Token_SYMBOL(*this);}
81 void stack_op(Expression
*)const;
83 /*--------------------------------------------------------------------------*/
85 inline S
& operator<<(S
& out
, const Token_SYMBOL
& d
) {untested(); d
.dump(out
); return out
;}
86 /*--------------------------------------------------------------------------*/
87 class Token_BINOP
: public Token
90 explicit Token_BINOP(const std::string Name
)
91 : Token(Name
, NULL
, "") {}
92 explicit Token_BINOP(const Token_BINOP
& P
) : Token(P
) {}
93 Token
* clone()const {return new Token_BINOP(*this);}
94 Token
* op(const Token
* t1
, const Token
* t2
)const;
95 void stack_op(Expression
*)const;
97 class Token_STOP
: public Token
100 explicit Token_STOP(const std::string Name
)
101 : Token(Name
, NULL
, "") {}
102 explicit Token_STOP(const Token_STOP
& P
) : Token(P
) {}
103 Token
* clone()const {return new Token_STOP(*this);}
104 void stack_op(Expression
*)const;
106 class Token_PARLIST
: public Token
109 explicit Token_PARLIST(const std::string Name
)
110 : Token(Name
, NULL
, "") {}
111 explicit Token_PARLIST(const Token_PARLIST
& P
) : Token(P
) {untested();}
112 Token
* clone()const {untested();return new Token_PARLIST(*this);}
113 void stack_op(Expression
*)const;
115 class Token_UNARY
: public Token
118 explicit Token_UNARY(const std::string Name
)
119 : Token(Name
, NULL
, "") {}
120 explicit Token_UNARY(const Token_UNARY
& P
) : Token(P
) {untested();}
121 Token
* clone()const {untested();return new Token_UNARY(*this);}
122 Token
* op(const Token
* t1
)const;
123 void stack_op(Expression
*)const;
125 class Token_CONSTANT
: public Token
128 explicit Token_CONSTANT(const std::string Name
, const Base
* Data
, const std::string Args
)
129 : Token(Name
, Data
, Args
) {}
130 explicit Token_CONSTANT(const Token_CONSTANT
& P
) : Token(P
) {untested();}
131 Token
* clone()const {untested();return new Token_CONSTANT(*this);}
132 void stack_op(Expression
*)const;
134 std::ostream
& _full_dump(std::ostream
& s
)const {data()->dump(s
); return s
;}
135 OMSTREAM
& _full_dump(OMSTREAM
& s
)const {data()->dump(s
); return s
;}
137 /*--------------------------------------------------------------------------*/
138 class INTERFACE Expression
139 :public List_Base
<Token
>
142 const CARD_LIST
* _scope
;
145 void dump(std::ostream
&out
)const {return _dump(out
);}
146 void dump(OMSTREAM
&out
)const {return _dump(out
); }
148 template<class S
> void _dump(S
&)const;
149 private: // expression-in.cc
150 void arglisttail(CS
& File
);
151 void arglist(CS
& File
);
153 void factor(CS
& File
);
154 void factortail(CS
& File
);
155 void termtail(CS
& File
);
157 void addexptail(CS
& File
);
158 void addexp(CS
& File
);
159 void logicaltail(CS
& File
);
160 void logical(CS
& File
);
161 void andtail(CS
& File
);
162 void andarg(CS
& File
);
163 void exptail(CS
& File
);
164 void expression(CS
& File
);
166 explicit Expression() : _scope(NULL
) {
168 explicit Expression(CS
& File
) : _scope(NULL
) {
171 private: // expression-reduce.cc
172 void reduce_copy(const Expression
&);
174 explicit Expression(const Expression
&, const CARD_LIST
*);
176 bool as_bool()const { untested();
177 return (!is_empty() && back()->data());
180 const Float
* f
= dynamic_cast<const Float
*>(back()->data());
181 return ((f
&& size()==1) ? (f
->value()) : (NOT_INPUT
));
184 /*--------------------------------------------------------------------------*/
186 inline S
& operator<<(S
& out
, const Expression
& d
) {d
.dump(out
); return out
;}
187 /*--------------------------------------------------------------------------*/
189 // vim:ts=8:sw=2:noet: