Wu Hang.  Introduction  Requirements  Checking  Environment  How to start  Tips.

Slides:



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

CPSC 388 – Compiler Design and Construction
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.
Problem Solving 5 Using Java API for Searching and Sorting Applications ICS-201 Introduction to Computing II Semester 071.
INTERFACES IN JAVA 1.Java Does not support Multiple Inheritance directly. Multiple inheritance can be achieved in java by the use of interfaces. 2.We need.
Winter Compiler Construction T7 – semantic analysis part II type-checking Mooly Sagiv and Roman Manevich School of Computer Science Tel-Aviv.
Written by: Dr. JJ Shepherd
6/10/2015C++ for Java Programmers1 Pointers and References Timothy Budd.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Stacks CS-240 Dick Steflik. Stacks Last In, First Out operation - LIFO As items are added they are chronologically ordered, items are removed in reverse.
1 Java (vs. C++). 2 Object-oriented Programming Java and C++ are the most popular object-oriented programming languages Java Sun Microsystems in 1990.
Make Sure You Know All This!. Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling 2 Objects and Classes.
Compiler Construction Semantic Analysis I Rina Zviel-Girshin and Ohad Shacham School of Computer Science Tel-Aviv University.
CSC 8310 Programming Languages Meeting 2 September 2/3, 2014.
Chapter 6Java: an Introduction to Computer Science & Programming - Walter Savitch 1 l Array Basics l Arrays in Classes and Methods l Programming with Arrays.
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.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009.
Prof. amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 10. Pointers & Dynamic Data Structures.
CSc 453 Semantic Analysis Saumya Debray The University of Arizona Tucson.
Overloading Binary Operators Two ways to overload –As a member function of a class –As a friend function As member functions –General syntax Data Structures.
Java Quiz Bowl A fun review of the Java you should know from CMPT 201 If you don’t know the answers - this week is for you to study up!
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2009 Pearson Education, Inc., Upper.
Arrays Module 6. Objectives Nature and purpose of an array Using arrays in Java programs Methods with array parameter Methods that return an array Array.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Chapter 6Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 6 l Array Basics l Arrays and Methods l Programming with Arrays.
CS412/413 Introduction to Compilers and Translators Spring ’99 Lecture 8: Semantic Analysis and Symbol Tables.
Java Objects and Classes. Overview n Creating objects that belong to the classes in the standard Java library n Creating your own classes.
Data Structures Using C++ 2E Chapter 3 Pointers. Data Structures Using C++ 2E2 Objectives Learn about the pointer data type and pointer variables Explore.
CSC1401 Classes - 2. Learning Goals Computing concepts Adding a method To show the pictures in the slide show Creating accessors and modifiers That protect.
1 Homework HW5 due today Review a lot of things about allocation of storage that may not have been clear when we covered them in our initial pass Introduction.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Stacks.
CS536 Semantic Analysis Introduction with Emphasis on Name Analysis 1.
U n i v e r s i t y o f H a i l 1 ICS 202  2011 spring  Data Structures and Algorithms 
ENEE150 – 0102 ANDREW GOFFIN Project 4 & Function Pointers.
CS 153: Concepts of Compiler Design September 30 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Bernd Fischer RW713: Compiler and Software Language Engineering.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Inheritance and Class Hierarchies Chapter 3. Chapter Objectives  To understand inheritance and how it facilitates code reuse  To understand how Java.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
ITI Introduction to Computing II Lab-5 Dewan Tanvir Ahmed University of Ottawa.
CSSE 375 Organizing Data – Part 1 Shawn and Steve Q1.
Java & C++ Comparisons How important are classes and objects?? What mechanisms exist for input and output?? Are references and pointers the same thing??
Array Size Arrays use static allocation of space. That is, when the array is created, we must specify the size of the array, e.g., int[] grades = new int[100];
Interfaces, Abstract Classes, and Polymorphism. What Is an Interface? An interface is the set of public methods in a class Java provides the syntax for.
1 Chapter 15-1 Pointers, Dynamic Data, and Reference Types Dale/Weems.
Module 13: Properties and Indexers. Overview Using Properties Using Indexers.
CS 153: Concepts of Compiler Design September 23 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
Class Everything in Java is in a class. The class has a constructor that creates the object. If you do not supply a constructor Java will create a default.
C allows programmer to define their own function according to their requirement. These types of functions are known as user-defined functions. Suppose,
Reference Types CSE301 University of Sunderland Harry R Erwin, PhD.
CSc 453 Semantic Analysis Saumya Debray The University of Arizona Tucson.
1 Topic 5 Polymorphism "“Inheritance is new code that reuses old code. Polymorphism is old code that reuses new code.”
Lecture 9 Symbol Table and Attributed Grammars
Chapter 7 User-Defined Methods.
Constructing Precedence Table
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Agenda Warmup AP Exam Review: Litvin A2
Review: Chapter 5: Syntax directed translation
C Basics.
Pointers and References
null, true, and false are also reserved.
Extending Classes.
Chapter 11: More on the Implications of Inheritance
Stacks CS-240 Dick Steflik.
Semantic Analysis Pu Youer
SYMBOL TABLE Chuen-Liang Chen Department of Computer Science
Boxcar and Freight Train
Review for Midterm 3.
Presentation transcript:

Wu Hang

 Introduction  Requirements  Checking  Environment  How to start  Tips

 Purpose ◦ Is syntactic analysis sufficient for program checking? ◦ What’s the differences between syntax and semantics?  Approach ◦ After syntactic analysis  What is a program?

 See wiki ◦ Refer to gcc for any semantic issues not mentioned. ◦ Discuss when you find sth. strange. ◦ May test many cases ◦ Take everything into consideration

 Type checking  Use before declaration  Duplicate variables  Subscript checking  Pointer checking (return value, parameters, assignment, etc.)  Mismatch parameters of function or fields of record  Break/continue out of a loop  Struct checking (return value, parameters, assignment, etc.)  Etc.

 Mapping from a symbol to an entry  Keep all information about variables, functions and types.  VarEntry, FuncEntry, TypeEntry in one env  Table.java

 An entry keeps information about specific variable/function/type  Must exists in some environment

 +-*/  Lvalue  Return value  Make sure you have filled expr.type after checking

 Top down/bottom up  Deep understanding about the “program” you get after syntactic analysis  Keep in mind what you NEED to do ◦ Try to write a program and run by gcc when you’re not sure whether it’s right or wrong.

 Semantic semantic = new Semantic(program);  for (int i = 0; i <program.declarationlist.size(); i++)  { ◦ checkDeclarationlist(program.declarationlist[i]);  }

 void checkStmt(Stmt stmt)  {  if (stmt instanceof Ifstmt)  checkIfstmt(stmt);  …  }  Funtion Overloading

 Get a variable to record loop ◦ Loop=0  When enter a loop ◦ Loop++;  When leave a loop ◦ Loop--;  When there is a continue/break ◦ If (loop>0) …

 abstract class Type {}  final class Void extends Type {}  final class Char extends Type {}  final class Int extends Type {}  class Pointer extends Type {  Type elementType;  }  final class Array extends Pointer {  int capacity;  }

 final class Name extends Type {  String name;  }  IT IS USED WHEN YOU SEE THIS:  Struct node{  Int data;  Struct node *next;  };

 abstract class Record extends Type {  class RecordField {  Type type;  String name;  }  List fields;  }  final class Struct extends Record {}  final class Union extends Record {}  final class Function extends Type {  Type argumentType;  Type returnType;  }

 Boolean IsEqual(Type a, Type b)  {  If…  }

 What is the node’s class? ◦ instanceof  Specify type ◦ getInstance() and equals(); static factory  Return specific string ◦ Intern()  Put attributes (lvalue, type, etc.) into the base class ◦ Simplify your code  Copy a HashMap ◦ clone()

 public class Symbol {  private String name;  private Symbol(String n) {  name = n;  }  public String toString() {  return name;  }  private static java.util.Dictionary dict = new java.util.Hashtable ();  public static Symbol symbol(String n) {  String u = n.intern();  Symbol s = dict.get(u);  if (s == null) {  s = new Symbol(u);  dict.put(u, s);  }  return s;  }

 Q & A?

 Thanks!