vishapoberon / compiler

vishap oberon compiler
http://oberon.vishap.am
GNU General Public License v3.0
186 stars 25 forks source link

Wrong Position when error occured #89

Open PizzaPablo666 opened 4 years ago

PizzaPablo666 commented 4 years ago
MODULE Postfix;
  IMPORT Texts, Oberon;
  VAR ch: CHAR;
    W: Texts.Writer; R: Texts.Reader;

PROCEDURE expression;
  VAR addop: CHAR;

PROCEDURE term;
  VAR mulop: CHAR;

PROCEDURE factor;
BEGIN
  IF ch = "(" THEN
    Texts.Read(R, ch);  expression;
    WHILE ch # ")" DO Texts.Read(R, ch) END
  ELSIF ch = "[" THEN
    Texts.Read(R, ch);    expression;
    WHILE ch # "]" DO Texts.Read(R, ch) END
  ELSE
    WHILE (ch < "a") OR (ch > "z") DO Texts.Read(R,ch) END ;
    Texts.Write(W,ch)
  END;
  Texts.Read(R, ch)
END factor;

BEGIN (*term*) factor;
  WHILE (ch = "*") OR (ch = "/") DO
    mulop := ch; Texts.Read(R, ch); factor; Texts.Write(W, mulop)
  END
END term;

BEGIN (*expression*) term;
  WHILE (ch = "+") OR (ch = "-") DO
    addop := ch; Texts.Read(R, ch); term; Texts.Write(W, addop)
  END
END expression;

PROCEDURE Parse;
BEGIN Texts.OpenReader(R, Oberon.Par.text, Oberon.Par.pos); Texts.Read(R, ch);
  WHILE ch # "~" DO
    expression; Texts.WriteLn(W); Texts.Append(Oberon.Log, W.buf);
    Texts.Read(R, ch)
  END
END Parse;

BEGIN Texts.OpenWriter(W);
  factor;
END Postfix.

In the last Procedure "main" in penultimate line of the code when I try to call factor which is local procedure of term procedure and can't be called, I have an error message:

Postfix.Mod  Compiling Postfix.

  48:   factor;
             ^
    pos  1046  err 0  undeclared identifier

Module compilation failed.

Correct line, but wrong position in the error message.

PizzaPablo666 commented 4 years ago

The code is from PIO : https://inf.ethz.ch/personal/wirth/Oberon/PIO.pdf ,page 36 , with some changes as you can see. I guess It is showing the position of the error from the whole file, not the line.

dcwbrown commented 4 years ago

That's right, pos is the value you would pass to Oberon's Files.Set(VAR r: Rider; f: File; pos: INT32).