[09 Sep 2008] How to manage a tree data structure?
-
- Posts: 14
- Joined: Tue Feb 16, 2010 7:11 pm
- Location: Rome
- Contact:
[18 Sep 2008] Re: Re: How to manage a tree data structure?
Note: This is an archived post that was originally sent to the Hollywood mailing list on Thu, 18 Sep 2008 00:18:45 +0200
Yes, I can explain the reasons for my choice... an hasty choice! When I planned my work I felt (perhaps wrongly) that it was easier to write the parser for expressions written in the normal way rather than write both the conversion function in Polish notation and the parser for this notation. On the other hand I found that the brackets were not a big problem.
I have a table that contains all operators (including parentheses), for each of them is also specified the level of precedence.
The parser receives a list of all the tokens that represent the source code, which I analyze one at a time using the following rough rules:
- When I encounter an opened parenthesis I simply insert it into the syntactic tree.
- When I encounter a closed parenthesis then I "climb" the syntactic tree until its opened parenthesis, then I replace the "opened" with the "closed" one.
- The next operator will take the place of that closed parenthesis.
I do not know if I was able to explain it properly, but I can post here a portion of the source code... even if it could be more cryptic of my words!
In any case, now the system works well for the expressions that we considered. Now I'm implementing the functions call mechanism and in this case the brackets are used to define the parameters list.
regards Paolo.
Yes, I can explain the reasons for my choice... an hasty choice! When I planned my work I felt (perhaps wrongly) that it was easier to write the parser for expressions written in the normal way rather than write both the conversion function in Polish notation and the parser for this notation. On the other hand I found that the brackets were not a big problem.
I have a table that contains all operators (including parentheses), for each of them is also specified the level of precedence.
The parser receives a list of all the tokens that represent the source code, which I analyze one at a time using the following rough rules:
- When I encounter an opened parenthesis I simply insert it into the syntactic tree.
- When I encounter a closed parenthesis then I "climb" the syntactic tree until its opened parenthesis, then I replace the "opened" with the "closed" one.
- The next operator will take the place of that closed parenthesis.
I do not know if I was able to explain it properly, but I can post here a portion of the source code... even if it could be more cryptic of my words!
In any case, now the system works well for the expressions that we considered. Now I'm implementing the functions call mechanism and in this case the brackets are used to define the parameters list.
regards Paolo.
- airsoftsoftwair
- Posts: 5433
- Joined: Fri Feb 12, 2010 2:33 pm
- Location: Germany
- Contact:
[20 Oct 2008] Re: How to manage a tree data structure?
Note: This is an archived post that was originally sent to the Hollywood mailing list on Mon, 20 Oct 2008 00:14:49 +0200
This code basically creates a file named "math.bin" and writes 4 simple Hollywood user functions into it. But: The functions are written as precompiled bytecode so neither the source code is exposed nor Hollywood's API because compiled bytecode can only be created by the Hollywood full version.
So, with ReadFunction() and WriteFunction() it should be possible to realize larger projects which dynamically need to run code that is loaded at specific occasions (like Paolo's game engine etc.)
I'm happy to annouce that I finally found a solution which can be used to dynamically load new code while Hollywood is running. In the next Hollywood version there will be two new functions called WriteFunction() and ReadFunction(). These allow to write Hollywood functions to files and load them again from files. Sounds cool, huh? It is Have a look at my litte test script:Ok. I will also try to see if there's a feasible way of allowing internal scripting without exposing Hollywood.
Code: Select all
/* BEGIN */
function coolmul(a, b)
return(a * b)
endfunction
function cooldiv(a, b)
return(a / b)
endfunction
function cooladd(a, b)
return(a + b)
endfunction
function coolsub(a, b)
return(a - b)
endfunction
openfile(1, "math.bin", #mode_write)
writefunction(1, coolmul, true)
writefunction(1, cooldiv, true)
writefunction(1, cooladd, true)
writefunction(1, coolsub, true)
closefile(1)
openfile(1, "math.bin", #mode_read)
mymul = readfunction(1)
mydiv = readfunction(1)
myadd = readfunction(1)
mysub = readfunction(1)
debugprint(mymul(2, 8), myadd(5, 4), mydiv(164, 2), mysub(7,7))
end
/* END */
So, with ReadFunction() and WriteFunction() it should be possible to realize larger projects which dynamically need to run code that is loaded at specific occasions (like Paolo's game engine etc.)
[20 Oct 2008] Re: How to manage a tree data structure?
Note: This is an archived post that was originally sent to the Hollywood mailing list on Mon, 20 Oct 2008 17:42:43 -0000
Really cool! This way if we have a huge lib and we only need one function we can use the ReadFunction fro what we need without waste memory
Fabio
Really cool! This way if we have a huge lib and we only need one function we can use the ReadFunction fro what we need without waste memory
Fabio
----------------------------
[Allanon] Fabio Falcucci | GitHub for recent works | Support me on Patreon for Hollywood libraries | ☆★ All my links ★☆
[Allanon] Fabio Falcucci | GitHub for recent works | Support me on Patreon for Hollywood libraries | ☆★ All my links ★☆
[20 Oct 2008] Re: How to manage a tree data structure?
Note: This is an archived post that was originally sent to the Hollywood mailing list on Mon, 20 Oct 2008 20:28:02 +0200
Hi all,
so even if you want the last function, you get it in only one readfunction call.
Hi all,
so if the file is really long, you have to use tons of readfunction calls. What about something like this: mymul = readfunction("coolmul")mymul = readfunction(1)
so even if you want the last function, you get it in only one readfunction call.
- TheMartian
- Posts: 109
- Joined: Sun Feb 28, 2010 12:51 pm
[20 Oct 2008] Re: How to manage a tree data structure?
Note: This is an archived post that was originally sent to the Hollywood mailing list on Mon, 20 Oct 2008 20:10:30 -0000
Hi
The ability to load functions certainly opens up some interesting possibilities and I for one look forward to 'try it out'...
Can you by any chance use this feature to overload a function as in dynamically replacing the same function again and again with a similarly named function that executes different code?
regards Jesper
Hi
The ability to load functions certainly opens up some interesting possibilities and I for one look forward to 'try it out'...
Can you by any chance use this feature to overload a function as in dynamically replacing the same function again and again with a similarly named function that executes different code?
regards Jesper
- airsoftsoftwair
- Posts: 5433
- Joined: Fri Feb 12, 2010 2:33 pm
- Location: Germany
- Contact:
[20 Oct 2008] Re: How to manage a tree data structure?
Note: This is an archived post that was originally sent to the Hollywood mailing list on Mon, 20 Oct 2008 23:19:58 +0200
Thus you can easily implement a more sophisticated way of function loading from file.
No, you don't have to. ReadFunction() is just the low-level function. You can of course implement it on top of a look up table which simply seeks to the file position where the function to be loaded resides, e.g.so if the file is really long, you have to use tons of readfunction calls.
Code: Select all
Function myReadFunc(fileid, section)
Local pos = myFindSection(fileid, section)
Seek(fileid, pos)
Return(ReadFunction(fileid))
EndFunction
See aboveWhat about something like this: mymul = readfunction("coolmul")
so even if you want the last function, you get it in only one readfunction call.
- airsoftsoftwair
- Posts: 5433
- Joined: Fri Feb 12, 2010 2:33 pm
- Location: Germany
- Contact:
[20 Oct 2008] Re: Re: How to manage a tree data structure?
Note: This is an archived post that was originally sent to the Hollywood mailing list on Mon, 20 Oct 2008 23:21:30 +0200
Of course. Actually, this is already possible, e.g.Hi
The ability to load functions certainly opens up some interesting possibilities and I for one look forward to 'try it out'...
Can you by any chance use this feature to overload a function as in dynamically replacing the same function again and again with a similarly named function that executes different code?
Code: Select all
subfunc = Function(a, b) Return(a - b) EndFunction
DebugPrint(subfunc(10, 2)) ; --> prints 8
subfunc = Function(a, b) Return(a + b) EndFunction
DebugPrint(subfunc(10, 2)) ; ---> prints 12
-
- Posts: 14
- Joined: Tue Feb 16, 2010 7:11 pm
- Location: Rome
- Contact:
[21 Oct 2008] Re: How to manage a tree data structure?
Note: This is an archived post that was originally sent to the Hollywood mailing list on Tue, 21 Oct 2008 13:01:10 +0200
First of all I thank you for your invaluable support, which will certainly make a difference on my work. This is an amazing feature! Now I've implemented almost all the text-based scripting system, but these functions may be very useful for future development since the author is already working on the sequel of the game. You talked about the "next Hollywood version", did you mean the next major version (like Hollywood 4) or we can already see it in the next update?
I also have two new exciting topics to be discussed here!
Thank you again! Paolo.
First of all I thank you for your invaluable support, which will certainly make a difference on my work. This is an amazing feature! Now I've implemented almost all the text-based scripting system, but these functions may be very useful for future development since the author is already working on the sequel of the game. You talked about the "next Hollywood version", did you mean the next major version (like Hollywood 4) or we can already see it in the next update?
I also have two new exciting topics to be discussed here!
Thank you again! Paolo.
- TheMartian
- Posts: 109
- Joined: Sun Feb 28, 2010 12:51 pm
[21 Oct 2008] Re: How to manage a tree data structure?
Note: This is an archived post that was originally sent to the Hollywood mailing list on Tue, 21 Oct 2008 18:06:05 -0000
Hi
So overloading is possible with the 'externally loaded' functions too like those coded in the source... nice! Does this mean that the 'old' externally loaded function gets garbage collected when replaced?
regards Jesper
Hi
So overloading is possible with the 'externally loaded' functions too like those coded in the source... nice! Does this mean that the 'old' externally loaded function gets garbage collected when replaced?
regards Jesper
- airsoftsoftwair
- Posts: 5433
- Joined: Fri Feb 12, 2010 2:33 pm
- Location: Germany
- Contact:
[21 Oct 2008] Re: How to manage a tree data structure?
Note: This is an archived post that was originally sent to the Hollywood mailing list on Tue, 21 Oct 2008 23:06:43 +0200
Yes, I'm talking about Hollywood 4. But it's not ready yet, but it will definitely come upFirst of all I thank you for your invaluable support, which will certainly make a difference on my work. This is an amazing feature! Now I've implemented almost all the text-based scripting system, but these functions may be very useful for future development since the author is already working on the sequel of the game. You talked about the "next Hollywood version", did you mean the next major version (like Hollywood 4) or we can already see it in the next update?