1 / 16

Chpater 3

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

noam
Download Presentation

Chpater 3

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chpater 3 Describing Syntax , Semantics

  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 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).

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

  7. Formal Methods of Describing Syntax • Backus-Naur Form and Context-Free Grammar • 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++? • 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.

  11. 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”;

  12. 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

  13. The Solution #include<iostream> 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: • int • char • double • 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<iostream> Using namespace std; int main( ) { int tall = 10; int width= 3; int area ; area = tall * width ; cout<<“Area = ” << area ; return 0; }

More Related