The semantic analyzer is the last part of the front
end of a compiler. Before the compiler can produce an executable version
of the code, it must build up a large base of knowledge about the details encoded
in the program. The input to the semantic analyzer phase is the parsed program produced by the parser,
Our semantic analyzer
creates an abstract syntax tree for the soure code.
To generate the semantic analyer, first, we need to use jjtree to create the .jj file, Then we
use this .jj file as the input file to javacc to create the semantic analyzer.
Here is the cal.jjt file.
First. we use jjtree to create the cal.jj file.
Second we use javacc to create the cal.java file.
then we use javac to compile cal.java file to create cal.class.
Finallly. we run our semantic analyzer on our test file. we will get a AST of the expression.