Professional Documents
Culture Documents
produces an internal representation for it, called intermediate code. The synthesis phase
translates the intermediate code into the target program.
The syntax of a programming language describes the proper form of its programs, while the
semantics of the language de_nes what its programs mean; that is, what each program does when
it executes. For specifying syntax, we present a widely used notation, called context-free
grammars.
Besides specifying the syntax of a language, a context-free grammar can be used to help guide
the translation of programs. A grammar-oriented compiling technique known as syntax-directed
translation.
The semantic analyzer uses the syntax tree and the information in the symbol table to check the
source program for semantic consistency with the language definition. It also gathers type
information and saves it in either the syntax tree or the symbol table, for subsequent use during
intermediate-code generation.
The semantic rule specifies that the string E.code is formed by concatenating E1.code, T.code,
and the character ‘+’.
A syntax-directed translation scheme embeds program fragments called semantic actions within
production bodies, as in