Mini-Pascal Compiling Mini-Pascal (MPC) language

Slides:



Advertisements
Similar presentations
CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
Advertisements

Principles of Programming Fundamental of C Programming Language and Basic Input/Output Function 1.
Constants and Data Types Constants Data Types Reading for this class: L&L,
Compilation Encapsulation Or: Why Every Component Should Just Do Its Damn Job.
1 Pass Compiler 1. 1.Introduction 1.1 Types of compilers 2.Stages of 1 Pass Compiler 2.1 Lexical analysis 2.2. syntactical analyzer 2.3. Code generation.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Fundamentals of Strings and Characters Characters.
Pointer. Warning! Dangerous Curves C (and C++) have just about the most powerful, flexible and dangerous pointers in the world. –Most other languages.
1 Lexical Elements Chapter 2 in ABC. 2 Tokens Token = word / symbol, does not contain white spaces. Tokens in C are either: –keywords –identifiers –constants.
A simple C++ program /* * This program prints the phrase "Hello world!" * on the screen */ #include using namespace std; int main () { cout
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
Introduction to Python
Arrays. A problem with simple variables One variable holds one value –The value may change over time, but at any given time, a variable holds a single.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
Overview of C++ Chapter 2 in both books programs from books keycode for lab: get Program 1 from web test files.
Introduction to a Programming Environment
1 Lecture 3  Lexical elements  Some operators:  /, %, =, +=, ++, --  precedence and associativity  #define  Readings: Chapter 2 Section 1 to 10.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
CSCI 1100/1202 January 16, Why do we need variables? To store intermediate results in a long computation. To store a value that is used more than.
CSC 107 – Programming For Science. Announcements  Textbook available from library’s closed reserve.
CSE 1301 Lecture 2 Data Types Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
Copyright 1999 by Larry Fuhrer. Pascal Programming Getting Started...
CPS120: Introduction to Computer Science
D. M. Akbar Hussain: Department of Software & Media Technology 1 Compiler is tool: which translate notations from one system to another, usually from source.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 2: Variables & Data Types.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs.
Smalltalk (and Squeak) Aida Dungan and Rick Shreve.
BASICS CONCEPTS OF ‘C’.  C Character Set C Character Set  Tokens in C Tokens in C  Constants Constants  Variables Variables  Global Variables Global.
COMP 171: Data Types John Barr. Review - What is Computer Science? Problem Solving  Recognizing Patterns  If you can find a pattern in the way you solve.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs -
The Functions and Purposes of Translators Syntax (& Semantic) Analysis.
Introducing C++ Programming Lecture 3 Dr. Hebbat Allah A. Elwishy Computer & IS Assistant Professor
Data Types Declarations Expressions Data storage C++ Basics.
Chapter 2 Variables.
CHAPTER 2 C++ SYNTAX & SEMANTICS #include using namespace std; int main() { cout
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
CS241 PASCAL I - Control Structures1 PASCAL Control Structures Modified Slides of Philip Fees.
Compiler Construction By: Muhammad Nadeem Edited By: M. Bilal Qureshi.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
Ajmer Singh PGT(IP) Programming Fundamentals. Ajmer Singh PGT(IP) Java Character Set Character set is a set of valid characters that a language can recognize.
Python Let’s get started!.
CPS120: Introduction to Computer Science Variables and Constants.
Agenda Comments Identifiers Keywords Syntax and Symentics Indentation Variables Datatype Operator.
1 09/03/04CS150 Introduction to Computer Science 1 What Data Do We Have.
12/14/2016CS150 Introduction to Computer Science 1 Announcements  Website is up!   All lecture slides, assignments,
Chapter 2 Scanning. Dr.Manal AbdulazizCS463 Ch22 The Scanning Process Lexical analysis or scanning has the task of reading the source program as a file.
Copyright © Curt Hill Simple I/O Input and Output using the System and Scanner Objects.
Chapter 2: Data and Expressions. Variable Declaration In Java when you declare a variable, you must also declare the type of information it will hold.
Topics for today: 1.Comments 2.Data types 3.Variable declaration.
Programming Languages Salihu Ibrahim Dasuki (PhD) CSC102 INTRODUCTION TO COMPUTER SCIENCE.
DEFINITION Java IDE created by Xinox Software JCreator is a powerful interactive development environment (IDE) for Java technologies. A Java compiler.
Definition of the Programming Language CPRL
Component 1.6.
Chapter 2 Variables.
Overview of c# Programming
Python Let’s get started!.
Written by Al.So. Software solutions
Introduction to Computer Science / Procedural – 67130
Lecture 2 Data Types Richard Gesick.
Variables A variable is a placeholder for a value. It is a named memory location where that value is stored. Use the name of a variable to access or update.
CS230 Tutorial Week 3.
Building Java Programs Chapter 2
Introduction to C++ Programming
C++ Data Types Data Type
Fundamental Programming
Comments Any string of symbols placed between the delimiters /* and */. Can span multiple lines Can’t be nested! Be careful. /* /* /* Hi */ is an example.
Chapter 2 Variables.
Lexical Elements & Operators
Python fundamental.
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

Mini-Pascal Compiling Mini-Pascal (MPC) language Subset of the Pascal programming language Somewhat similar to the Java and “C” programming languages There are many differences, however Differences make it much easier to compile ☺ We will discuss details of the actual language when it becomes important

Scanning 1st stage of compiling a program Code written in a programming language High-level languages are supposed to resemble English… …but they don’t. Contain many features specifically designed for the computer How often do you use a semi-colon?

Scanning Raw text is hard for computer to understand Much easier for it to work with objects Scanning converts text into tokens Object encoding a single text idea This is a very common problem, not just in compilers

Scanning Only consider token being processed This stage of compilation only generates tokens Looks for obvious lexical errors --- text that cannot be legal Does not track past tokens Does not worry if text has any real meaning Understanding meaning occurs later in the process

Lexical analysis for tokens in English Legal: ? “”, Snap p. 35 crackle < pop ppo quack! Illegal: ¡ I am excited ! Illegal: gemütlichkeit façade

Lexical analysis for tokens in English Legal: ? “”, Snap p. 35 crackle < pop ppo quack! Illegal: ¡ I am excited ! Illegal: gemütlichkeit façade

Types of Tokens in Mini-Pascal Operator All the meaningful symbols in Mini-Pascal: Numerical: + - * ^ Comparative: < > <= >= <> == Separator: ( ) [ ] . ; , Assignment: := Spaces are meaningful “:=” is one token “: =” is two tokens

Types of Tokens in Mini-Pascal Int Includes all numbers defined by Mini-Pascal Mini-Pascal does not include real numbers Int token includes an uninterrupted series of integers “1354934573212” is one token “13 45” is two tokens – for “13” and “45” “13.65” is three tokens – for “13”, “.”, and “65” “2,585” is three tokens – for “2”, “,”, and “585”

Types of Tokens in Mini-Pascal String The literal strings in Mini-Pascal Java strings begin and end with double quote (“”) Pascal strings begin and end with single quote (‘’) Can include any set of characters, letters, and numbers, but cannot go across multiple lines ‘Hi Mom. #1’ is one token -- “Hi Mom. #1” Note: The quotes are not included in the token

Types of Tokens in Mini-Pascal Identifier/Id Includes keywords (reserved) in Mini-Pascal: and array begin case const div do downto else end for function if mod nil not of or procedure program record repeat then to type until var while Also potential variable and method names Begin with letter and then any combination of letters and numbers DO NOT worry (yet) if it is an actual name

Other Work While Scanning Comments Pascal also includes comments Begins with either a “{“ or “(*” Then include any legal characters including letters, numbers, spaces, newlines End with either “}” or “*)” { This is a legal comment *) (* and so is this } There is no comment token --- it is not used in compilation