11
Unit 1, Lesson 3 Program Execution Process AOIT Introduction to Programming ight © 2009–2012 National Academy Foundation. All rights reserved.

Unit 1, Lesson 3 Program Execution Process AOIT Introduction to Programming Copyright © 2009–2012 National Academy Foundation. All rights reserved

Embed Size (px)

Citation preview

Page 1: Unit 1, Lesson 3 Program Execution Process AOIT Introduction to Programming Copyright © 2009–2012 National Academy Foundation. All rights reserved

Unit 1, Lesson 3

Program Execution Process

AOITIntroduction to Programming

Copyright © 2009–2012 National Academy Foundation. All rights reserved.

Page 2: Unit 1, Lesson 3 Program Execution Process AOIT Introduction to Programming Copyright © 2009–2012 National Academy Foundation. All rights reserved

When Python executes circle.py, it draws a red circle

from turtle import *title("circle program")setup()turtle.up()turtle.goto(0,20)turtle.down()turtle.color("red")turtle.width(2)turtle.begin_fill()turtle.circle(50)turtle.end_fill()done()

Page 3: Unit 1, Lesson 3 Program Execution Process AOIT Introduction to Programming Copyright © 2009–2012 National Academy Foundation. All rights reserved

Program execution begins with

Start

Before you begin to run a program, think about the results you expect. What does circle.py do? What is the output?

Start

Hardware ComponentsSoftware Components

• Program execution is ready to start when IDLE is open and you have opened circle.py.

• Each step of the program execution process includes software and hardware components.

Page 4: Unit 1, Lesson 3 Program Execution Process AOIT Introduction to Programming Copyright © 2009–2012 National Academy Foundation. All rights reserved

In step 1, the user selects Run Module

1 Start

1. User: Run > Run Module

Hardware ComponentsSoftware Components

Computer processor, disk

drive, and mouse

Python shell and .py file

In which IDLE window is the Run menu?

Using the mouse, the user selects Run > Run Module.

What do you know about the software and hardware components used in this step?

Page 5: Unit 1, Lesson 3 Program Execution Process AOIT Introduction to Programming Copyright © 2009–2012 National Academy Foundation. All rights reserved

In step 2, the parser deconstructs the program

1 Start

2 User: Run > Run Module

Hardware ComponentsSoftware Components

Computer processor, disk drive, and mousePython shell and .py

file

2. Read in and parse program

Python parser and

.py file

Computer processor and

disk drive

What do you suppose “deconstruct” means?

The parser reads in the Circle program and deconstructs it into its primitive components.

Page 6: Unit 1, Lesson 3 Program Execution Process AOIT Introduction to Programming Copyright © 2009–2012 National Academy Foundation. All rights reserved

In step 3, the parser displays an error, if any

1 Start

2 User: Run > Run Module

Hardware ComponentsSoftware Components

Computer processor, disk drive, and mousePython shell and .py

file

3 Read in and parse program Python parser and .py file

Computer processor and disk drive

3. If syntax error

Send error message and

exit

Yes

No

If the parser detects an error, it stops runningand returns an error message to the screen.If there is no error, the parser keeps running.

The pop-up error message always says the same thing. What is it?

Page 7: Unit 1, Lesson 3 Program Execution Process AOIT Introduction to Programming Copyright © 2009–2012 National Academy Foundation. All rights reserved

In step 4, the parser builds an execution table

Start

4. Build execution tablePython parser and

.py file

Computer processor and

disk drive

2 User: Run > Run Module

Hardware ComponentsSoftware Components

Computer processor, disk drive, and mousePython shell and .py

file

3 Read in and parse program Python parser and .py file

Computer processor and disk drive

If Syntax Error 4 Send error

message and exit

Yes

No

The parser builds an execution table. This table contains a description of each statement in the program.

Why might the parser need to build an execution table? Why couldn’t it always read the program top to bottom, left to right, like a book?

Page 8: Unit 1, Lesson 3 Program Execution Process AOIT Introduction to Programming Copyright © 2009–2012 National Academy Foundation. All rights reserved

In step 5, the executor runs the program

1 Start

2 User: Run > Run Module

Hardware ComponentsSoftware Components

Computer processor, disk drive, and mousePython shell and .py

file

3 Read in and parse program Python parser and .py file

Computer processor and disk drive

If Syntax Error 4 Send error

message and exit

5. Execute program Python executor and .py file

Computer processor and

screen

5 Build execution table Python parser and .py file

Computer processor and disk drive

Yes

No

A software component called the Python executor runs the program by calling internal machine instruction functions one after the other. For circle.py, this means the machine instruction functions actually draw the circle.

What are some functions you have seen in Python programs?

Page 9: Unit 1, Lesson 3 Program Execution Process AOIT Introduction to Programming Copyright © 2009–2012 National Academy Foundation. All rights reserved

In step 6, the executor returns control to the shell

Start

2 User: Run > Run Module

Hardware ComponentsSoftware Components

Computer processor, disk drive, and mousePython shell & .py file

3 Read in and parse program Python parser and .py file

Computer processor and disk drive

If Syntax Error 4 Send error

message and exit

6 Execute program Python executor and .py file

Computer processor and screen

6. End program and wait for drawing window to

be closed

5 Build execution table Python parser and .py file

Computer processor and disk drive

Python shell Computer processor, screen,

and mouse

Yes

No

When the executor reaches the last statement, it returns control to the shell. The shell waits for the drawing window to be closed.

What is the last statement of the Circle program?

Page 10: Unit 1, Lesson 3 Program Execution Process AOIT Introduction to Programming Copyright © 2009–2012 National Academy Foundation. All rights reserved

The end point is always

Start

End

2 User: Run > Run Module

Hardware ComponentsSoftware Components

Computer processor, disk drive, and mousePython shell and .py

file

3 Read in and parse program Python parser and .py file

Computer processor and disk drive

If Syntax Error 4 Send error

message and exit

6 Execute program Python executor and .py file

Computer processor and screen

7 End program and wait for drawing window to be closed

5 Build execution table Python parser and .py file

Computer processor and disk drive

Python shell Computer processor, screen, and mouse

Yes

No

When the program ends, the drawing window closes.

What is the drawing window?

End

Page 11: Unit 1, Lesson 3 Program Execution Process AOIT Introduction to Programming Copyright © 2009–2012 National Academy Foundation. All rights reserved

The program execution process draws the circle

Start

End

1. User: Run > Run Module

Hardware ComponentsSoftware Components

Computer processor, disk drive, and mousePython shell and .py

file

2. Read in and parse program

Python parser and .py file

Computer processor and disk drive

If syntax error

3. Send error message and exit

5. Execute program Python executor and .py file

Computer processor and screen

6. End program and wait for drawing window to be closed

4. Build execution table Python parser and .py file

Computer processor and disk drive

Python shell Computer processor, screen, and mouse

Yes

No