6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Sep 21, 2024 9:29 pm

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: a little interpreter
PostPosted: Tue Jan 20, 2015 11:24 am 
Offline

Joined: Sat Dec 08, 2012 8:29 pm
Posts: 62
hi guys
i have coded a little-interpreter, which i wanted to call "L"

"L" stands for "Little", it is a very small interpreter similar to pascal, it can be useful for scripting in robotic, embedded and non-embedded applications.

It is written in C++, a port in C is available (i have to upload new sources), and it has been tested on x86-32, x86-64, powerpc, arm, ultrasparc, HP-PA and blackfin processors and is easy to port to new targets.

Very alpha stage, but ... it will be improved. It may be useful to learn something about "interpreter".

enjoy!


Top
 Profile  
Reply with quote  
 Post subject: Re: a little interpreter
PostPosted: Mon Feb 09, 2015 4:30 pm 
Offline

Joined: Sat Dec 08, 2012 8:29 pm
Posts: 62
i added few examples


Code:
Program factorial
Begin
    Input n
    factorial = 1
    While n > 1
    Begin
        factorial = factorial * n
        n = n - 1
    End
    Output factorial
End


Code:
Program test_prime
Begin
   Input n
   c = 2
   is_prime = 1
   While (c < n / 2) & is_prime
   Begin
      If n % c == 0
      Begin
         is_prime = 0
      End
      c = c + 1
   End
   Output is_prime
End


Top
 Profile  
Reply with quote  
 Post subject: Re: a little interpreter
PostPosted: Tue Apr 14, 2015 11:09 am 
Offline

Joined: Sat Dec 08, 2012 8:29 pm
Posts: 62
i added a sub-repo with a standalone project about a mini calculator


Top
 Profile  
Reply with quote  
 Post subject: Re: a little interpreter
PostPosted: Tue Jul 28, 2015 12:45 pm 
Offline

Joined: Sat Dec 08, 2012 8:29 pm
Posts: 62
any comment ?


Top
 Profile  
Reply with quote  
 Post subject: Re: a little interpreter
PostPosted: Tue Jul 28, 2015 1:21 pm 
Offline

Joined: Wed Jan 08, 2014 3:31 pm
Posts: 578
Isn't code.google.com going away? You might need to find a new repository.

See http://google-opensource.blogspot.com/2015/03/farewell-to-google-code.html

I'll take a look at your code to see if I can learn anything new about interpreter design. But personally I think I'd prefer something like Forth for robotics on a 6502 due to system constraints.

Update: After a quick look you would need a way to address raw memory for it to be useful on something like a 6502 or microcontroller. The reason is that most I/O peripherals are memory mapped and in BASIC you use PEEK and POKE to manipulate them. So to achieve similar utility you'll need those keywords.


Top
 Profile  
Reply with quote  
 Post subject: Re: a little interpreter
PostPosted: Wed Jul 29, 2015 12:29 pm 
Offline

Joined: Sat Dec 08, 2012 8:29 pm
Posts: 62
I might implement these features :D

actually I am working on advanced lexer, planning to support an advanced interpreter (with functions, type checking, etc)

Code:
# eval 1+(2.2*3.0E9+ ( 0xdeadbeaf logicalAnd 0xffffffff ) )

yards analysis: PASSED
stack analysis: PASSED

rpn_v[]={ 0 3 5 4 8 10 9 6 1 }

[1] 1 token_DecValue, type12
[2.2] 1 token_FloatinPointENGValue, type15
[3.0E9] 1 token_FloatinPointSCIValue, type16
[*] -1 token_Asterisk, type55
[0xdeadbeaf] 1 token_HexValue, type13
[0xffffffff] 1 token_HexValue, type13
[logicalAnd] -1 token_LogicalAnd, type41
[+] -1 token_Plus, type53
[+] -1 token_Plus, type53

#########################
#    good expression    #
#########################


Code:
# eval 1.1 + 2.2 * 3.0E9

yards analysis: PASSED
stack analysis: PASSED

rpn_v[]={ 0 2 4 3 1 }

[1.1] 1 token_FloatinPointENGValue, type15
[2.2] 1 token_FloatinPointENGValue, type15
[3.0E9] 1 token_FloatinPointSCIValue, type16
[*] -1 token_Asterisk, type55
[+] -1 token_Plus, type53

#########################
#    good expression    #
#########################


Code:
# eval 1+2+

yards analysis: PASSED
stack analysis: FAILED

#########################
#    bad  expression    #
#########################


Code:
# eval 1+2+(2+3

Error: parentheses mismatched/case1

yards analysis: FAILED
stack analysis: PASSED

#########################
#    bad  expression    #
#########################


Code:
# eval Fa(Fb(1,2,3,4,5),Fc(6,7,8,9),0)

yards analysis: PASSED
stack analysis: PASSED

function_pool has 3 functions
 + function1 [Fa] { typeRet typeRet type12 } 3 args
 + function2 [Fb] { type12 type12 type12 type12 type12 } 5 args
 + function3 [Fc] { type12 type12 type12 type12 } 4 args

rpn_v[]={ 4 6 8 10 12 2 17 19 21 23 15 26 0 }

[1] 1 token_DecValue, type12
[2] 1 token_DecValue, type12
[3] 1 token_DecValue, type12
[4] 1 token_DecValue, type12
[5] 1 token_DecValue, type12
[Fb] -4 token_StrictAlphaNum, type19
[6] 1 token_DecValue, type12
[7] 1 token_DecValue, type12
[8] 1 token_DecValue, type12
[9] 1 token_DecValue, type12
[Fc] -3 token_StrictAlphaNum, type19
[0] 1 token_DecValue, type12
[Fa] -2 token_StrictAlphaNum, type19

#########################
#    good expression    #
#########################


I am considering the RPN method as the hypothetical way to transform a math expression into machine opcodes, crazy idea for AS. I do not like methods like Recursive Descent.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 16 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: