Download presentation
Presentation is loading. Please wait.
Published bySarah Watson Modified over 8 years ago
1
Computer Programming – Grammar – data types – Variables – Keywords – Operators – decision making – Loops – Arrays – Functions – files Programming Environment
2
Computation model It is a formal system which defines a programming language. It also defines how the statements and expressions in a program get executed.
4
Declarative Computation Model Practical Programming Languages : Grammar – Extended Backus-Naur-FORM (EBNF) – Ambiguous Grammar :
5
? * + [ ] { }
6
The rules to define an integer can be written as, I [S] D {D} | X S +|- D 1|2|3|4|5|6|7|8|9 Z 0 With these productions, the following integers can be generated. 0, + 1, – 12, + 58, 902,
7
Consider the if statement in C, the production using BNF would be, I I(C) S|I (C) S ES
8
It can be simplified when converted to EBNF as, I ICS [ES]
9
S a SBC | aBC CB BC bC bc aB ab cC cc bB bb
10
E E + E| E*E | a
11
Language Semantics : Language Design : Translation Approaches to Semantics : Data Structure of Declarative Model : – single-assignment store schema Declarative Variables : Data flow Variables
12
int x, y; y = 10; y = y + x;
14
Stateful computation model Implicit or declarative state Explicit state: Stateful collections – indexed and unindexed collections
15
void disp(char *str) { int k; if(strlen(str)==0) return; k=strlen(str); printf(“%c”,str[k-1]); str[k-1]=’\0’; disp(str); }
17
Object oriented programming model
18
Concurrent model. Declarative concurrent model Message passing concurrent model Lazy concurrent model
19
Relational model
20
Functional Programming model
21
Logic Programming model predicates fact(N,F):- fact1(N,1,F). fact1(0,F,F). fact1(N,X,F):- M is N-1, Y is X*N, fact1(M,Y,F).
22
Component Based Model
23
Graphical User Interface Programming
24
Distributed computation model
25
Constraint Programming model
26
Compiler ● Lexical analysis ● Syntax analysis ● Semantic analysis ● Intermediate (machine-independent) code generation ● Intermediate code optimization ● Target (machine-dependent) code generation ● Target code optimization
29
int main ( ) { int a, b ; float c ; a = 5 ; b = 10 ; c = a + b ; printf (“ % d”, c) ; }
30
LEX : Lex is a program generator
31
YACC YACC is parser generator
32
operators \ [ ] – ?. * + \ ( ) / { } % ^
33
Lex keywords ● yytext ● yyleng
34
input ( ) –Returns the next input character. output (x) – Writes the character x on the output. unput (x) –Pushes the character x back yywrp ( )–Function called by lex when the input ends.
36
Structure
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.