aboutsummaryrefslogtreecommitdiffstats
path: root/element.h
blob: 25d903d373e36d2b7167445b190f09bf68ec558c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#ifndef INCLUDE_ELEMENT_H
#define INCLUDE_ELEMENT_H

// element.h
// Revision 1-jan-2005

#include "blassic.h"

#include <string>

class Element {
public:
	Element (ProgramPos ppos) :
		ppos (ppos)
	{ }
	void nextchunk () { ppos.nextchunk (); }
	void nextline () { ppos.nextline (); }
	ProgramPos getpos () const { return ppos; }
private:
	ProgramPos ppos;
};

class ForElement : public Element {
public:
	ForElement (const std::string & nvar, ProgramPos pos) :
		Element (pos),
		varname (nvar)
	{ }
	virtual ~ForElement () { }
	virtual bool next ()= 0;
	const std::string var () const
	{ return varname; }
	bool isvar (const std::string & nvar) const
	{ return varname == nvar; }
private:
	ForElement (const ForElement &); // Forbidden
	ForElement & operator = (const ForElement &); // Forbidden
	const std::string varname;
};

class ForElementNumber : public ForElement {
public:
	ForElementNumber (const std::string & nvar,
			ProgramPos pos,
			BlNumber initial, BlNumber nmax, BlNumber nstep);
protected:
	BlNumber * varaddr, max, step;
};

class ForElementNumberInc : public ForElementNumber {
public:
	ForElementNumberInc (const std::string & var, ProgramPos pos,
			BlNumber initial, BlNumber max, BlNumber step);
	bool next ();
};

class ForElementNumberDec : public ForElementNumber {
public:
	ForElementNumberDec (const std::string & var, ProgramPos pos,
			BlNumber initial, BlNumber max, BlNumber step);
	bool next ();
};

class ForElementInteger : public ForElement {
public:
	ForElementInteger (const std::string & nvar,
			ProgramPos pos,
			BlInteger initial, BlInteger nmax, BlInteger nstep);
protected:
	BlInteger * varaddr, max, step;
};

class ForElementIntegerInc : public ForElementInteger {
public:
	ForElementIntegerInc (const std::string & var, ProgramPos pos,
			BlInteger initial, BlInteger max, BlInteger step);
	bool next ();
};

class ForElementIntegerDec : public ForElementInteger {
public:
	ForElementIntegerDec (const std::string & var, ProgramPos pos,
			BlInteger initial, BlInteger max, BlInteger step);
	bool next ();
};

inline ForElementNumber * newForElementNumber (const std::string & var,
	ProgramPos pos, BlNumber initial, BlNumber max, BlNumber step)
{
	if (step >= 0.0)
		return new ForElementNumberInc (var, pos, initial, max, step);
	else
		return new ForElementNumberDec (var, pos, initial, max, step);
}

inline ForElementInteger * newForElementInteger (const std::string & var,
	ProgramPos pos, BlInteger initial, BlInteger max, BlInteger step)
{
	if (step >= 0)
		return new ForElementIntegerInc (var, pos, initial, max, step);
	else
		return new ForElementIntegerDec (var, pos, initial, max, step);
}

class RepeatElement : public Element {
public:
	RepeatElement (ProgramPos pos) :
		Element (pos)
	{ }
};

class WhileElement : public Element {
public:
	WhileElement (ProgramPos pos) :
		Element (pos)
	{ }
};

class LocalLevel {
public:
	LocalLevel ();
	LocalLevel (const LocalLevel & ll);
	~LocalLevel ();
	LocalLevel & operator= (const LocalLevel & ll);
	void addlocalvar (const std::string & name);
	void freelocalvars ();
private:
	class Internal;
	Internal * pi;
};

class GosubElement : public Element, public LocalLevel {
public:
	GosubElement (ProgramPos pos, bool is_polled) :
		Element (pos),
		is_gosub (true),
		is_polled (is_polled)
	{ }
	GosubElement (LocalLevel & ll) :
		Element (0),
		LocalLevel (ll),
		is_gosub (false),
		is_polled (false)
	{ }
	bool isgosub () const { return is_gosub; }
	bool ispolled () const { return is_polled; }
private:
	bool is_gosub;
	bool is_polled;
};


#endif

// End of element.h
Un proyecto texto-plano.xyz