Download presentation
Presentation is loading. Please wait.
1
Programming languages
The most part of modern programming languages has been designed to be easy to use and understand; for this reason, these languages are defined high-level languages (like Pascal, C, Java, C++, C#). The computer is not able to directly understand the high-level languages, so this has or to be translated into another language, understandable by the computer, or to be interpreted by another computer program already in an executable form that translates the high-level language and then acts directly the commands of the program. The language that the computer can understand is called machine language and it is in a binary form (0/1). Between binary code and high-level languages there are assembly languages. Assembly languages are a symbolic representation of the machine language, that still requires to transform mnemonic codes in binary codes before it can be executed by the computer. Assembly languages are defined low-level language.
2
Programming languages
To write a program any editor program that allows the writing of a plain text is required. In general the editor is part of an so called IDE (Integrated Development Environment) that integrate en editor, a compiler, an assembler and a linker. In general an IDE integrates also other tools, like debuggers that permits to execute step by step a program controlling the state of the execution.
3
Compilation The translation of a program from a high-level language to a low level language is made by another program called a compiler. The compiler processes the program written in high level language to produce an executable code that it can run on the computer. This process is called “program compilation”. Once compiled, you can run the resulting program as many times as you want without having to recompile. The input program of the compiler is called the source program or source code; The machine language program generated by the compiler is called object program or object code. The compilation process can be divided in two phases. The first is the actual compilation that transforms the source code file in an assembly code file, and the second is the assembling phase where the assembly code is translated into binary code.
4
Interpretation Some high-level languages are not translated by compilers, but from another type of programs, called interpreters. As a compiler, an interpreter translates the instructions of a program from a high level, but, unlike a compiler, an interpreter performs each piece of code immediately after translated, instead of translating the entire program before. In the case of interpretation the source code could be translated many times, every time that the same code is executed. This requires more time to translate the code then compilation.
5
Bytecode interpretation
Java uses a slightly different approach, which combines compilation and interpretation. The Java compiler does not translate the program into the specific language of the computer, but translates it into a binary code called bytecode. The bytecode is not a machine language of any computer. It's a machine language of a virtual machine. To run a program written in bytecode on a real computer is easy. The program that does the run is a kind of interpreter called the Java Virtual Machine (JVM). The JVM is a program that reads the byte code derived from a compilation and executes it on a given computer. To run all the programs that are in bytecode on a new computer needs just to implement the JVM for that computer.
6
Compilation process from a source file to an executable file
A source file is a text file containing a sequence of instructions (called source code) written in a programming language (at a high level) ready to be transformed by a special process into an executable program or to be interpreted by a special interpreter. In computing, an executable file, or simply an executable, is a file that contains an executable program for a computer, a machine language program written in a format to be loaded by the operating system, and then ready to run. The compiler is a program that can read, understand and convert (translate) a set of instructions written in a programming language (source code), into instructions of another language (assembly code). This process is called “compilation”. After compilation the assembly code is translated by another program in a binary code (object code). Usually these two steps are both considered the “compilation”. Object code is not yet executable because it needs to be integrated by other parts of code like library functions.
7
Pure compilation like in C language
… int min(int a, int b) { if (a<b) c=a; else c=b; } mov a,R1 mov b,R2 tst jlt less mov R1,c jmp end less: mov R2,c end: compiler assembler <name>.c <name>.asm <name>.obj
8
Compilation process from a source file to an executable file
To obtain an executable code it’s necessary to link together different parts of object code coming from other compilations or from code libraries. This code is inserted in a unique file after connecting the different parts in a single program. Object code can come from separate compilations used to avoid to compile every time too much source code. In separate compilation only some functions are compiled to control syntactic correctness and to produce the object code. Code libraries contains pieces of object code of general use provided with the compiler to avoid to the programmer to code usual functions as I/O or mathematical functions. The program that produces the executable file from object codes is called linker. To execute the program it’s enough to tell to the operating system the name of the executable program to execute.
9
Pure compilation like in C language
… int min(int a, int b) { if (a<b) c=a; else c=b; } mov a,R1 mov b,R2 tst jlt less mov R1,c jmp end less: mov R2,c end: compiler assembler <name>.c <name>.asm <name>.obj <other name>.obj … PC linker <some name>.lib <name>.exe
10
Interpretation process from a source file to a run
The interpreter is a program that can read, understand and convert a set of instructions written in a programming language (source code) and execute them directly on a given computer. This process is called “interpretation”. This means that in the case a part of the code must be executed many times the interpreter needs to translate the code every time. This process needs to use the same computation time more and more times. As translating a line of code need tenth if not hundreds of times the time of the execution of the same code, is evident that interpretation is a time wasting process. In general interpretation is used during the development process or for naives programs.
11
Interpretation like in Basic language
… If a<b then c=a; else c=b; PC interpreter <name>.bas
12
Bytecode compilation process from a source file to bytecode
To write a program in Java involves writing one or more files containing the classes’ code. The name of a class file must be <class name>.java The class name must begin with a capital letter. (Ex. Point.java) The .java files are compiled by the Java compiler that comes with the Java SDK (Standard Development Kit); the command to compile is javac <class name>.java The Java compiler creates the file in bytecode format with the name <class name>.class. If within the code of a class other inner classes are declared will result in more of a .class file. At least one of the created classes must have a static method called main that will be activated for first by the JVM. That will be the main class and to execute the program is needed to run that class. The command for the execution of a class is java <class name> The JVM loads other classes as they are needed from single files or from Java Archive files (.jar) at run time.
13
Pure compilation like in C language
… int min(int a, int b) { if (a<b) c=a; else c=b; } compiler <name>.java <name>.class <other name>.class PC JVM <some name>.jar
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.