Saturday, January 30, 2010

Semantic Analyzer

This post is continuation of my previous blog post regarding Compiler construction in which I had discussed "Lexical" and "Syntax" analyzer. In this post, I will discuss the Semantic Analyzer which gave me a really hard time during the semester. It was tougher than the previous 2 phases. For this phase, we were alloted one month (The whole of March).

The job of the Semantic Analyzer is to ensure that the code is semantically correct. In this phase, the compiler associates semantic information to the parse tree built during the Syntax Analysis phase and constructs Symbol Table. A Symbol Table holds information about identifiers in the source code regarding their declaration and location in the code. At this point, the code is syntactically correct and being checked for semantic errors such as type checking, object binding, assignment of local variables before use, etc.

Click here to download Semantic Analyser.zip file. Run JFlex tool over Scanner.txt file to generate a lexer file. Use 'byaccj' tool over CS-540Assignment_3.txt file to generate a parser file. Byaccj is a YACC-compatible parser generator tool that takes an input source file and produces one or more Java files. For detailed information about byaccj and its use, click here. The zip file also contains a README.txt file that contains step-by-step instructions for the user. You will need to download and install "byaccj1.15_win32" before proceeding with the third instruction. The test.txt file is a test file for testing the functionality of the Semantic Analyzer.

No comments:

Post a Comment