Compiler construction issues

Started by
2 comments, last by Javelin 18 years, 8 months ago
Hi I'm working on my own type of scriping language and I use flex and bison to generate the parser. In the language one should not have to declare functions before they are used and/or one should not have to specify where any symbols/functions might be (e.g. #include, #use). This in not a problem as long as all code is in the same file (multiple passes of the AST), but since each file contain exactly one class there is a little problem. I.e. if I compile a class that depends on file (other class) that has not yet been built, the symbols of unbuilt class will not be recognised. My thoughts to solve this problem: 1. When parsing file1 and discovery that file2 is needed -> Halt parsing of file1 and start with file2. When file2 is done, start from where you left file1. * I tried to do this, but I suspect that I have to store/reset a number of parameters in flex/bison in order to get it to work. 2. Build a "preprocessor" that finds out in which order things should be compiled. * I do not think that this is a good solution since I can see a number of other potential problems with it. Does anyone have som input on the idéas or a solution to the problem itself. // Thanks
// Javelin// Assumption is the mother of all fuckups...
Advertisement
You could try and use some sort of make file that depicts the order in which files should be built. Another idea is use includes, i.e. include the class file that another file needs to use. You could try forward declarations. This would tell the parser that there is a class of that type waiting to be parsed, so allow the parsing of it.
I suggest you do a two-pass compilation system.

- First pass creates "interface" files for all your classes. The creation of those files ignores dependencies (they act like forward declarations).

- Second pass uses interface files to do whatever work it needs.
Hello

Thanks for the suggestions. However the whole point was that the user should not have to declare anything before use.

I sovlved it with something similar that ToohrVyk spoke of.
// Javelin// Assumption is the mother of all fuckups...

This topic is closed to new replies.

Advertisement