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
| type
TC_operateur = class(TObject)
class function IndefOfOperator(Operator: TC_operateur): TOperatorType;
function estprioritaire(Operator: TC_operateur): boolean;
end:
TC_plus = class(TC_operateur)
...
end;
TC_multiplie = class(TC_operateur)
...
end;
TC_operateur_Class = class of TC_operateur;
TOperatorType = (otnone, otmultiplie, otplus);
const
OPERATORS_RULES = array[TOperatorType] of TC_operateur_Class = (nil, TC_multiplie, TC_plus );
class function TC_operateur.IndefOfOperator(Operator: TC_operateur): TOperatorType;
begin
for Result := Low(TOperatorType) to High(TOperatorType)
if OPERATORS_RULES[Result] = Operator.ClassType then
Exit;
Result := otnone;
end;
function TC_operateur.estprioritaire(Operator: TC_operateur): boolean;
begin
Result := IndefOfOperator(Self) < IndefOfOperator(Operator);
// none à gérer au cas où
end; |
Partager