chpt7review - Semantic analysis Parsing only verifies that...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Semantic analysis Parsing only verifies that the program consists of tokens arranged in a syntactically-valid combination, we now move on to semantic analysis , where we delve deeper to check whether they form a sensible set of instructions in the programming language. For a program to be semantically correct, all variables, functions, classes, etc. are properly defined, expressions and variables are used in ways that respect the type system, access control isn’t violated, and so on. Semantic analysis is the next-to-last phase of the front end and the compiler’s last chance to weed out incorrect programs. We need to ensure the program is well-formed enough to continue on to the next phase where we generate code.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
semantic analysis and symbol table A large part of semantic analysis consists of tracking variable/function/type declarations .As we enter each new identifier in our symbol table, we need to record the type information of the declaration. Then, as we continue parsing the rest of the program, we make sure that the type of each identifier and expression is respected in terms of the operations being performed
Background image of page 2
semantic analysis phase. . The type of the right-side expression of an assignment statement should match the type of the left-side, and the left-side needs to be a properly declared and assignable identifier (i.e. not some sort of constant). The parameters of a function should match the arguments of a function call in both number and type. The language may require that identifiers are unique, disallowing a global variable and function of the same name. The operands to multiplication operation will need to be
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/23/2011 for the course CS Compile taught by Professor Weizhong during the Spring '05 term at Fudan University.

Page1 / 12

chpt7review - Semantic analysis Parsing only verifies that...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online