Frank Heckenbach a écrit :
Maurice Lombardi wrote:
It seems that operators pow and ** cannot be redefined in gpc. Is that expected ?
No, they should be. I think adding them in parse.y:operator_identifier should do the trick, but there's a comment stating exactly that this "is unnecessary". Seems it is necessary, but since I don't know the real meaning of this comment, I'll leave this to Peter... (maur7.pas)
With today snapshot (20001214) pow and shl work as expected, but ** compiles but fails when using it with a message:
operatordemo.pas: In function `pascal_main_program': operatordemo.pas:49: left operand of `**' must be of integer, real or complex type
The test program is just an expansion of operatordemo:
------------------------------------------------------ program OperatorDemo;
type Vector3 = record x, y, z: Real; end;
var a, b, c: Vector3 = (1, 2, 3);
operator + (u, v: Vector3) w: Vector3; begin w.x := u.x + v.x; w.y := u.y + v.y; w.z := u.z + v.z; end;
operator pow (u: Vector3; v: integer) w: Vector3; begin w.x := u.x pow v; w.y := u.y pow v; w.z := u.z pow v; end;
operator shl (u: Vector3; v:integer) w: Vector3; begin w.x := round(u.x) shl v; w.y := round(u.y) shl v; w.z := round(u.z) shl v; end;
operator ** (u: Vector3; v:real) w: Vector3; begin w.x := u.x ** v; w.y := u.y ** v; w.z := u.z ** v; end;
begin c := a + b ; writeln(c.x,' ',c.y,' ',c.z);
c := a pow 3; writeln(c.x,' ',c.y,' ',c.z);
c := a shl 2; writeln(c.x,' ',c.y,' ',c.z);
c := a ** 2.5; (* WRONG *) writeln(c.x,' ',c.y,' ',c.z);
readln;
end. ------------------------------------------------
Hope this helps
Maurice