180 likes | 333 Views
Chpater 3. Describing Syntax , Semantics. Outline. The definition of Syntax The Definition of Semantic Most Common Methods of Describing Syntax. Introduction. We usually break down the problem of defining a programming language into two parts. Defining the PL’s syntax
E N D
Chpater 3 Describing Syntax , Semantics
Outline • The definition of Syntax • The Definition of Semantic • Most Common Methods of Describing Syntax
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?
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.
Syntax • It is the Form of the its (expressions, statement, program unit. • A sentenceis a string of characters over some alphabet. • A languageis a set of sentences. • A lexemeis the lowest level syntactic unit of a language (e.g., *, sum, begin). • A tokenis a category of lexemes (e.g., identifier).
Syntax • Ex: While ( Boolean Exprission ) Statement While ( x <10 ) { cout<< x << endl ; }
Formal Methods of Describing Syntax • Backus-Naur Form and Context-Free Grammar • Extended BNF
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
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?
C++ Traning • Do you want to know how to Program? • If yes, what do you need to write your first Program in C++? • Install the Visual Studio .NET on your computer. • Knowing the basics of C++. • What are the basics of C++? • We will study most of the basics in the class step by step.
C++ Traning • The Basic Structure of C++ Code: • Library: #include<iostream> • Using the namespace using namespace std; • The function main int main() { } • Your code cout<<“hello”;
C++ • Write a program that would print the phrase I am studying Programmig Languages in this summer • Library • Using namesapce • The function main • Your code
The Solution #include<iostream> Using namespace std; int main( ) { cout<<“I am studying Programming Languages this summer”; }
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: • int • char • double • Float How to define a variable in C++? [Type] [variable name] = [value] ; int x = 10; [Type] [variable name];int z;
Question • Write a program that will calculate the area of the rectangle where its tall = 10 and width = 3 and show the result?
The Solution #include<iostream> Using namespace std; int main( ) { int tall = 10; int width= 3; int area ; area = tall * width ; cout<<“Area = ” << area ; return 0; }