|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Does anyone has any kind of resources about creating compilers/interpreters ?
I just wanted to hv some exprience building this kind of software. I don't pretend to build anything complex, just very simple stuff. regards, idss |
|
#2
|
||||
|
||||
|
This is probably a good starting point:
http://www.oreilly.com/catalog/lex/
__________________
Up the Irons What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home. "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest Down with Sharon Osbourne Puzzle of the Month solved by Keath and KevinADC, superior perl programmers of the month |
|
#3
|
||||
|
||||
|
Have you learned about function pointers yet? I've written several (4+) interpreters using the following method:
Write up a list of all your commands. Keep them simple, and assembly-like. You'll want to figure out how you use variables here too. Create a function for each of your commands, all the functions need to have the same interface. (I use "void functionName(void)") Create an array of function pointers and point each element to each of your functions. This way, you're assigning a number to each function. Accept an array of integers (or unsigned chars) as the program, loop through each value and call the appropriate function pointer. The location in the program should be kept track of by a single variable, (I use "pc") the function advances this variable as needed, or moves it in the case of a branch. If a function requires a variable, pull it's identifier from the program. Example: Commands: assign v1 literal add v1 v2 (v2 added to v1) program written out: assign 1 100 (variable #1 = 100) assign 2 150 (variable #2 = 150) add 1 2 (add var#2 to var#1, var#1 now = 250) if the command "assign" is stored in cmds[0] and "add" is stored in cmds[1], then the above program would be stored as: 0,1,100,0,2,150,1,1,2 (this is your p-code) After you get your program working well this way, then you write the language translator. This can be simple if your code is assembly like, or complex if you want to allow variable names, functions, and other stuff. (variable names would be stored internally, then converted to a number later) I've used a couple of my interpreters without writting this step. They were used for small, embedded programs. (code embedded inside the data) At least, that's how I did it, I'm sure there's other ways. This does end up running REALLY fast though.
__________________
"Science is constructed of facts as a house is of stones. But a collection of facts is no more a science than a heap of stones is a house." - Henri Poincare Last edited by dog135 : October 15th, 2003 at 04:46 PM. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Software Design > Compiler/Interpreter resources |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|