Semantic Analysis Semantic analysis includes

Slides:



Advertisements
Similar presentations
CH4.1 Type Checking Md. Fahim Computer Engineering Department Jamia Millia Islamia (A Central University) New Delhi –
Advertisements

CS3012: Formal Languages and Compilers Static Analysis the last of the analysis phases of compilation type checking - is an operator applied to an incompatible.
CPSC 388 – Compiler Design and Construction
Symbol Table.
Chapter 6 Type Checking. The compiler should report an error if an operator is applied to an incompatible operand. Type checking can be performed without.
Semantic Analysis Chapter 6. Two Flavors  Static (done during compile time) –C –Ada  Dynamic (done during run time) –LISP –Smalltalk  Optimization.
1 Compiler Construction Intermediate Code Generation.
CS 330 Programming Languages 10 / 16 / 2008 Instructor: Michael Eckmann.
Tutorial 6 & 7 Symbol Table
Environments and Evaluation
CH2.1 CSE4100 Chapter 2: A Simple One Pass Compiler Prof. Steven A. Demurjian Computer Science & Engineering Department The University of Connecticut 371.
Chapter 10 Implementing Subprograms. Copyright © 2007 Addison-Wesley. All rights reserved. 1–2 Semantics of Call and Return The subprogram call and return.
Cs164 Prof. Bodik, Fall Symbol Tables and Static Checks Lecture 14.
Static checking and symbol table Chapter 6, Chapter 7.6 and Chapter 8.2 Static checking: check whether the program follows both the syntactic and semantic.
CSc 453 Semantic Analysis Saumya Debray The University of Arizona Tucson.
1 Semantic Analysis Aaron Bloomfield CS 415 Fall 2005.
1 October 16, October 16, 2015October 16, 2015October 16, 2015 Azusa, CA Sheldon X. Liang Ph. D. Computer Science at Azusa Pacific University Azusa.
1 Run-Time Environments. 2 Procedure Activation and Lifetime A procedure is activated when called The lifetime of an activation of a procedure is the.
Names. 2 Variables  binding is an association between an entity (such as a variable) and a property (such as its value). A binding is static if the association.
Basic Semantics Associating meaning with language entities.
Interpretation Environments and Evaluation. CS 354 Spring Translation Stages Lexical analysis (scanning) Parsing –Recognizing –Building parse tree.
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
CS536 Semantic Analysis Introduction with Emphasis on Name Analysis 1.
Review: Syntax directed translation. –Translation is done according to the parse tree. Each production (when used in the parsing) is a sub- structure of.
Structure of Programming Languages Names, Bindings, Type Checking, and Scopes.
Bernd Fischer RW713: Compiler and Software Language Engineering.
1 Run-Time Environments Chapter 7 COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University, 2005.
10-1 Chapter 10: Implementing Subprograms The General Semantics of Calls and Returns Implementing “Simple” Subprograms Implementing Subprograms with Stack-Dynamic.
1 Semantic Analysis  Semantic analysis includes  Dynamic Checking (Those checks for which to perform, compiler doesn’t have sufficient information) 
1 Compiler Construction Run-time Environments,. 2 Run-Time Environments (Chapter 7) Continued: Access to No-local Names.
Semantic Analysis Chapter 6. Two Flavors  Static (done during compile time) –C –Ada  Dynamic (done during run time) –LISP –Smalltalk  Optimization.
Chapter 2: A Simple One Pass Compiler
Implementing Subprograms
Lecture 9 Symbol Table and Attributed Grammars
Definition of the Programming Language CPRL
Run-Time Environments Chapter 7
Names and Attributes Names are a key programming language feature
Context-Sensitive Analysis
Type Checking, and Scopes
A Simple Syntax-Directed Translator
Constructing Precedence Table
Compiler Construction (CS-636)
Subject Name Compiler Design Subject Code: 10CS63
Structure of Programming Languages
Semantic Analysis with Emphasis on Name Analysis
Compilers.
-by Nisarg Vasavada (Compiled*)
Names.
CS 536 / Fall 2017 Introduction to programming languages and compilers
Semantic Analysis Chapter 6.
Chapter 5 Names, Bindings, Type Checking, and Scopes.
Run-Time Environments
Basic Program Analysis: AST
Course supervisor: Lubna Siddiqui
Implementing Subprograms
Chapter 2: A Simple One Pass Compiler
Scope of Variables.
Lecture 15 (Notes by P. N. Hilfinger and R. Bodik)
Compilers B V Sai Aravind (11CS10008).
Run-Time Environments
Govt. Polytechnic,Dhangar
Designing a Predictive Parser
Three-address code A more common representation is THREE-ADDRESS CODE . Three address code is close to assembly language, making machine code generation.
A Simple Two-Pass Assembler
Semantic Analysis Chapter 6.
Languages and Compilers (SProg og Oversættere)
Symbol Table 薛智文 (textbook ch#2.7 and 6.5) 薛智文 96 Spring.
Lecture 6: Names (Revised based on the Tucker’s slides) 5/27/2019
Implementing Subprograms
Presentation transcript:

Semantic Analysis Semantic analysis includes Dynamic Checking (Those checks for which to perform, compiler doesn’t have sufficient information) Static Checking (Semantic Checks that can be performed in compile time) Dynamic checking: A piece of object code is added to the compiled program to perform the checking in the execution time Example: var a[10] int; …; read (I); a(I) := 0; Generated code is as such the last statement would have been: If I <= 10 then a(I) := 0 else print (“subscript out of range error”)

Semantic Analysis Static checking examples: Type checks: in A := B + C, all operands should have the same type Flow-of-control checks: check whether a e.g. break statement has somewhere to return control. Uniqueness checks: In some languages names must be unique Nested-related checks: In ADA for loops can have name, and it must appear twice (before the for keyword and before the end statement.

Symbol Table Considerations OPERATIONS: Insert (string, token_ID) Lookup (string) NOTICE: Reserved words are placed into symbol table for easy lookup Attributes may be associated with each entry, i.e., typing info, size info, memory address, etc. ARRAY symtable lexptr token attributes div mod id 1 2 3 4 d i v EOS m o d EOS c o u n t EOS i EOS ARRAY lexemes

Symbol Table Management program sort(input, output); var a : array [0 .. 10] of integer; x : integer; procedure readarray; var i : integer; begin … a … end; procedure exchange( i, j, : integer); begin x := a[i]; a[i] := a[j]; a[j] := x end procedure quicksort(m, n: integer); var k, v : integer; function partition(y, z: integer) : integer; var i, j : integer; begin … a … … v … … exchange(i, j); … end { partition }; begin … end { quicksort } begin … end { sort }.

Symbol Table Management When entering readarray symbol table lexeme type attributes sort - a int x int readarray - i int 1 2 3 4 4 Scope Stack

Symbol Table Management After entering quicksort symbol table lexeme type attributes sort - a int x int readarray - exchange - quicksort - k int v int 1 2 3 4 5 6 7 6 Scope Stack