Post Reply 
Social Buttons
 
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Aritmetic evaluator - FB
04-26-2018, 05:05 AM (This post was last modified: 04-26-2018 05:08 AM by Aurel.)
Post: #11
RE: Aritmetic evaluator - FB
Quote:Show me your tokens and then pseudo code to process:
Code:
if a = b then
x = 4
y = 2
else
x = 3
y = 1
end if

my tokens (in array)now look like this :

IF - keyword (2)
a - ident(3)
= - opEqual(4)
b - ident (3)
then - keyword(5)
x - ident(3)
= - opEqual(4)
...
...

that is what i have in plan to do..
also put all that in ANI script program to be more interactive..
or more transparent ..

I not finish completely tokenizer but should be like this
but i have in plan two arrays
first hold tokens(strings)
second hold tokenTyps(integers)
Is that good?
Find all posts by this user
Quote this message in a reply
04-26-2018, 08:35 AM
Post: #12
RE: Aritmetic evaluator - FB
now i see what is quads
i think on something similar
in fact few days back i have started with this one:

Code:
'Parser -Eval -o2- by Aurel 2018
$ filename "ParseEval.exe"
#lookahead
string token,crlf= chr(13)+chr(10),buff
'test expression -> 2+3*4
string TokenList[] = {"2","+","3","*","4"}
string OperatorList[] = {"-","+","*","/","^","("} '6
string op
'get size of list?
print spanof(TokenList) ' size of array -> 5 ...count of tokens
int tokCount = spanOf(TokenList)
int prec
string opStack
string opPLUS,opMULTI
string cell
'
'loop trough tokens
For t = 1 to tokCount
    token = TokenList[t]
     If instr("+-*/^(",token) <> 0
     op = token
print "OP:"  + op
     End if
  
        if token <> op
            buff = buff + tokenlist[t]
        end if  
     'select token
        'case "("
        '.........................
        'case "^"
        '.........................
        'case "/"
         '..........................
        if token = "*"
            buff = buff + tokenlist[t] + crlf
        end if
                
        '.........................
        if token = "+"
            buff = buff + tokenlist[t]  + crlf
         end if
        '.........................
        
     'end select



    'buff = buff + token

    'print "BUFF: " buff + "  N:" + str(t)
    
     ' i instr(token,"+-*/^(",op) = 0
          'buff = buff + token + crlf
      'end if

Next t
'show operator buffer
print buff

is not very much but as product i get this:


Attached File(s) Image(s)
   
Find all posts by this user
Quote this message in a reply
04-26-2018, 10:29 PM
Post: #13
RE: Aritmetic evaluator - FB
small update
using byte op at strptr(token)

Code:
'Parser -Eval -o2- by Aurel 2018
$ filename "ParseEval.exe"
#autodim off
'#lookahead

string op,token,crlf= chr(13)+chr(10)
bstring buff
'test expression -> 2+3*4
string TokenList[] = {"2","+","3","*","4"}
'TokenList[1]="2"
'TokenList[2]="+"
'TokenList[3]="3"
'TokenList[4]="*"
'TokenList[5]="4"
'string OperatorList[] = {"-","+","*","/","^","("} '6
'get size of list?
print spanof(TokenList) ' size of array -> 5 ...count of tokens
int tokCount = spanOf(TokenList)
int prec
string opStack
string opPLUS,opMULTI
string cell
'
'loop trough tokens
int t
For t = 1 to tokCount
    token = TokenList[t]
    
     If instr("+-*/^(",token) <> 0
       op = token
        print "OP:"  + op
     End if  
        if token <> op
            buff = buff + tokenlist[t]
        end if
   byte op at strptr(token) 'must be before select
     select op
        case "("
            buff = buff + tokenlist[t] + crlf
        '......................................
        case "^"
            buff = buff + tokenlist[t] + crlf
        '......................................
        case "/"
            buff = buff + tokenlist[t] + crlf
         '.....................................
        case "*"
            buff = buff + tokenlist[t] + crlf                
        '......................................
        case "+"
            buff = buff + tokenlist[t]  + crlf        
        '......................................
        
     end select



    'buff = buff + token

    'print "BUFF: " buff + "  N:" + str(t)
    
     ' i instr(token,"+-*/^(",op) = 0
          'buff = buff + token + crlf
      'end if

Next t
'show operator buffer
print buff
buff=NULL
print "OK"


Attached File(s) Image(s)
   
Find all posts by this user
Quote this message in a reply
04-27-2018, 12:17 AM
Post: #14
RE: Aritmetic evaluator - FB
One easy to follow written in Java called
ImageJ interpreter is open source.
The way how is created looking very simple to translate to basic
(ithink) ?

https://imagej.nih.gov/ij/source/ij/macr...reter.java
Find all posts by this user
Quote this message in a reply
04-30-2018, 02:03 AM
Post: #15
RE: Aritmetic evaluator - FB
Hallo Ed
if you visit this forum
What you think about this schematic of evaluation.


Attached File(s) Image(s)
   
Find all posts by this user
Quote this message in a reply
05-06-2018, 05:43 AM
Post: #16
RE: Aritmetic evaluator - FB
I was thinking about some things..
In fact for simple token evaluator we need just to
re-arange expression to get proper precedence
something like sorting algorythm
but sorting algo which know how to sort by operator precedence
If there are some similar sorting algo - let me know?
I have some ideas how to do that but are still "on the paper"
also triples & quads are interesting way for parsing expressions too.
Find all posts by this user
Quote this message in a reply
07-10-2018, 04:53 AM
Post: #17
RE: Aritmetic evaluator - FB
I hope that I will find time for programming ...
Find all posts by this user
Quote this message in a reply
07-11-2018, 10:12 PM
Post: #18
RE: Aritmetic evaluator - FB
(07-10-2018 04:53 AM)Aurel Wrote:  I hope that I will find time for programming ...

I hope you will too! I miss talking about compilers, interpreters, expression evaluaters, parsing, lexing and so forth!
Find all posts by this user
Quote this message in a reply
07-12-2018, 03:36 AM
Post: #19
RE: Aritmetic evaluator - FB
Hi Ed ...
Smile
Quote: I miss talking about compilers....

yeah i miss too...
i was out of internet about month or more due to
local freakin problems with conections do you can
believe and still is not fixed properly then
i have lot of work outside of house ...you know LIFE...
i hope that i will back soon ...
cheers
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: