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!
a little interpreter
Re: a little interpreter
i added few examples
Code: Select all
Program factorial
Begin
Input n
factorial = 1
While n > 1
Begin
factorial = factorial * n
n = n - 1
End
Output factorial
End
Code: Select all
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
Re: a little interpreter
i added a sub-repo with a standalone project about a mini calculator
Re: a little interpreter
Isn't code.google.com going away? You might need to find a new repository.
See http://google-opensource.blogspot.com/2 ... -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.
See http://google-opensource.blogspot.com/2 ... -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.
Re: a little interpreter
I might implement these features 
actually I am working on advanced lexer, planning to support an advanced interpreter (with functions, type checking, etc)
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.
actually I am working on advanced lexer, planning to support an advanced interpreter (with functions, type checking, etc)
Code: Select all
# 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: Select all
# 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: Select all
# eval 1+2+
yards analysis: PASSED
stack analysis: FAILED
#########################
# bad expression #
#########################
Code: Select all
# eval 1+2+(2+3
Error: parentheses mismatched/case1
yards analysis: FAILED
stack analysis: PASSED
#########################
# bad expression #
#########################
Code: Select all
# 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 #
#########################