Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Programming Languages S1.3.1Bina © 1998 Liran & Ofir Introduction to Programming Languages Programming in C.

Similar presentations


Presentation on theme: "Introduction to Programming Languages S1.3.1Bina © 1998 Liran & Ofir Introduction to Programming Languages Programming in C."— Presentation transcript:

1 Introduction to Programming Languages S1.3.1Bina © 1998 Liran & Ofir Introduction to Programming Languages Programming in C

2 Introduction to Programming Languages S1.3.2Bina © 1998 Liran & Ofir Programming Languages n The need for Programming Languages l Programming Languages allow programmers to express computations that are to be carried to express computations that are to be carried out by computers out by computers

3 Introduction to Programming Languages S1.3.3Bina © 1998 Liran & Ofir Programming Languages l Machine level Programming Languages are understood by machines, but are difficult for understood by machines, but are difficult for humans to understand and express ideas humans to understand and express ideas n The need for Programming Languages High Level Programming Languages

4 Introduction to Programming Languages S1.3.4Bina © 1998 Liran & Ofir Programming Languages n High Level Programming Languages: l Abstract out the underlying complexities of computer by providing a view of the computer by providing a view of the computer that provides a higher level of computer that provides a higher level of abstraction abstraction

5 Introduction to Programming Languages S1.3.5Bina © 1998 Liran & Ofir Programming Languages n Programming Languages are defined by: Syntax rules Semantics rules

6 Introduction to Programming Languages S1.3.6Bina © 1998 Liran & Ofir SyntaxSyntax n The rules describing the forms of Programming Languages constructs l Describes which sequence of characters are valid programs of the language

7 Introduction to Programming Languages S1.3.7Bina © 1998 Liran & Ofir SemanticsSemantics n The rules describing the meaning of syntactically correct programs l Describes what will the program do if executed

8 Introduction to Programming Languages S1.3.8Bina © 1998 Liran & Ofir Lexical Rules n Describe the valid words (lexems) from which a valid program can be constructed l Constants 9, 9.6, 1.7E+3, 'b' l Identifiers book, salary l Reserved (key) words if, return, do

9 Introduction to Programming Languages S1.3.9Bina © 1998 Liran & Ofir Syntax Rules n Describe which sequence of lexems form valid programs l Assignment is Identifier = Expression l Expression is Identifier or Constant l ratio = 0.9 (valid) Color = red l name = John Smith (invalid) Ratio = 0.0.9

10 Introduction to Programming Languages S1.3.10Bina © 1998 Liran & Ofir Semantic rules n Describe consistency rules. l A variable must be declared before it is used. n Describe the meaning of valid programs. Count = 9; Count = 9; Value of the variable Count becomes 9 Value of the variable Count becomes 9 Count = Count + 1; Count = Count + 1; Value of the variable Count is incremented by 1 Value of the variable Count is incremented by 1

11 Introduction to Programming Languages S1.3.11Bina © 1998 Liran & Ofir CompilerCompiler Compiler Program in a high level language Equivalent program in the machine language

12 Introduction to Programming Languages S1.3.12Bina © 1998 Liran & Ofir Elements of Programming Languages n Variables n Variable Types n Operators n Expressions n Assignment n Control Structures n Functions n etc.

13 Introduction to Programming Languages S1.3.13Bina © 1998 Liran & Ofir VariablesVariables n Abstraction of Computer Memory. A variable has a name Name

14 Introduction to Programming Languages S1.3.14Bina © 1998 Liran & Ofir VariableVariable l Variable Type: Abstraction of the set of values the variable may assume: Abstraction of the set of values the variable may assume: l Integer (int) 9, 7, -12990 l Character (char) 'A', '\n', 'b' l Boolean True, False l WeekDay Monday, Wednesday

15 Introduction to Programming Languages S1.3.15Bina © 1998 Liran & Ofir OperatorsOperators n Arithmetic Operators +, -, *, /,... +, -, *, /,... n Relational Operators <, <=, ==, !=... <, <=, ==, !=... n Logical Operators &&, ||, !

16 Introduction to Programming Languages S1.3.16Bina © 1998 Liran & Ofir OperatorsOperators n Precedence rules: Define the order by which the operators are evaluated. n Associativity rules: Define the order by which the operators having the same precedence are evaluated.

17 Introduction to Programming Languages S1.3.17Bina © 1998 Liran & Ofir ExpressionsExpressions n Arithmetic Expressions: l Operands: variables constants constants l Operators: + - * /...... l Example: 3+5*7 3*(a+b)/n 3*(a+b)/n

18 Introduction to Programming Languages S1.3.18Bina © 1998 Liran & Ofir ExpressionsExpressions n Relational Expressions: l Operands: variables constants constants l Operators: > >= >= < <= <= == == != !=...... l Example: 3 > 5 a+b <= 3*x a+b <= 3*x

19 Introduction to Programming Languages S1.3.19Bina © 1998 Liran & Ofir ExpressionsExpressions n Boolean Expressions: l Operands: Boolean variables Boolean constants: True, False Boolean constants: True, False l Operators: and - && or - || or - || not - ! not - ! l Example: a && b ((a+b) >= 12 ) && (x != y) ((a+b) >= 12 ) && (x != y)

20 Introduction to Programming Languages S1.3.20Bina © 1998 Liran & Ofir AssignmentAssignment n Changes the value of a variable. ==> = ==> = l Example: A A = 5; 5

21 Introduction to Programming Languages S1.3.21Bina © 1998 Liran & Ofir Control Structures n Describe the order of statement execution l Sequence l Selection l Iteration

22 Introduction to Programming Languages S1.3.22Bina © 1998 Liran & Ofir Control Structures n Sequence Statement-1;Statement-2;...Statement-n; Statements are executed sequentially one after another.

23 Introduction to Programming Languages S1.3.23Bina © 1998 Liran & Ofir Control Structures n Selection: if ( Expr ) { Sequence-1} Expr is evaluated. If the result is True, statements of Sequence-1 will be executed. if (Expr) { Sequence-1} else { Sequence-2} Expr is evaluated. If the result is True, statements of Sequence-1 will be executed. Otherwise, statements of Sequence-2 will be executed.

24 Introduction to Programming Languages S1.3.24Bina © 1998 Liran & Ofir Control Structures n Iteration: Expr is evaluated. If the result is True, Statements of Sequence-1 will be executed. Expr is evaluated again. If the result is True, Statements of Sequence-1 will be executed.... while (Expr) { Sequence-1 Sequence-1}


Download ppt "Introduction to Programming Languages S1.3.1Bina © 1998 Liran & Ofir Introduction to Programming Languages Programming in C."

Similar presentations


Ads by Google