Wherever there's a forum, Aurel and Tomaaz will be there to argue
I've been missing it though, so keep it up!

A programming language written in naalaa
|
Wherever there's a forum, Aurel and Tomaaz will be there to argue
![]()
10-28-2018, 07:06 PM
Hi Marcus
I don't want to bothering you but something is not clear to me in your PROLAN inside procedure / function Signed factor. procedure SignedFactor() if nextType = CHARACTER if nextAsc = CHR_PLUS ' Not quite sure here ... _GetNext _Factor Why you not sure with calling GetNext or with Factor ? and i don't get it why you have SignedFactor and just Factor ? i have made recursive descent like this in 3 functions look in this as pseudo code and what you think about that option? 'fn expression ----------------------------------------------- function Expression() as Float float res if tokType = tNUM OR tokType = tVAR 'num or numeric variable if nextTokenType = tPLUS OR nextTokenType = tMINUS if tPLUS '(+) GetToken() ' get token from token list/array res = token + Term() elseif tMINUS '(-) GetToken() res = token - Term() end if end if end if return res end function 'term ------------------------------------------------------- function Term() as Float float res res = Factor() if nextTokenType = tMULTI OR nextTokenType = tDIVIDE if tMULTI '(*) GetToken() res = res * Factor() elseif tDIVIDE '(/) GetToken() res = res / Factor() end if end if return res end function 'factor ----------------------------------------------------- function Factor() as Float float res if tokType = tNUM return GetNum(token) end if if tokType = tVAR return GetVar(token) end if if tokType = tLParen '( Match("(") res = Expression() Match(")") end if 'else? return res ' from func->Expression() end function
Not quite sure about the naalaa version of prolan. It was a mess. Have a look at the C version instead (https://naalaa.com/jail/). Probably it looks even worse, haha
![]() ![]() I've actually had some good use of jail while helping my woman write scripts that needed to process files recursively and such. Could never have used naalaa for that, and in C (her preferred language besides assembler) it would have been a complete mess ![]()
05-09-2019, 06:40 PM
Yo Marcus
Just to let you know... you dont need two factor routines than just one is enough no matter what you use directly -tokens or bytcode. i do it in my new freak-show micro(A) interpreter like this: Code: '----------------------------------------------------- So, as you can see only three functions for expression evaluator. By the way, your NaaLaa version of Prolan is very clear and good.... ![]() all best !
05-10-2019, 09:26 AM
(05-09-2019, 06:40 PM)Aurel Wrote: Yo Marcus Thanks for the tip and code! I'll see if there's a reason for why I'm doing it the way I do. I probably did it that way when writing naalaa, for some dumb reason, and then I just mimiced that for jail.
07-05-2020, 07:49 AM
Yo Marcus
in prolan u use for while loop this : Code: * Marcus i don't see in your code any stack operation ,only sLoopScope-- , IS that mean that is not possible to have one while loop inside another? (07-05-2020, 07:49 AM)Aurel Wrote: Yo Marcus Long time since I wrote that code. But I'm pretty sure you can have loops within loops without any problem. The second loop executes recursively (in C) through ExecuteBlock. The internal "scopes" are used for creating keys that the memory manager uses for searching through recursive hash tables. For exampel, if you call a function from the main program: Code: myFunc = function(paramOne, paramTwo) { the scope will increase by one when the function call begins. So the keys for the parameters and local variabels are 1.paramOne, 1.param2, 1.localVarOne and 1.localVarTwo. If you made a recursive call inside myFunc: Code: myFunc = function(paramOne, paramTwo) { the second call would use the keys 2.paramOne, 2.paramTwo and so on, to differentiate them from the surrounding call. Note that for example 2.paramOne is not a single hash key. 2 is a hash key in the main memory that leads to another hash table, in which paramOne is a key. The memory manager breaks down the keys while searching the tables. I know, it's really stupid, but that's how it works ![]() You can download a fresh version of jail from here: https://naalaa.com/jail/jail.zip It's just a backup of my working folder, so it's probably filled with crap. Edit: And regarding scopes, only functions have their own scopes, loops do not. If you create a variable inside a loop, it will either belong to the main program or be local if you're inside a function. So, hm, its possible that sLoopScope is just used for error detection (functions use other scope variables) or it might be a left over from some experiment.
07-09-2020, 01:01 PM
Hi Marcus ..first thanks for reply and explanation
yeah ...i figured it when i looking into one Basic interpreter code on github. And no ,your is not crap at all, i investigate many sources on github and there you can find a lot of craps ..really beleive it or not ..of course there are also a really great open source interpreters published ,some of them are so damn complex that someone who looking first time in it must be totally confused. see yaa.. ![]() |
« Next Oldest | Next Newest »
|