1 /**********************************************************
2  * Version $Id$
3  *********************************************************/
4 //#include <..\stdafx.h>
5 
6 #include "zuweisung.h"
7 
8 
9 using namespace std;
10 
BBZuweisung()11 BBZuweisung::BBZuweisung()
12 {
13 	typ = NoTyp;
14 	memset(&ZuArt, 0, sizeof(BBZuArt));
15 	memset(&ZuVar, 0, sizeof(BBZuVar));
16 }
17 
~BBZuweisung()18 BBZuweisung::~BBZuweisung()
19 {
20 	if (typ == NoTyp)
21 		return;
22 
23 	switch(typ)
24 	{
25 	case FTyp:
26 	case ITyp:
27 		if (ZuArt.IF != NULL)
28 			delete ZuArt.IF;
29 		break;
30 	case PTyp:
31 	case MTyp:
32 		if (ZuArt.MP != NULL)
33 			delete ZuArt.MP;
34 		break;
35 	case MIndex:
36 		if (ZuArt.MP != NULL)
37 //			delete ZuArt.MP;
38 			delete ZuArt.IF;
39 		if (ZuVar.MatrixIndex.PVar != NULL)
40 			delete ZuVar.MatrixIndex.PVar;
41 		break;
42 	}
43 	typ = NoTyp;
44 	memset(&ZuArt, 0, sizeof(BBZuArt));
45 	memset(&ZuVar, 0, sizeof(BBZuVar));
46 }
47 
48 
49 // Verarbeitung der einzelnen Zeilen
isZuweisung(const string & statement,BBZuweisung * & Z)50 bool isZuweisung(const string& statement, BBZuweisung *&Z)
51 {
52 	// Syntax: Variablen-Name = Audruck
53 	if (statement.empty())
54 		return false;
55 	string s(statement);
56 	int pos = s.find_first_of('=');
57 	if (pos <= 0)
58 		return false;
59 
60 	// erster Substring mu� Variablen-Name sein
61 	BBZuweisung::BBZuweisungTyp t;
62 	BBMatrix *bbm;
63 	BBBaumMatrixPoint *bbp;
64 	string sub1 = s.substr(0, pos);
65 	trim(sub1);
66 	BBTyp *b = isVar(sub1);
67 	if (b == NULL)
68 	{
69 		// �berpr�fen, ob erster Token ein MatrixIndex (M[p]) ist
70 		if (!isMatrixIndex(sub1, bbm, bbp))
71 			return false;
72 		else
73 			t = BBZuweisung::MIndex;
74 	}
75 
76 	string sub2 = s.substr(pos+1);
77 	trim(sub2);
78 	if (sub2.empty())
79 		return false;
80 
81 	if (b != NULL)
82 	{
83 		// Typ herausfinden
84 		switch (b->type)
85 		{
86 		case BBTyp::IType:
87 			t = BBZuweisung::ITyp;
88 			break;
89 		case BBTyp::FType:
90 			t = BBZuweisung::FTyp;
91 			break;
92 		case BBTyp::MType:
93 			t = BBZuweisung::MTyp;
94 			break;
95 		case BBTyp::PType:
96 			t = BBZuweisung::PTyp;
97 			break;
98 		}
99 	}
100 	if (t == BBZuweisung::PTyp || t == BBZuweisung::MTyp)
101 	{
102 		BBBaumMatrixPoint *k = NULL;
103 		try
104 		{
105 			pars_matrix_point(sub2, k, /*false*/ t == BBZuweisung::MTyp);
106 		}
107 		catch (BBFehlerException)
108 		{
109 			return false;
110 		}
111 		Z = new BBZuweisung;
112 		Z->typ = t;
113 		if (t == BBZuweisung::PTyp)
114 			Z->ZuVar.PVar = getVarP(b);
115 		else
116 			Z->ZuVar.MVar = getVarM(b);
117 		try
118 		{
119 			pars_matrix_point(sub2, Z->ZuArt.MP, /*false*/t == BBZuweisung::MTyp);
120 		}
121 		catch (BBFehlerException)
122 		{
123 			return false;
124 		}
125 	}
126 	else if (t == BBZuweisung::ITyp || t == BBZuweisung::FTyp)
127 	{
128 		BBBaumInteger *k = NULL;
129 		try
130 		{
131 			pars_integer_float(sub2, k, false);
132 		}
133 		catch (BBFehlerException)
134 		{
135 			return false;
136 		}
137 		Z = new BBZuweisung;
138 		Z->typ = t;
139 		if (t == BBZuweisung::ITyp)
140 			Z->ZuVar.IVar = getVarI(b);
141 		else
142 			Z->ZuVar.FVar = getVarF(b);
143 		try
144 		{
145 			pars_integer_float(sub2, Z->ZuArt.IF);
146 		}
147 		catch (BBFehlerException)
148 		{
149 			return false;
150 		}
151 	}
152 	else if (t == BBZuweisung::MIndex)
153 	{
154 		Z = new BBZuweisung;
155 		Z->typ = t;
156 		Z->ZuVar.MatrixIndex.PVar = bbp;
157 		Z->ZuVar.MatrixIndex.MVar = bbm;
158 		try
159 		{
160 			pars_integer_float(sub2, Z->ZuArt.IF);
161 		}
162 		catch (BBFehlerException)
163 		{
164 			return false;
165 		}
166 	}
167 	return true;
168 }
169