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

You are viewing a single comment's thread from:

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

in utopian-io •  6 years ago  (edited)

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 :)

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!