Jump to content
  • Advertisement
Sign in to follow this  
chadsxe

Compiler talk....Parsing questions?

This topic is 4312 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

So I am still reading "Writing Compilers and Interpreters" as suggested by a few people on this board. Progress is slow but none the less it is progress. I am now reading into parsing and have run into a few questions. The book state that declarations provide more difficulty with parsing than expressions. My question obvisously would be why? If we allow initialization of a declaration, what additional work will be required by the parser?

Share this post


Link to post
Share on other sites
Advertisement
It is a good book, I thoroughly enjoyed the ending.

Declarations are a little more complicated because you need to deal with a definition and possible assignment in one go. I don't think it's a major issue and if you don't then cool, just get on with it ;)

Share this post


Link to post
Share on other sites
The book is good but it kills me how old the code is. So many outdated practices. Any thought on my second part of the question - If we allow initialization of a declaration, what additional work will be required by the parser?


Thanks

Chad

Share this post


Link to post
Share on other sites
In addition to initialization, you have to keep track of the name in a symbol table, and make sure you can resolve the proper symbol based on the scope of the block you are in. You can declare a global variable 'x', and then declare an 'x' inside a block, which will be used only inside that block.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
The book state that declarations provide more difficulty with parsing than expressions.


The other point, wich my lecturer missed entirely is that of 'inherited' atributes and 'synthesized' attributes. Consider these two ways to declare variables:

Pascal:

a, b, c: INTEGER

C:

int a, b, c;

Imagine you're doing LL (left reading, left reducing). In the pascal example you're reading variables from left to right, but you don't know the type is yet. So what do you do with the var names/labels? You have to keep track of them somewhere so you can pin the type on to them when you get to it.

In the C example, you know the type right away and can set the type attribute when you add it to the symbol table. Pascal: synthesized, C, inherited.

That's my understanding at least, if I'm wrong, please correct me!

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!