4a081a07   
   From: z80eu@arcor.de   
      
   Sv. Broholm schrieb:   
   > On 20 Jan., 20:56, Peter Dassow wrote:   
   >   
   >> Unfortunately a new problem occurs:   
   >   
   >> TP 3 does not anything about a forward declaration of a function.   
   >> So if there are 3 functions like a(d), b(e) and c(f),   
   >> and a(d) uses b(e) inside, and b(e) uses c(f) inside,   
   >> but c(f) uses also a(c) inside, that's Catch22 if you can't use forward   
   >> declaration.   
   >   
   > Forward declaration does exist in TP3, and it is similar to FORWARD in   
   > TP4.   
   > Show us your code.   
   >   
   > Regards   
   > Svend   
      
   That's astounding... but here are the three functions (Eval, Factor and   
   Term):   
      
   [...]   
      
   FUNCTION Eval: Integer; FORWARD;   
      
   FUNCTION Factor: Integer;   
      
   VAR   
    word: String;   
    val: Integer;   
      
   BEGIN   
    word := GetWord;   
    val := 0;   
    IF Length(word)=0 THEN Error('Missing operand')   
    ELSE IF (word='.') OR (word='*') THEN val := locPtr   
    ELSE IF word='$' THEN val := locPtr   
    ELSE IF word='-' THEN val := -Factor   
    ELSE IF word='+' THEN val := Factor   
    ELSE IF word='~' THEN val := -Factor-1   
    ELSE IF word='(' THEN BEGIN   
    val := Eval;   
    RParen;   
    END   
    ELSE IF word='''' THEN BEGIN   
    IF Length(line)=0 THEN   
    Error('Missing operand')   
    ELSE BEGIN   
    val := Ord(line[1]);   
    Delete(line,1,1);   
    Expect('''');   
    END;   
    END   
    ELSE IF Pos(word[1],numeric)>0 THEN BEGIN   
    CASE word[Length(word)] OF   
    'O': val := EvalOct(Copy(word,1,Length(word)-1));   
    'D': val := EvalDec(Copy(word,1,Length(word)-1));   
    'H': val := EvalHex(Copy(word,1,Length(word)-1));   
    ELSE val := EvalDec(word);   
    END;   
    END   
    ELSE val := RefSym(word);   
      
    Factor := val;   
   END;   
      
      
   FUNCTION Term: Integer;   
      
   VAR   
    word: String;   
    val: Integer;   
    oldLine: String;   
      
   BEGIN   
    val := Factor;   
      
    oldLine := line;   
    word := GetWord;   
    WHILE (word='*') OR (word='/') OR (word='%') DO BEGIN   
    CASE word[1] OF   
    '*': val := val * Factor;   
    '/': val := val DIV Factor;   
    '%': val := val MOD Factor;   
    END;   
    oldLine := line;   
    word := GetWord;   
    END;   
    line := oldLine;   
      
    Term := val;   
   END;   
      
      
   FUNCTION Eval: Integer;   
      
   VAR   
    word: String;   
    val: Integer;   
    oldLine: String;   
      
   BEGIN   
    val := Term;   
      
    oldLine := line;   
    word := GetWord;   
    WHILE (word='+') OR (word='-') {OR (word='*') OR (word='/')} DO BEGIN   
    CASE word[1] OF   
    '+': val := val + Term;   
    '-': val := val - Term;   
    END;   
    oldLine := line;   
    word := GetWord;   
    END;   
    line := oldLine;   
      
    Eval := val;   
   END;   
      
      
   I will get always an error with TP3 (but not with TP4), regardless of   
   what order I use (what function comes first).   
      
   Regards   
    Peter   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|