Not found ERROR

Started by Zlatko Vid, March 12, 2024, 08:45:50 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Zlatko Vid

Hi Charles

In which case o2 show this error ?

In my case this error occurs in tiny py-like interpreter
i want to translate to o2 code
telling me that function not found
BUT function exist of course ...so i
don't get it why o2 cannot see it or i do something wrong
i use 0.6.0 for this one...

i forget to try in old A043..

Zlatko Vid

sorry i forget to post code here it is :
so why is not found ? thanks

'min.py in o2 by Aurel / (c) 2022 Carsten Herting (slu4) *** MIT LICENSE ***
$filename "minpy.exe"
include "rtl32.inc"
#lookahead
'indexbase 1

'global vars...
int pc=0 : string variable[]  'program counter: identifier -> (type, value) lookup table
'get program
string source , e , fname
fname = "test.txt"
source = GetFile fname
print source


'...
sub Look() as string ' returns the current character while skipping over comments
string src = mid(source,pc,1) ' comments are entered by # and exited by \n or \0
if src = "#"
while src <> chr(10) and src <> chr(0): pc = pc + 1 : wend ' scan over comments here
     end if
return src
end sub
'...
sub Take() as string
      string c ' takes away and returns the current character
c = Look() : pc = pc + 1 : return c
end sub
'...
sub TakeString(string _word) as int ' returns whether a certain string could be taken starting at pc
int n : string c
int copypc = pc
for n = 1 to LEN(_word)
         c = mid(_word,n,1)
if Take() <> c : pc = copypc : return False : end if
    next n
    return True
end sub
'...
sub NextC() as string ' returns the next non-whitespace character
    string s
    while Look() = " " or Look() = chr(9) or Look() = chr(10) or Look() = chr(13) : wend
    s=Take()
    return Look()
end sub
'...
sub TakeNext(string c) as int ' eats white-spaces, returns whether a certain character could be eaten
     string s
if NextC() = c
       s=Take()
        return True
else
       return False
    end if
end sub   

sub IsDigit(string c) as int : return (c >= "0" and c <= "9") : end sub ' recognizers
sub IsAlpha(string c) as int : return ((c >= "a" and c <= "z") or (c >= "A" and c <= "Z")) : end sub
sub IsAlNum(string c) as int : return (IsDigit(c) or IsAlpha(c)) : end sub
sub IsAddOp(string c) as int : return (c = "+" or c = "-") : end sub
sub IsMulOp(string c) as int : return (c = "*" or c = "/") : end sub
'...
sub TakeNextAlNum() as string
string alnum = ""
if IsAlpha(NextC())
while IsAlNum(Look()): alnum = alnum + Take() : wend
     end if
return alnum
end sub
'...
sub BooleanFactor(int act) as int
 ' py code ->   inv = TakeNext('!') ; e = Expression(act);  b = e[1];  Next()
int inv = TakeNext("!")
    int b,b1,b2
   b1 = MathExpression(act)
    NextC()
   
'if (e[0] == "i"): '# a single mathexpression may also serve as a boolean factor
if TakeString("==") = true
               b2 =  MathExpression(act)
  elseif TakeString("!=") : b = (b != MathExpression(act))
  elseif TakeString("<=") : b = (b <= MathExpression(act))
  elseif TakeString("<")  : b = (b < MathExpression(act))
  elseif TakeString(">=") : b = (b >= MathExpression(act))
  elseif TakeString(">")  : b = (b > MathExpression(act))
else
      if TakeString("==") : b = (b = StringExpression(act))
     elseif TakeString("!="): b = (b <> StringExpression(act))
  else
              b = (b != val(""))
           end if
    end if
    ' end if

return b    'act[0] and (b != inv)
end sub
'...
sub BooleanTerm(int act) as int
int b = BooleanFactor(act)
while TakeNext("&") : b = b & BooleanFactor(act) : wend ' logical and corresponds to multiplication
return b
end sub
'...
sub BooleanExpression(int act) as int
int b = BooleanTerm(act)
while TakeNext("|"): b = b | BooleanTerm(act) : wend ' logical or corresponds to addition
return b
end sub

'....
sub MathFactor(int act) as int
int m = 0
If TakeNext("(") <> 0
int m = MathExpression(act)
If not TakeNext(")") : Error("missing ')'") : end if
elseif isdigit(NextC()) <> ""
While isdigit(Look()) : m = 10 * m + ord(Take()) - ord("0") : wend
elseif TakeString("val("):
s = StringC(act)
If act[0] And s.isdigit(): m = Int(s) : end if
If not TakeNext(')'): Error("missing ')'")
Else
ident = TakeNextAlNum()
If ident not in variable Or variable[ident][0] != "i" : Error("unknown variable") : end if
elseif act[0]
            m = variable[ident][1]
     End if
Return m
end sub
'....
sub MathTerm(int act) as int
int m = MathFactor(act)
While IsMulOp(NextC()) <> 0
c = Take()
        int m2 = MathFactor(act)
If c == "*"
             m = m * m2 ' multiplication
Else
             m = m / m2                           ' division
         End if
     Wend
Return m
end sub
'....
sub MathExpression(int act) as int
string c = NextC() '# check For an optional leading sign
If IsAddOp(c) <> 0 : c = Take() : end if
int m = MathTerm(act)
If c = "-":  m = -m : end if
While IsAddOp(NextC()) <> chr(0)
c = Take()
         int m2 = MathTerm(act)
If c = "+"
             m = m + m2 '# addition
Else
          m = m - m2                                   '# subtraction
         End if
     Wend  
Return m
end sub
'....

sub Expression(int act) as int
copypc = pc :
     string ident = TakeNextAlNum()
     pc = copypc                                             ' scan for identifier or "str"
if NextC() = "\"  or ident = "str"                        'or (ident in variable and variable[ident][0] == 's'):
return  StringExpression(act)                           '("s", StringExpression(act))
else
        return  MathExpression(act)                             '('i', MathExpression(act)
    end if
    return 0
end sub
'...



sub Program()
int act = True
'while NextC() <> chr(0) : Block(act) : wend
end sub

'def Error(text):




'start program...
Program()

Charles Pegge

Hi Aurel,

could you check your code in notepad (with the wordwrap turned off). There are some very long strange lines, which may be scrambling the code and disrupting #lookahead.

Zlatko Vid

Hi Charles
Yes i can of course ...uff i know that something is strange

Zlatko Vid

Dang ...
Troubles make "oh boy" python quotes 'var'
which is in Basic double quotes "var"  >:(

translation is always a nightmare  ::)

why i want to do that ...well we have lisp interpreter,toy interpreter
and i want that e have python -like interpreter too..
am I crazy  :o

Charles Pegge

Go for it!. At least Python is readable.

I dropped the Lisp and Scheme in more recent times because these languages are horrible to read, and our implementations were buggy. It's the lack of distinctive block structures that make them write-only languages.

Zlatko Vid

Fine Charles..
Yes Python is easier to read / understand what is what..i think too.
this one compile ,but i commented some lines because they need
more functions to be translated and in general code will be
little bit larger than original python code  ::)

'min.py in o2 by Aurel / (c) 2022 Carsten Herting (slu4) *** MIT LICENSE ***
$filename "minpy.exe"
include "rtl32.inc"
#lookahead
'indexbase 1

'global vars...'program counter: identifier -> (type, value) lookup table
int pc=0,copypc=0 : string variable[1024]
'get program
string source , e , fname
fname = "test.txt"
source = GetFile fname
print source


'...
' returns the current character while skipping over comments
sub Look() as string
string src = mid(source,pc,1)   
if src = "#"
while src <> chr(10) and src <> chr(0): pc = pc + 1 : wend
     end if
return src
end sub
'...
' takes away and returns the current character
sub Take() as string
      string c
c = Look() : pc = pc + 1 : return c
end sub
'...
' returns whether a certain string could be taken starting at pc
sub TakeString(string _word) as int
int n : string c
int copypc = pc
for n = 1 to LEN(_word)
         c = mid(_word,n,1)
if Take() <> c : pc = copypc : return False : end if
    next n
    return True
end sub
'...
' returns the next non-whitespace character
sub NextC() as string
    string s
    while Look() = " " or Look() = chr(9) or Look() = chr(10) or Look() = chr(13) : wend
    s=Take()
    return Look()
end sub
'...
'eats white-spaces, returns whether a certain character could be eaten
sub TakeNext(string c) as int
     string s
if NextC() = c
       s=Take()
        return True
else
       return False
    end if
end sub   
'...
sub IsDigit(string c) as int : return (c >= "0" and c <= "9") : end sub
sub IsAlpha(string c) as int : return ((c >= "a" and c <= "z") or (c >= "A" and c <= "Z")) : end sub
sub IsAlNum(string c) as int : return (IsDigit(c) or IsAlpha(c)) : end sub
sub IsAddOp(string c) as int : return (c = "+" or c = "-") : end sub
sub IsMulOp(string c) as int : return (c = "*" or c = "/") : end sub
'...
sub TakeNextAlNum() as string
string alnum = ""
if IsAlpha(NextC()) = true
while IsAlNum(Look()) = true : alnum = alnum + Take() : wend
     end if
return alnum
end sub
'...
'/*
sub BooleanFactor(int act) as int
 ' py code ->   inv = TakeNext('!') ; e = Expression(act);  b = e[1];  Next()
int inv = TakeNext("!")
    int b,b1,b2
   b1 = MathExpression(act)
    NextC() 
'if (e[0] == "i"):
if TakeString("==") = true
        b = (b1 = MathExpression(act))
elseif TakeString("!=") = true
        b = (b != MathExpression(act))
elseif TakeString("<=") = true
        b = (b <= MathExpression(act))
elseif TakeString("<") = true
        b = (b < MathExpression(act))
elseif TakeString(">=") = true
        b = (b >= MathExpression(act))
elseif TakeString(">") = true
        b = (b > MathExpression(act))
else
   if TakeString("==") = true
            'b = (b = StringExpression(act))
   elseif TakeString("!=") = true
           ' b = (b <> StringExpression(act))
  else
              b = (b != val(""))
       end if
    end if
    ' end if
return b    'act[0] and (b != inv)
end sub
'*/

'...
sub BooleanTerm(int act) as int
     int b
'int b = BooleanFactor(act)
'while TakeNext("&") = true : b = b & BooleanFactor(act) : wend
return b
end sub
'...
sub BooleanExpression(int act) as int
int b = BooleanTerm(act)
while TakeNext("|") = true : b = b | BooleanTerm(act) : wend
return b
end sub

'....
sub MathFactor(int act) as int
int m = 0 : string s,ident
If TakeNext("(") <> 0
'm = MathExpression(act)
'If not TakeNext(")") : Error("missing ')'") : end if

elseif isDigit(NextC()) = true
While isDigit(Look()) = true : m = 10 * m + val(Take()) - val("0") : wend

elseif TakeString("val(") = true
's = StringC(act)
'If act=0 And isDigit() = true : m = Int(s) : end if
'If not TakeNext(")"): Error("missing ')'") : end if

Else
ident = TakeNextAlNum()
'If ident not in variable Or variable[ident][0] != "i" : Error("unknown variable") : end if
elseif act = 0
            m = variable[1] = ident
     End if
Return m
end sub
'....
sub MathTerm(int act) as int
     string c=""
int m = MathFactor(act)
While IsMulOp(NextC()) <> 0
c = Take()
        int m2 = MathFactor(act)
If c == "*"
             m = m * m2
Else
             m = m / m2
         End if
     Wend
Return m
end sub
'....
sub MathExpression(int act) as int
string c = NextC()
If IsAddOp(c) <> 0 : c = Take() : end if
int m = MathTerm(act)
If c = "-":  m = -m : end if
While IsAddOp(NextC()) <> 0
c = Take()
         int m2 = MathTerm(act)
If c = "+"
             m = m + m2
Else
          m = m - m2
         End if
     Wend  
Return m
end sub
'....

sub Expression(int act) as int
copypc = pc :
     string ident = TakeNextAlNum()
     pc = copypc
if NextC() = "\"  or ident = "str"           
'return  StringExpression(act)                 
else
        return  MathExpression(act)
    end if
    return 0
end sub
'...

sub Program()
int act = True
'while NextC() <> chr(0) : Block(act) : wend
end sub

'start program...
Program()