1 / 24

Introduction to Programming Languages

Introduction to Programming Languages. Programming in C. Programming Languages. The need for Programming Languages. Programming Languages allow programmers to express computations that are to be carried out by computers. Programming Languages. The need for Programming Languages.

lamont
Télécharger la présentation

Introduction to Programming Languages

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. Introduction to Programming Languages Programming in C

  2. Programming Languages • The need for Programming Languages • Programming Languages allow programmers • to express computations that are to be carried • out by computers

  3. Programming Languages • The need for Programming Languages • Machine level Programming Languages are • understood by machines, but are difficult for • humans to understand and express ideas High Level Programming Languages

  4. Programming Languages • High Level Programming Languages: • Abstract out the underlying complexities of • computer by providing a view of the • computer that provides a higher level of • abstraction

  5. Programming Languages • Programming Languages are defined by: Syntax rules Semantics rules

  6. Syntax • The rules describing the forms of Programming Languages constructs • Describes which sequence of characters are valid programs of the language

  7. Semantics • The rules describing the meaning of syntactically correct programs • Describes what will the program do if executed

  8. Lexical Rules • Describe the valid words (lexems) from which a valid program can be constructed • Constants 9, 9.6, 1.7E+3, 'b' • Identifiers book, salary • Reserved (key) words if, return, do

  9. Syntax Rules • Describe which sequence of lexems form valid programs • Assignment is Identifier = Expression • Expression is Identifier or Constant • ratio = 0.9 Color = red (valid) • name = John Smith Ratio = 0.0.9 (invalid)

  10. Semantic rules • Describe consistency rules. • A variable must be declared before it is used. • Describe the meaning of valid programs. Count = 9; Value of the variable Count becomes 9 Count = Count + 1; Value of the variable Count is incremented by 1

  11. Compiler Compiler Program in a high level language Equivalent program in the machine language

  12. Elements of Programming Languages • Variables • Variable Types • Operators • Expressions • Assignment • Control Structures • Functions • etc.

  13. Variables • Abstraction of Computer Memory. Name A variable has a name

  14. Variable • Variable Type: Abstraction of the set of values the variable may assume: • Integer (int) 9, 7, -12990 • Character (char) 'A', '\n', 'b' • Boolean True, False • WeekDay Monday, Wednesday

  15. Operators • Arithmetic Operators + , - , * , / , ... • Relational Operators < , <= , == , !=... • Logical Operators && , || , !

  16. Operators • Precedence rules: Define the order by which the operators are evaluated. • Associativity rules: Define the order by which the operators having the same precedence are evaluated.

  17. Expressions • Arithmetic Expressions: • Operands: variables constants • Operators: + - * / ... • Example: 3+5*7 3*(a+b)/n

  18. Expressions • Relational Expressions: • Operands: variables constants • Operators: > >= < <= == != ... • Example: 3 > 5 a+b <= 3*x

  19. Expressions • Boolean Expressions: • Operands: Boolean variables Boolean constants: True, False • Operators: and - && or - || not - ! • Example: a && b ((a+b) >= 12 ) && (x != y)

  20. A Assignment • Changes the value of a variable. <Assignment> ==> <Var> = <Expression> • Example: A = 5; 5

  21. Control Structures • Describe the order of statement execution • Sequence • Selection • Iteration

  22. Control Structures • Sequence Statement-1; Statement-2; . . . Statement-n; Statements are executed sequentially one after another.

  23. Expr is evaluated. If the result is True, statements of Sequence-1 will be executed. Expr is evaluated. If the result is True, statements of Sequence-1 will be executed. Otherwise, statements of Sequence-2 will be executed. Control Structures • Selection: if ( Expr ) { Sequence-1 } if (Expr) { Sequence-1 } else { Sequence-2 }

  24. Control Structures • Iteration: while (Expr) { Sequence-1 } 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. ...

More Related