1 Semantic Analysis  Semantic analysis includes  Dynamic Checking (Those checks for which to perform, compiler doesn’t have sufficient information) 

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
Assemblers Dr. Monther Aldwairi 10/21/20071Dr. Monther Aldwairi.
Chapter 6 Type Checking Section 0 Overview
Environments and Evaluation
Yu-Chen Kuo1 Chapter 2 A Simple One-Pass Compiler.
CH2.1 CSE4100 Chapter 2: A Simple One Pass Compiler Prof. Steven A. Demurjian Computer Science & Engineering Department The University of Connecticut 371.
S: Application of quicksort on an array of ints: partitioning.
Chapter 10 Implementing Subprograms. Copyright © 2007 Addison-Wesley. All rights reserved. 1–2 Semantics of Call and Return The subprogram call and return.
Chapter 7Louden, Programming Languages1 Chapter 7 - Control I: Expressions and Statements "Control" is the general study of the semantics of execution.
Cs164 Prof. Bodik, Fall Symbol Tables and Static Checks Lecture 14.
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
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.
COP4020 Programming Languages
Names Variables Type Checking Strong Typing Type Compatibility 1.
CSC 338: Compiler design and implementation
Runtime Environments Compiler Construction Chapter 7.
March 12, ICE 1341 – Programming Languages (Lecture #6) In-Young Ko Programming Languages (ICE 1341) Lecture #6 Programming Languages (ICE 1341)
1 Semantic Analysis Aaron Bloomfield CS 415 Fall 2005.
Compiler Construction
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.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Basic Semantics Associating meaning with language entities.
Interpretation Environments and Evaluation. CS 354 Spring Translation Stages Lexical analysis (scanning) Parsing –Recognizing –Building parse tree.
410/510 1 of 18 Week 5 – Lecture 1 Semantic Analysis Compiler Construction.
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
Introduction to Code Generation and Intermediate Representations
CS536 Semantic Analysis Introduction with Emphasis on Name Analysis 1.
The Functions and Purposes of Translators Syntax (& Semantic) Analysis.
Review: Syntax directed translation. –Translation is done according to the parse tree. Each production (when used in the parsing) is a sub- structure of.
1 Static Checking and Type Systems Chapter 6 COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University, 2005.
Structure of Programming Languages Names, Bindings, Type Checking, and Scopes.
Compiler Construction By: Muhammad Nadeem Edited By: M. Bilal Qureshi.
Bernd Fischer RW713: Compiler and Software Language Engineering.
1 A Simple Syntax-Directed Translator CS308 Compiler Theory.
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.
ISBN Chapter 10 Implementing Subprograms.
Implementing Subprograms
CS 330 Programming Languages 10 / 23 / 2007 Instructor: Michael Eckmann.
Chapter 8: Semantic Analyzer1 Compiler Designs and Constructions Chapter 8: Semantic Analyzer Objectives: Syntax-Directed Translation Type Checking Dr.
CSc 453 Semantic Analysis Saumya Debray The University of Arizona Tucson.
1 Compiler Construction Run-time Environments,. 2 Run-Time Environments (Chapter 7) Continued: Access to No-local Names.
ISBN Chapter 10 Implementing Subprograms.
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
Definition of the Programming Language CPRL
Run-Time Environments Chapter 7
Constructing Precedence Table
-by Nisarg Vasavada (Compiled*)
Names.
Semantic Analysis Chapter 6.
Run-Time Environments
Chapter 2: A Simple One Pass Compiler
Run-Time Environments
Designing a Predictive Parser
Semantic Analysis Semantic analysis includes
Semantic Analysis Chapter 6.
Symbol Table 薛智文 (textbook ch#2.7 and 6.5) 薛智文 96 Spring.
Lecture 6: Names (Revised based on the Tucker’s slides) 5/27/2019
Presentation transcript:

1 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”)

2 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.

3 Symbol Table Considerations ARRAY symtable lexptr token attributes div mod id EOSi tnuoc dom vid ARRAY lexemes 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.

4 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 }.

5 Symbol Table Management symbol table lexeme type attributes sort - a int x int readarray - i int Scope Stack When entering readarray

6 Symbol Table Management symbol table lexeme type attributes sort - a int x int readarray - exchange - quicksort - k int v int Scope Stack After entering quicksort