Jump to content
  • Advertisement
Sign in to follow this  
Javelin

Compiler construction issues

This topic is 4832 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!