[Oberon] Understanding ORS.Mod.txt

Srinivas Nayak sinu.nayak2001 at gmail.com
Sun Jun 12 20:35:02 CEST 2016


In

   PROCEDURE String;

     VAR i: INTEGER;

   BEGIN i := 0; Texts.Read(R, ch);

     WHILE ~R.eot & (ch # 22X) DO

       IF ch >= " " THEN

         IF i < stringBufSize-1 THEN str[i] := ch; INC(i) ELSE Mark("string too long") END ;

       END ;

       Texts.Read(R, ch)

     END ;

     str[i] := 0X; INC(i); Texts.Read(R, ch); slen := i

   END String;


we see

str[i] := 0X; INC(i); Texts.Read(R, ch); slen := i

Why slen is one more than the actual string length?
Am I missing something silly?


With thanks and best regards,

Yours sincerely,
Srinivas Nayak

Home: http://www.mathmeth.com/sn/
Blog: http://srinivas-nayak.blogspot.in/

On 06/12/2016 07:11 PM, Srinivas Nayak wrote:
> We see
>
>    PROCEDURE Ten(e: LONGINT): REAL;
>
>      VAR x, t: REAL;
>
>    BEGIN x := 1.0; t := 10.0;
>
>      WHILE e > 0 DO
>
>        IF ODD(e) THEN x := t * x END ;
>
>        t := t * t; e := e DIV 2
>
>      END ;
>
>      RETURN x
>
>    END Ten;
>
> Should it be, RETURN x * t ?
>
>
> With thanks and best regards,
>
> Yours sincerely,
> Srinivas Nayak
>
> Home: http://www.mathmeth.com/sn/
> Blog: http://srinivas-nayak.blogspot.in/
>
> On 06/12/2016 07:01 PM, Srinivas Nayak wrote:
>> Dear Friends,
>>
>> Finally I could gather my courage to read NW's compiler implementation.
>> Hope to get your help when I get doubts.
>>
>> In ORS.Mod.txt we see
>>
>>    PROCEDURE Mark*(msg: ARRAY OF CHAR);
>>
>>      VAR p: LONGINT;
>>
>>    BEGIN p := Pos();
>>
>>      IF (p > errpos) & (errcnt < 25) THEN
>>
>>        Texts.WriteLn(W); Texts.WriteString(W, "  pos "); Texts.WriteInt(W, p, 1); Texts.Write(W, " ");
>>
>>        Texts.WriteString(W, msg); Texts.Append(Oberon.Log, W.buf)
>>
>>      END ;
>>
>>      INC(errcnt); errpos := p + 4
>>
>>    END Mark;
>>
>> Why we did, errpos := p + 4 ?
>> How do I understand/interpret this?
>> I was thinking, it should be errpos := p + 1 ...
>> Kindly correct me.
>>
>>
>> With thanks and best regards,
>>
>> Yours sincerely,
>> Srinivas Nayak
>>
>> Home: http://www.mathmeth.com/sn/
>> Blog: http://srinivas-nayak.blogspot.in/


More information about the Oberon mailing list