Levels of Programming Languages 1.Low level languages 2.High level languages
Low level languages Machine language Machine language Directly executable by CPU Assembly language Machine dependent Mnemonic codes ( 易記碼 ) each opcode Need to translate to machine code first – not directly executable
High level language Machine independent and portable Human like language 3GL C, Fortran, COBOL, BASIC, PASCAL, etc. 4GL SQL (Structured Query Language)
3GL LanguageFull nameApplication COBOL Common Business Oriented Language Commercial Prolog Programming in logic Artificial Intelligence ( 人工 智能 ) expert systems LISP List Processing BASIC Beginner's All- purpose Symbolic Instruction Code General purpose FORTRAN Formula TranslatorScientific
4GL e.g. SQL command select * from student order by class, class_no; - display all the student records in the database table “student” in ascending order of class and class_no.
Advantages of high-level language over low-level language Advantages of HIGH level language Reasons 1. More effectiveDesigned to solve problem 2. Easier to learn, write, read and modify Instructions are English-like format 3. Programs are shorter in length One high-level language statement take the place of many machine instructions 4. Portable (can use in different computers with little modification) Machine-independent
Advantages of low-level language over high-level language Advantages of LOW level language Reasons 1. More efficientHardware features, like bus width, is fully made use of 2. Require smaller memory space to run Fewer low-level instructions are needed to do the same task (no redundant instructions produced by a translator) 3. Precise control of hardware Some low-level instructions are designed specifically for controlling the hardware at low level
Translators Is a software Converts the source code into machine instructions Syntax errors of a program are detected in the translation phase Three types of translators: assembler, compiler, interpreter
Assembler Produces one machine instruction for each assembly language statement Translates the whole source program before execution takes place
Compiler Converts the whole source program before execution takes place The computer needs the object program only
Interpreter No object program is produced The translated machine instructions CANNOT be reused Interpreter must be present
Comparison of Translators AssemblerCompilerInterpreter Translate low- level language into machine language Translate high-level language into machine language A new file, called object program, is created No new file is produced Programs run fasterPrograms run slower
Comparison of Translators AssemblerCompilerInterpreter Translate the whole source programTranslate and execute a statement at a time Less convenient for programmer. Every change in the source program needs compilation Convenient for programmer Programmer can hide the source program The source program must be present Translator is not necessary at run-timeTranslator is necessary at run-time
Machine instruction Op. codeOperand Op. code is the operation to be performed. Operand is the data to be acted on.