By: Bahman Ravaei Farhad Rad نیمسال

Slides:



Advertisements
Similar presentations
Etter/Ingber Engineering Problem Solving with C Fundamental Concepts Chapter 2 Simple C Programs.
Advertisements

Programming Language Concepts
1 Variables and Data Types. 2 Variable Definition a location in memory, referenced by a name (identifier), where data of a given type can be stored, changed,
CSci 1130 Intro to Programming in Java
Chapter Three Arithmetic Expressions and Assignment Statements
Intermediate Code Generation
Types and Arithmetic Operators
L5:CSC © Dr. Basheer M. Nasef Lecture #5 By Dr. Basheer M. Nasef.
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
Introduction to C Programming
1 Outline 13.1Introduction 13.2A Simple Program: Printing a Line of Text in a Web Page 13.3Another JavaScript Program: Adding Integers 13.4Memory Concepts.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Program Design and Development
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
C programming an Introduction. Types There are only a few basic data types in C. char a character int an integer, in the range -32,767 to 32,767 long.
CSCI/CMPE 4341 Topic: Programming in Python Chapter 3: Control Structures (Part 1) – Exercises 1 Xiang Lian The University of Texas – Pan American Edinburg,
Introduction to C Programming
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
CSCI 1730 January 17 th, 2012 © by Pearson Education, Inc. All Rights Reserved.
Spreadsheets Objective 6.02
2 Explain advanced spreadsheet concepts and functions Advanced Calculations 1 Sabbir Saleh_Lecture_17_Computer Application_BBA.
A First Book of ANSI C Fourth Edition
Chapter 9 Formatted Input/Output Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
1 2 2 Introduction to Java Applications Introduction Java application programming –Display messages –Obtain information from the user –Arithmetic.
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Chapter 3: Data Types and Operators JavaScript - Introductory.
Chapter 2 Basic Elements of Java. Chapter Objectives Become familiar with the basic components of a Java program, including methods, special symbols,
Numeric Types, Expressions, and Output ROBERT REAVES.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
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.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
IFS Intro to Data Management Chapter 5 Getting More Than Simple Columns.
SNOBOL4 CSC 507 Hwan-Jun, Lee 11/29/2005. Content of Presentation Introduction Significant Features of SNOBOL Pattern Matching Primitive Functions Predicates.
Introduction to Visual Basic Programming. Introduction Simple Program: Printing a Line of Text Another Simple Program: Adding Integers Memory Concepts.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
 2000 Deitel & Associates, Inc. All rights reserved. Outline 8.1Introduction 8.2A Simple Program: Printing a Line of Text in a Web Page 8.3Another JavaScript.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Programming in Java (COP 2250) Lecture 4 Chengyong Yang Fall, 2005.
Types of C Variables:  The following are some types of C variables on the basis of constants values it has. For example: ○ An integer variable can hold.
Part:2.  Keywords are words with special meaning in JavaScript  Keyword var ◦ Used to declare the names of variables ◦ A variable is a location in the.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
2: Basics Basics Programming C# © 2003 DevelopMentor, Inc. 12/1/2003.
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
© 2004 Pearson Addison-Wesley. All rights reserved August 27, 2007 Primitive Data Types ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
Chapter 6 JavaScript: Introduction to Scripting
Introduction to C++ Programming
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
2.5 Another Java Application: Adding Integers
Revision Lecture
Concatenation P1 = ‘A’ | ‘B’ P2 = ‘C’ | ‘D’ P3 = P1 P2
Computing with C# and the .NET Framework
Java Programming: From Problem Analysis to Program Design, 4e
Chapter 2 - Introduction to C Programming
INPUT & OUTPUT scanf & printf.
With Assignment Operator
Chapter 2: Basic Elements of Java
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Introduction to C++ Programming
Introduction to Java Applications
Chapter 2 - Introduction to C Programming
Matlab Basics.
DATA TYPES AND OPERATIONS
Introduction to C Programming
Presentation transcript:

By: Bahman Ravaei 790649 Farhad Rad 116703 81-82-2 نیمسال SNOBOL 4 By: Bahman Ravaei 790649 Farhad Rad 116703 81-82-2 نیمسال

Introduction to the snobol 4 P.L Developed at BELL laboratories in 1962 Is a string of characters (character oriented) Define other data type Consist of a sequence of statement Array and Table have more flexibility Function calls can be made recursively Link list node and complex number are possible programmer define data type

four basic type of statements: i) the Assignment statement ii) the Pattern matching statements iii) the Replacement statement iv) the End statement

Assignment statements : the simple type of assignment: variable = value example: v = 5 the value may be given an experssion example: W = 14 + (16 - 10) which assigns the value 20 to the variable w

“BLANK are required around arithmetic operators” The value may be string of characters example: v = ‘dog’

Arithmetic: i) Integers ii) Real arithmetic operation is “addition +” ,”subtraction -” ,”multiplication * ” ,”division / ” and “exponentiation ** or !” blanks are required between the binary operators and their operands ,Unary operator such as the minus sign must be adjacent to their operands. example: Q2 = -P / -N

Predicates of arithmetic operations : -Unary operators -Exponentiation -Multiplication and Division -Addition and Subtraction All arithmetic operations associate to the left except exponentiation . example : 2 ** 3 ** 5 is equivalent to : 2 ** (3 ** 5)

Example : m = 4 n = 5 p = n * m / (n - 1) assign the value 5 to p Example : pi = 3.14159 mul = 2. * pi * 5. assign Real value to pi and mul

Pattern matching statements: Define : The operation of examining for occurrence of specified substring Pattern matching have two type: i ) the pattern matching statement ii ) the replacement statement

the pattern matching statement : the pattern matching statement has the form : subject pattern two fields separated by at least one blank example: trade = ‘programmer ’ trade ‘gram’ Pattern can an expression row = ‘k’ no. = 20 ‘kk2429’ row no. + 4 pattern is equivalent by ‘k24’

Replacement statements The replacement statement has the form subject pattern = object If the pattern matching operation succeeds the subject string is modified by replacing the matched substring by the object . example: WORD = “GRID” WORD ‘I’ = ‘OU’ thus WORD is equivalent GROUD

If pattern not found the statement failed example: If pattern not found the statement failed example: WORD ‘AB’ = ‘OU’ example: HAND = ‘AC4DAHDKS’ RANK = 4 SUIT = ‘D’ HAND RANK SUIT = ‘AS’ first RANK and SUIT concatenate that it’s 4D and later HAND ‘4D’ = ‘AS’ example : HAND RANK SUIT =

Patterns Two operation available for constructing complex patterns: i) alternation ii) concatenation alternation is indicated by expression of the form: P1 | P2 example: KEYWORD = ‘COMPUTER’ | ‘PROGRAM’ KEYWORD = KEYWORD | ‘ALGORITM’

can use KEYWORD to pattern field: TEXT = ‘PROGRAMMING ALGORITM FOR COMPUTERS ‘ TEXT KEYWORD = after matching: TEXT = ‘MING ALGORITM FOR COMPUTERS’

Concatenation Concatenation of two patterns ,P1 and P2 ,is specified in the same way as the concatenation of two strings: P1 P2 example: BASE = ‘BINARY’ | ‘DECIMAL’ | ‘HEX’ SCALE = ‘FIXED’ | ‘FLOAT’ ATTRIBUTE = SCALE BASE

Array : Arrays are created by function ARRAY . ARRAY (p , e) example : board = ARRAY (‘3,3’ , ‘x’) x X

Example : A1 = ARRAY ( 5 ) A2 = ARRAY (5 , A1) A2 A1

Flow of control A SNOBOL program is a sequence of statements terminated by an end statement . labels and goto provide to control the flow of the program. Example of label: START TEXT = INPUT the end statement is distinguished by the label END

Transfer to a labelled statement is specified in the goto field which may appear at the end of a statement and is separated from the rest of the statement by a colon ‘ : ’. Two types of transfers can be specified in the goto field : i ) conditional ii ) unconditional

conditional A conditional transfer consists of a label enclosed within parentheses preceded by an F or S corresponding to Failure or Success. example : TEXT = INPUT :F(DONE) example : LOOP PUNCH = INPUT S:LOOP END

we can use F and S in one statement example: we can use F and S in one statement example: COLOR = ‘RED’ | ‘GREEN’ | ‘BLUE’ BRIGHT TEXT COLOR = :S(BRIGHT)F(BLAND) . . . BLAND …….

unconditional An unconditional transfer is indicated by the absence of an F or S before the enclosing parentheses . example: LOOP PUNCH = INPUT :F(END) OUTPUT = PUNCH :(LOOP) END

Indirect reference Indirect referencing is indicated by the unary operator $. examples: i) MONTH = ‘APRIL’ $MONTH = ‘CRUEL’ is equivalent: APRIL = ‘CRUEL’ ii) WORD = ‘RUN’ $(WORD ‘:’) = $(WORD ‘:’) + 1 iii) $(‘A’ | ‘B’) iv) N = N + 1 :($(‘PHASE’ N))

Functions: i) primitive functions ii) predicates iii) defined functions

Primitive function Many snobol procedure are invoked by function built into the system ,called primitive functions. Few example of primitive function: i) SIZE (string) APE = ‘SIMIAN’ OUTPUT = SIZE(APE) ii) DUPL (string ,integer) DUPL(‘/*’,5) iii) REPLACE( TEXT,CH1,CH2) STATEMENT = ‘A(I,J) = A(I,J) + 3’ OUTPUT = REPLACE(STATEMENT,’()’,’<>’) print the line : A<I,J> = A<I,J> + 3

Predicate: A function or operation that returns the NULL string if a given condition is satisfied. Example: i) LE(n1 , n2 ) PUNCH = LE( SIZE(TEXT),80) TEXT ii) LT( n1 , n2 ) ADD N = LT( N , 50 ) N+1 iii) DIFFER ( st1 , st2 ) OUTPUT = DIFFER ( FIRST , SECOND ) FIRST SECOND iv) LGT ( st1 , st2 )

Defined function: A function defined by Programmer. The primitive function DEFINE to specify the function name , formal arguments , local variables, and the entry point of the function. Example: DEFINE ( ‘ DELETE ( STRING , CHAR )’ , ‘D1’ ) D1 STRING CHAR = :S ( D1 ) DELETE = STRING : ( RETURN )

Example: DEFINE ( ‘ DELETE ( STRING , CHAR )’ ) DELETE STRING CHAR = :F ( FRETURN) D2 STRING CHAR = :S ( D1 ) DELETE = STRING : ( RETURN )

Programmer define data type: The primitive function DATA can be used to difine the new data type. Example: DATA( ‘ NODE ( VALUE , LINK)’) P = NODE (‘ S ‘ , ) P = NODE (‘ T ‘ , P ) P = LINK ( P ) P ‘ T ‘ ‘ S’ NULL

Program format: Example: OUTPUT = ‘ THE TOTAL NUMBER OF OCCURRENCE IS’ + SUM< N > X = 2 ; Y = 3 ; Z = 10 * : THIS IS A COMMENT

End