Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chpater 3. Outline The definition of Syntax The Definition of Semantic Most Common Methods of Describing Syntax.

Similar presentations


Presentation on theme: "Chpater 3. Outline The definition of Syntax The Definition of Semantic Most Common Methods of Describing Syntax."— Presentation transcript:

1 Chpater 3

2 Outline The definition of Syntax The Definition of Semantic Most Common Methods of Describing Syntax

3 Introduction We usually break down the problem of defining a programming language into two parts. Defining the PL’s syntax Defining the PL’s semantics In other words, In Order to understand any Programming Language, you need to understand: Syntax Semantics – What is the Syntax & the Semantics?

4 What is the Syntax & the Semantics?  Syntax:  It is the Form of the its (expressions, statement, program unit.  Semantic:  It the meaning of those (expressions, statements, Program units) The boundary between the two is not always clear.

5 Syntax It is the Form of the its (expressions, statement, program unit. A sentence is a string of characters over some alphabet. A language is a set of sentences. A lexeme is the lowest level syntactic unit of a language (e.g., *, sum, begin). A token is a category of lexemes (e.g., identifier).

6 Syntax Ex: While ( Boolean Exprission ) Statement While ( x <10 ) { cout<< x << endl ; }

7 Formal Methods of Describing Syntax 1.Backus-Naur Form and Context-Free Grammar 2.Extended BNF

8 Formal Methods of Describing Syntax Context-Free Grammars – Developed by Noam Chomsky in the mid-1950s – Language generators, meant to describe the syntax of natural languages Backus Normal Form (BNF) – Invented by John Backus to describe Algol 58 – BNF is equivalent to context-free grammars

9 Review What is the Syntax? What is Semantic? Give an example of a syntax? How can we describe the syntax? What is a language? What is a statement? What is a token? What is a lexmes?

10 C++ Traning Do you want to know how to Program? If yes, what do you need to write your first Program in C++? 1.Install the Visual Studio.NET on your computer. 2.Knowing the basics of C++. What are the basics of C++? – We will study most of the basics in the class step by step.

11 C++ Traning The Basic Structure of C++ Code: – Library: #include – Using the namespace using namespace std; – The function main int main() { } – Your code cout<<“hello”;

12 C++ Write a program that would print the phrase I am studying Programmig Languages in this summer 1.Library 2.Using namesapce 3.The function main 4.Your code

13 The Solution #include Using namespace std; int main( ) { cout<<“I am studying Programming Languages this summer”; }

14 C++ Variables: a variable is a storage location and an associated symbolic name (an identifier) which contains some known or unknown quantity or information Types: 1.int 2.char 3.double 4.Float How to define a variable in C++? [Type] [variable name] = [value] ; int x = 10; [Type] [variable name]; int z;

15 Question Write a program that will calculate the area of the rectangle where its tall = 10 and width = 3 and show the result?

16 The Solution #include Using namespace std; int main( ) { int tall = 10; int width= 3; int area ; area = tall * width ; cout<<“Area = ” << area ; return 0; }


Download ppt "Chpater 3. Outline The definition of Syntax The Definition of Semantic Most Common Methods of Describing Syntax."

Similar presentations


Ads by Google