Лекции 11-12 25 марта 2016 г.. оператор объявления переменных : int a; char a, b = 5, c; присваивание ( Assign ): id = ; пустой оператор ; if( ) else.

Slides:



Advertisements
Similar presentations
Recursive Descent Technique CMSC 331. UMBC 2 The Header /* This program matches the following A -> B { '|' B } B -> C { '&' C } C -> D { '^' D } D ->
Advertisements

For(int i = 1; i
Passing by-value vs. by-reference in ARM by value C code equivalent assembly code int a;.section since a is not assigned an a:.skip initial.
ANALYSIS OF PROG. LANG. PROGRAM ANALYSIS Instructors: Crista Lopes Copyright © Instructors. 1.
Constructor. 2 constructor The main use of constructors is to initialize objects. A constructor is a special member function, whose name is same as class.
Python Mini-Course University of Oklahoma Department of Psychology Lesson 28 Classes and Methods 6/17/09 Python Mini-Course: Lesson 28 1.
Chapter 6 Type Checking. The compiler should report an error if an operator is applied to an incompatible operand. Type checking can be performed without.
Def f(n): if (n == 0): return else: print(“*”) return f(n-1) f(3)
CSC241 Object-Oriented Programming (OOP) Lecture No. 9.
Classes 2 COMPSCI 105 SS 2015 Principles of Computer Science.
CS311 – Today's class Perl – Practical Extraction Report Language. Assignment 2 discussion Lecture 071CS Operating Systems I.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 4: Control Structures I (Selection)
Handout on Functions Passing Values to Functions #include int mult(int, int); int main() { int a = 10, b = 20; cout
Синтаксис языка Java.
CS 202 Computer Science II Lab Fall 2009 October 22.
8.5 Proving Triangles are Similar Geometry Mrs. Spitz Spring 2005.
7.3 Proving Triangles are Similar Geometry. Objectives/DFA/HW  Objectives:  You will use similarity theorems to prove that two triangles are similar.
Introduction to Java. Main() Main method is where the program execution begins. There is only one main Displaying the results: System.out.println (“Hi.
Java Programming Constructs 1 MIS 3023 Business Programming Concepts II The University of Tulsa Professor: Akhilesh Bajaj All slides in this presentation.
Recap, Test 1 prep, Composition and Inheritance. Dates Test 1 – 12 th of March Assignment 1 – 20 th of March.
CP104 Introduction to Programming Selection Structures_3 Lecture 11 __ 1 The Switch Statement The switch statement provides another means to select one.
M. Taimoor Khan #include void main() { //This is my first C++ Program /* This program will display a string message on.
Lesson 3 CDT301 – Compiler Theory, Spring 2011 Teacher: Linus Källberg.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
FACTORS A Monomial can be written as a product of its factors. A Monomial can be written as a product of its factors. Example: Example: a 2a = 2 * a a.
1 Lecture 04 Structural Programming in C++ You will learn: i) Operators: relational and logical ii) Conditional statements iii) Repetitive statements.
Construction of Triangles 1.Given three sides Example Triangle ABC has sides AB = 6cm, BC = 8cm and AC = 10cm. Construct the triangle ABC and measure and.
Concordia TAV 2002 Comp5421_421 Comp5421 Object Oriented Programming Using C++ Efficiently Lecture 4 (2) Tianxiang Shen Summer 2002 Department of Computer.
Lecture 13 Transition from Fortran to C Yi Lin Feb 27, 2007.
© M. Winter COSC 4P41 – Functional Programming Programming with actions Why is I/O an issue? I/O is a kind of side-effect. Example: Suppose there.
int num = 22; if (num > 0) if (num % 5 == 0) System.out.println(num); else System.out.println(num + “ is negative”);
GCF Factoring To find the GCF between two or more terms: 1)Factor Tree 2)List all factors 3)Find the largest # and variable that goes into all terms.
Warm Up 1. Name all sides and angles of ∆FGH. 2. What does it mean for two segments to be congruent? FG, GH, FH, F, G, H They have the same length.
Algebra II.  To remember everything in 1 st Semetser!
LAWS OF EXPONENTS LAW 1: (base)power x (same base)another power
C syntax (simplified) BNF. Program ::= [ ] Directives ::= [ ] ::= | |… ::=#include > ::=#define.
1.2 Linear Measure and Precision Objectives: Measure segments and determine accuracy of measurement. Compute with measures.
Holt Geometry 4-3 Congruent Triangles 4-3 Congruent Triangles Holt Geometry Warm Up Warm Up Lesson Presentation Lesson Presentation Lesson Quiz Lesson.
Introducing Simple Algebra
CS 160 – Summer 16 Exam 1 Prep.
MT262A Review.
Warm UP.
CSE 303 Concepts and Tools for Software Development
Do Now: 1) x = 8 2) x = 14 3) x = 6, –6 4) x = 9, –6.
C Fundamentals & Pointers
Theorems Involving Parallel Lines and Triangles
You found the relationship between the angle measures of a triangle. Recognize and apply properties of inequalities to the measures of the angles.
Measure Line Segments Unlike a line, a line segment, or segment, can be measured because it has two endpoints. A segment with endpoints A and B can be.
CS 200 Branches Jim Williams, PhD.
Basic Program Analysis: AST
פרק 3 ניתוח לקסיקאלי תורת הקומפילציה איתן אביאור.
2.3 Using Deductive Reasoning to Verify Conjectures
Algebraic Expressions
2.5 Proving Statements about Segments
5.7 Vocabulary CPCTC CPCTC is an abbreviation for the phrase “Corresponding Parts of Congruent Triangles are Congruent.” It can be used as a justification.
Passing by-value vs. by-reference in ARM
Congruence “Same size, same shape”
Selection CSCE 121 J. Michael Moore.
February 15 Your assignment: ASK QUESTIONS
CS Week 3 Jim Williams.
CPCTC uses congruent triangles to prove corresponding parts congruent.
Constructing a Triangle
Essentials of geometry
Proofs Section 4.8.
Warm-Up Add or subtract. 1) (5x2 + 4x + 2) + (-2x + 7 – 3x2)
Chapter 4: Control Structures I (Selection)
Programming Language C Language.
GEOMETRY 5.5 GEOMETRY 5.5 Review of 5.4 – Angles & Sides of a Triangle.
Warm-Up 5 minutes Add or subtract. 1) (5x2 + 4x + 2) + (-2x + 7 – 3x2)
Range check 範圍檢查: int age; int score; int month; 1-12
Presentation transcript:

Лекции марта 2016 г.

оператор объявления переменных : int a; char a, b = 5, c; присваивание ( Assign ): id = ; пустой оператор ; if( ) else while( ) for( |ε; ; | |ε) switch( ) { case значение1: … case значениеN: [default: ] } ввод значения с клавиатуры в переменную : in a; вывод значения выражения : out ; печать текста на экран : out “Hello, world!”; блок кода : { }

DeclareVars → Type DeclVarList ; Type → char | int DeclVarList → InitVar DeclVarList’ DeclVarList’ →, InitVar | ε InitVar → id InitVar’ InitVar’ → = num | ε StmtList → Stmt StmtList’ StmtList’ → Stmt StmtList’ | ε Stmt → DeclareVars | AssignOp | WhileOp | ForOp | IfOp | SwitchOp | IOp | OOp | ; | {StmtList} AssignOp → Assign ; Assign → id = E

WhileOp → while (E) Stmt ForOp → for (ForInit; ForExp; ForLoop) Stmt ForInit → Assign | ε ForExp → E | ε ForLoop → Assign | ++ id | -- id | ε IfOp → if ( E ) Stmt ElsePart ElsePart → else Stmt | ε SwitchOp → switch ( E ) { Cases } Cases → ACase Cases’ Cases’ → ACase Cases’ | ε ACase → case num : Stmt | default : Stmt IOp → in id ; OOp → out OOp’ ; OOp’ → E | str

№ ПравилоСемантическое определение 1 DeclareVars → Type p DeclVarList q ; q = p 2 Type p → char p = char 3 Type p → int p = int 4 DeclVarList p → InitVar q DeclVarList’ r r = p; q = r 5 DeclVarList’ p →, InitVar q q = p 6 DeclVarList’ p → ε 7 InitVar p → id q InitVar’ r setIdType(q,p); r = q 8 InitVar’ p → = num val {MOV} val,,p 9 InitVar’ p → ε 10 StmtList → Stmt StmtList’ 11 StmtList’ → Stmt StmtList’ 12 StmtList’ → ε

№ ПравилоСемантическое определение 1313 Stmt → DeclareVars 1414 Stmt → AssignOp 1515 Stmt → WhileOp 16 Stmt → ForOp 17 Stmt → IfOp 18 Stmt → SwitchOp 19 Stmt → IOp 20 Stmt → OOp 21 Stmt → ; 22 Stmt → {StmtList} 23 AssignOp → Assign ; 24 Assign → id p = E q {MOV} q,,p checkId(p) 25 WhileOp → while {LBL},,l1 ( E p ) {EQ} p,0,l2 Stmt {JMP},,l1 {LBL},,l2 l1 = newlab(); l2 = newlab()

№ ПравилоСемантическое определение 26 ForOp → for ( ForInit ; {LBL},,l1 ForExp p ; {EQ} p,0,l4 {JMP},,l3 {LBL},,l2 ForLoop {JMP},,l1 ) {LBL},,l3 Stmt {JMP},,l2 {LBL},,l4 l1 = newlab(); l2 = newlab() l3 = newlab(); l4 = newlab() 27 ForInit → Assign 28 ForInit → ε 29 ForExp p → E q p = q 30 ForExp p → ε p = ‘1’ 31 ForLoop → Assign 32 ForLoop → ++ id p {ADD} p1p checkId(p) 33 ForLoop → ε 34 IfOp → if ( E p ) {EQ} p,0,l1 Stmt {JMP},,l2 {LBL},,l1 ElsePart {LBL},,l2 l1 = newlab(); l2 = newlab() 35 ElsePart → else Stmt 36 ElsePart → ε

№ ПравилоСемантическое определение 37 SwitchOp → switch ( E p ) { Cases q,end } {LBL},,end q = p; end = newlab() 38 Cases p,end → ACase q,end1,def1 Cases’ r,end2,def2 q = r = p; end1 = end2 = end; def2 = def1 q = r = p; end1 = end2 = end; if(def >= 0 && def1 >= 0){ SYNTAX ERROR: two default sect. } else def2 = max(def, def1) 39 Cases’ p,end,def → ACase q,end1,def1 Cases’ r,end2,def2 40 Cases’ p,end,def → ε {JMP},,q if (def >= 0) q = def; else q = end 41 ACase p,end,def → case num val {NE} p,val,next : Stmt {JMP},,end {LBL},,next next = newlab(); def = ACase p,end,def → default : {JMP},,next {LBL},,def Stmt {JMP},,end {LBL},,next next = newlab(); def = newlab() 43 IOp → in id p ; {IN},,p checkId(p) 44 OOp → out OOp’ ; 45 OOp’ → E p {OUT},,p 46 OOp’ → str s {OUT},,s

№ ПравилоСемантическое определение 15E4 p → E3 q E4’ rs p = s; r = q 16E4’ pq → + E3 r {ADD} prs E4’ st q = t; s = Alloc() 17E4’ pq → - E3 r {SUB} prs E4’ st q = t; s = Alloc() 18 E4’ pq → ε q = p 19E3 p → E2 q E3’ rs p = s; r = q 20E3’ pq → * E2 r {MUL} prs E3’ st q = t; s = Alloc() 21 E3’ pq → ε q = p 22E2 p → ! E1 q {NOT} q,,r r = Alloc(); p = r 23E2 p → E1 q p = q 24E1 p → ++ id q {ADD} q1q p = q; checkId(q) 25E1 p → ( E q )p = q 26E1 p → num val p = val 27E1 p → id q E1’ rs p = s; r = q; checkId(q) 28E1’ pq → ++ {MOV} p,,r {ADD} p1p r = Alloc(); q = r 29E1’ pq → ε q = p

Напишите список атомов, который будет сгенерирован для следующих инструкций 1.if (a==b) while (x<y) Stmt 2.for (i = 1; i<=100; i = i+1) for (j = 1; j<=i; j = j+1) Stmt 3.if (a==b) for (i=1; i<=20; i=i+1) Stmt1 else while (i>0) Stmt2 4.if (a==b) if (b>0) Stmt1 else while (i>0) Stmt2 Упражнение 1

Напишите список атомов, который будет сгенерирован для следующего кода int a, b = 0; in a; while(a > 0){ a = a / 10; b++; } out a; Упражнение 2