You are viewing a single comment's thread from:

RE: Writing a simple Compiler on my own - Function Semantics (part 1) [C][Flex][Bison]

in #utopian-io5 years ago

Another nice post, and great to see you progressing further through the compiler creation.
My advise for this time is you could probably have included more content into this session and possibly finalizing the semantics part.
How soon can we start seeing some of the real action of the compiler? at least maybe some unit tests of what has been created so far?
Screenshots with some results would be awesome!

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

Sort:  

Thank you! I can clearly see that you are enjoying this project!

  • Right now the compilation steps that are finished are only the Lexical Analysis (via the flex lexer) and Syntax Analysis (via the bison parser). The first one combined characters to form lexical units or tokens, whilst the second one combined those tokens to form the syntax
  • Semantic Analysis and all that follows from now on is much more complex and extending the previous steps by adding action code to the parser rules (mainly), that try to control more things about the language.
  • One of the things that occurs in all the steps is the Symbol Table that stores information about the identifiers that get's a somewhat final form after Semantic analysis is done :)

Right now, compiling the example file "full_example.c" we get messages, such as:



These messages are mainly for debugging purposes, to check if the compiler works as it should, but you can see that:

  • we are being informed about identifiers and if they are inserted to the symbol table for the first time or are just references.
  • if we are leaving a scope (function in our language) we get notified about which identifiers are being hidden etc.

    Some of the next articles will again be similar to today's article, cause we first have to create code that will be called as action code. Using the semantic code such as type checking, function declaration etc. in the actual compiler that we have right now, requires the introduction of attributes (attribute grammar), meaning that we will have to insert all the needed entries like data type, parameter etc. in a new structure that each non-terminal has. But, not all the non-terminals need all of these attributes! They don't have the same requirements of attributes and so we will end up creating an abstract syntax tree (AST), where the actual node can be of many types. But, all these types will be inter-compatible so that we can form a tree of node elements. The actual information/attributes will be stored in this AST, and together with the Symbol Table help us get into the final Machine Code Generation step.

I think I spoiled enough haha. We have a long road to take :)

Thank you for your review, @mcfarhat! Keep up the good work!

Coin Marketplace

STEEM 0.27
TRX 0.12
JST 0.031
BTC 57908.48
ETH 2913.17
USDT 1.00
SBD 3.61