Computing Fundamentals Using Python PDF
Document Details
PES University
Ms. Archana A
Tags
Summary
This document is a presentation on computing fundamentals using Python, covering topics such as compilers, interpreters, syntax errors, and semantic errors. It's targeted at undergraduate students in computer science.
Full Transcript
COMPUTING FUNDAMENTALS USING PYTHON Ms. Archana A Assistant Professor Department of Computer Applications COMPUTING FUNDAMENTALS USING PYTHON Computing Fundamentals… Archana A Department of Computer Applications COMPUTING FUNDAMENTALS USING PYTHON Computing Fundamentals Program Translation A...
COMPUTING FUNDAMENTALS USING PYTHON Ms. Archana A Assistant Professor Department of Computer Applications COMPUTING FUNDAMENTALS USING PYTHON Computing Fundamentals… Archana A Department of Computer Applications COMPUTING FUNDAMENTALS USING PYTHON Computing Fundamentals Program Translation A central processing unit (CPU) is designed to interpret and execute a specific set of instructions represented in binary form (i.e., 1s and 0s) called machine code. Only programs in machine code can be executed by a CPU. COMPUTING FUNDAMENTALS USING PYTHON Computing Fundamentals Writing programs at this “low level” is tedious and error-prone. Therefore, most programs are written in a “high-level” programming language such as Python. Since the instructions of such programs are not in machine code that a CPU can execute, a translator program must be used. COMPUTING FUNDAMENTALS USING PYTHON Computing Fundamentals There are two fundamental types of translators: Compiler translates programs into machine code to be executed by the CPU (C, C++, Java) Interpreter executes instructions in place of the CPU (Perl, Python etc.) COMPUTING FUNDAMENTALS USING PYTHON Computing Fundamentals 1. Compiler A compiler takes the source code as a whole and translates it into object code all in one go. Once converted, the object code can be run unassisted at any time. This process is called compilation Compiled programs generally execute faster than interpreted programs. COMPUTING FUNDAMENTALS USING PYTHON Computing Fundamentals Compiler: It is a translator which takes input i.e., High-Level Language, and produces an output of low-level language i.e. machine or assembly language. A compiler is more intelligent than an assembler it checks all kinds of limits, ranges, errors, etc. But its program run time is more and occupies a larger part of memory. It has slow speed because a compiler goes through the entire program and then translates the entire program into machine codes. COMPUTING FUNDAMENTALS USING PYTHON Computing Fundamentals Compiler: COMPUTING FUNDAMENTALS USING PYTHON Computing Fundamentals 2. Interpreter An interpreter is a program that translates a programming language into a comprehensible language. – It translates only one statement of the program at a time. Interpreters, more often than not are smaller than compilers. COMPUTING FUNDAMENTALS USING PYTHON Computing Fundamentals Interpreter An interpreter can immediately execute instructions as they are entered. This is referred to as interactive mode. This is a very useful feature for program development. Python, as we shall see, is executed by an interpreter. COMPUTING FUNDAMENTALS USING PYTHON Computing Fundamentals Compiler Interpreter Compiler scans the whole program in Translates program one statement at a 1. one go. time. As it scans the code in one go, the Considering it scans code one line at a 2. errors (if any) are shown at the end time, errors are shown line by line. together. Due to interpreters being slow in Main advantage of compilers is it’s 3. executing the object code, it is preferred execution time. less. It converts the source code into It does not convert source code into 4. object code. object code instead it scans it line by line It does not require source code for It requires source code for later 5 later execution. execution. Python, Ruby, Perl, SNOBOL, MATLAB, Eg. C, C++, C# etc. etc. COMPUTING FUNDAMENTALS USING PYTHON Computing Fundamentals What are Syntax Errors and Semantic Errors? Syntax errors are caused by invalid syntax `for example, entering prnt instead of print. Since a translator cannot understand instructions containing syntax errors, translators terminate when encountering such errors indicating where in the program the problem occurred. COMPUTING FUNDAMENTALS USING PYTHON Computing Fundamentals In contrast, semantic errors (generally called logic errors ) are errors in program logic. Such errors cannot be automatically detected, since translators cannot understand the intent of a given computation. COMPUTING FUNDAMENTALS USING PYTHON Computing Fundamentals. THANK YOU Ms. Archana A Assistant Professor Department of Computer Science [email protected] +91 80 6666 3333 Extn 392