#### Tomaaz

• Sr. Member
• Posts: 322
« Reply #15 on: 17. January 2019, 14:45:21 »
If you manage to learn something beyond BASIC it may actually destroy your bad reputation.

#### Aurel

• Regular Member
• Hero Member
• Posts: 504
« Reply #16 on: 17. January 2019, 15:09:08 »
Quote
If you manage to learn something beyond BASIC it may actually destroy your bad reputation

As i said before i will continue with C api programming
and testing some lexers/parsers ...this can help me to improve some things,
..and continue to work on my own editor in Oxygen Basic...

#### Tomaaz

• Sr. Member
• Posts: 322
« Reply #17 on: 18. January 2019, 17:47:25 »
Is a new chapter coming soon?

#### Aurel

• Regular Member
• Hero Member
• Posts: 504
« Reply #18 on: 14. February 2019, 23:50:04 »
maybe...

Code: [Select]
`'recursive descent token evaluator#lookaheadint tc=0 : string tokenstring tokens[5]tokens[1] = "2"tokens[2] = "+"tokens[3] = "3"tokens[4] = "*"tokens[5] = "4"sub gettok(){tc++token = tokens[tc]}sub expr() as float{float v = term()if token = "+": gettok() : v = v + term(): end ifif token = "-": gettok() : v = v - term(): end ifreturn v}sub term() as float{float v = factor()if token = "*": gettok() : v = v * factor(): end ifif token = "/": gettok() : v = v / factor(): end ifreturn v}sub factor() as float{if asc(token)>47  and asc(token)<58 float v = val(token)end ifgettok()return v}'exec-----------------gettok() 'startfloat res = expr()print str res`

#### Aurel

• Regular Member
• Hero Member
• Posts: 504
« Reply #19 on: 15. February 2019, 12:27:04 »
and this one with parens

Code: [Select]
`'recursive descent token evaluator#lookaheadint tc=0 : string tokenstring tokens[7]tokens[1] = "2"tokens[2] = "*"tokens[3] = "("tokens[4] = "3"tokens[5] = "+"tokens[6] = "4"tokens[7] = ")"sub gettok()tc++ : token = tokens[tc]end subsub expr() as floatfloat v = term()if token = "+": gettok() : v = v + term(): end ifif token = "-": gettok() : v = v - term(): end ifreturn vend subsub term() as floatfloat v = factor()if token = "*": gettok() : v = v * factor(): end ifif token = "/": gettok() : v = v / factor(): end ifreturn vend sub sub factor() as floatfloat vif asc(token)>47  and asc(token)<58 'numsv = val(token) : gettok()end ifif asc(token)=40 and asc(token)<>41 'match (...)gettok() : v = expr() : gettok()end ifreturn vend sub'exec-----------------gettok() 'startfloat res = expr()print str res`

#### Aurel

• Regular Member
• Hero Member
• Posts: 504
« Reply #20 on: 16. February 2019, 10:52:18 »
and tiny tokenizer

Code: [Select]
`'microB tokenizerint tkNULL=0,tkPLUS=1,tkMINUS=2,tkMULTI=3,tkDIVIDE=4int tkCOLON=5,tkCOMMA=6,tkLPAREN=7,tkRPAREN=8,tkLBRACKET=9,tkRBRACKET=10int tkPRINT=11,tkDOT=12,tkLINE=13,tkCIRCLE=14 ,tkEOL = 20string tokList[256] : int typList[256]   'token/type arraysint start , p = 1 ,start = p ,tp ,n      'initstring code,ch,tk ,crlf=chr(13)+chr(10),bfcode = "var1 + 2.5 " ' test or load_src?sub tokenizer(src as string) as int 'ch = mid(src,p,1) : print "CH:" + ch' get first charwhile p <= len(src)             ch = mid(src,p,1)                    'get char If asc(ch)=32 : p++ : end if             'skip blank space             If (asc(ch)>96 and asc(ch)<123)          ' [a-z]       print "CH2:" + ch : p--   while (asc(ch)>96 and asc(ch)<123) or (asc(ch)>47 and asc(ch)<58) ' [a-z0-9]*       p++:ch = mid(src,p,1) : print "AZ:" + ch        tk =tk+ch      wend      print "TOK-AZ:" + tk       tp++ : tokList[tp] = tk : tk="" :p++              'return IDENT; Elseif (asc(ch)>47 and asc(ch)<58)                    ' [0-9] p--    while (asc(ch)>47 and asc(ch)<58) or (asc(ch)=46)  '[0-9[0.0]]*        p++ : ch = mid(src,p,1):tk = tk + ch     wend       tp++ : tokList[tp] = tk : tk="":p++       'return NUMBER; Elseif asc(ch)=43                                     ' [ + ]       tk = ch : tp++ : tokList[tp] = tk : tk="" :p++  ' set_token      'elseif...  End ifwendreturn tpend sub'call tokenizer..tested(ident,numbers)int tn: tn = tokenizer(code) : print "number of tokens:" + str(tn)for n = 1 to tn : bf = bf + tokList[n] + crlf : next nprint  bf`
« Last Edit: 18. March 2019, 12:48:06 by Aurel »

• Sr. Member
• Posts: 322