700 likes | 781 Views
INF160 IS Development Environments AUBG, COS dept. Lecture 03 Title: Programming Languages (Extract from Syllabus). Lecture Contents:. Variety of Programming Languages Processing a HLL program Processing an Assembly language program Processing a Machine language program
E N D
INF160 IS Development Environments AUBG, COS dept Lecture 03 Title: Programming Languages (Extract from Syllabus)
Lecture Contents: • Variety of Programming Languages • Processing a HLL program • Processing an Assembly language program • Processing a Machine language program • Creating, Compiling and Running • VB programs • C++ programs • C# programs • Java programs
Introduction • There are many programming languages -- C, C++, Pascal, BASIC, FORTRAN, COBOL, and LISP are just a few. These are all high-level languages. One can also write programs in low-level languages called assembly languages, although this is more difficult. Low-level languages are closer to the language used by a computer, while high-level languages are closer to human languages. • Eventually, every program must be translated into a machine language that the computer can understand. This translation is performed by compilers, interpreters, and assemblers. • When you buy software, you normally buy an executable version of a program. This means that the program is already in machine language -- it has already been compiled and assembled and is ready to execute.
Hierarchy of PL C O M P U T E R - machine language - assembly language - high level language - natural language U S E R
Natural Language Sentence Add contents of Price and Tax, save result to Cost.
Typical HLL statement • High - Level Languages (C, C++, C#, VBasic, Java etc) • Resemble human language cost = price + tax;
Format of Assembly Language • Mnemonic CodeOp • Symbolic names for operands MOV AX, PRICE ADD AX, TAX STO AX, COST
Format of Assembly Language • Mnemonic CodeOp • Symbolic names for operands 0010 0000 0000 0100 MOV AX, PRICE 1000 0000 0000 0101 ADD AX, TAX 0011 0000 0000 0110 STO AX, COST
Format of ML instructions • Machine Language • Binary 0s and 1s that specify what to do • Format of ML instruction: • CodeOp, • 0, 1 or 2 Operands as memory addresses or immediate values • Example: 0010 0000 0000 0100 1000 0000 0000 0101 0011 0000 0000 0110
The Need of Language Processors A HLL program or an assembly language program has to be translated (compiled or interpreted) to its corresponding machine language form
VB, C++, C#, Java - High Level PL • In order to run /to execute/, any program written in HLL should be transformed to executable form • Three ways to convert source code into executable form: • Compiler – generate object code • Interpreter – interpret the source code • Compiler of hybrid (semi-interpreting) type
data Object program Executing computer Results Source program compiler Run time Compile time
Data Interpreter Results Source program Compile time Run time
data Object program in IL form Interpreter Results Source program compiler Compile2 time Run time Compile1 time
VB, C++, C#, Java - High Level PL • Java is compiled to intermediate form – byte code. Byte code processed by interpreter named JVM. • Visual Basic, C++ (managed code) and C# are compiled to intermediate form – MSIL code. MSIL code processed by interpreter named CLR. • C++ (native, yet unmanaged code) is compiled to directly executable native machine code. No intermediate code, no need of interpreter.
Implement the Code Source code is compiled to check for rule violations C# , VB, C++ (managed code) → Source code is converted into Microsoft Intermediate Language (IL) IL is between high-level source code and native code IL code not directly executable on any computer IL code not tied to any specific CPU platform Second step, managed by .NET’s Common Language Runtime (CLR), is required C# Programming: From Problem Analysis to Program Design 17
Implement the Code • CLR loads .NET classes • A second compilation, called a just-in-time (JIT) compilation, is performed • IL code is converted to the platform’s native code C# Programming: From Problem Analysis to Program Design Execution steps for .NET 18
How Java works . Java Programming: From Problem Analysis to Program Design, 4e 22
Problem-Analysis-Coding-Execution Cycle Java Programming: From Problem Analysis to Program Design, 4e 23
How Java Works • Java's platform independence is achieved by the use of the Java Virtual Machine (JVM). • A Java program consists of one or more files with a .java extension • these are just text (i.e. source) files. • When a Java program is compiled, the .java files are fed to the compiler which produces a .class file for each .java file. • The .class file contains Java bytecode. • Java byte code is like machine language, but it is intended for the Java Virtual Machine, not for a specific processor.
Creating, Compiling & Running HLL Programs • From Command Line Window • Details follow • From within IDE • Details in coming lectures
Three ways to open command line window • First approach: • Click Start (bottom left button) • Type: cmd
Three ways to open command line window • Second approach: • Click Start (bottom left button) • Select All Programs > • Select Accessories > • Click Command Prompt
Three ways to open command window • Third approach: • Click Start (bottom left button) • Select All Programs > • Select MS Visual Studio 2012 > • Select Visual Studio Tools > • Click Developer Command Prompt for VS 2012
Running text editor from command window To use NotePad, type notepad <file name> from the DOS prompt. To use WordPad, type write <file name> from the DOS prompt.
Compiling and Running VB programs • Compiling and Running VB programs
Compiling and Running VB programs • Using any text editor, type the source text of a VB demo program like this: Module myModule Sub Main() Console.WriteLine(“Hello from VB”) Console.ReadLine() End Sub End Module • Save the VB program as prog1.vb file.
Compiling and Running VB programs • The VB compiler is named vbc. • Run the compiler with statement like this: vbc prog1.vb • Run the application with a statement like this: prog1
Compiling and Running C++ programs • Compiling and Running C++ programs
Compiling and Running C++ programs • Using any text editor, type the source text of a C++ demo program like this: #include <iostream> using namespace std; void main() { cout << endl <<"Hello from C++"<<endl; system("pause"); } • Save the C++ program as a prog2.cpp file.
Compiling and Running C++ programs • The C++ compiler is named cl. • Run the compiler with statement like this: cl prog2.cpp • Run the application with a statement like this: prog2
Compiling and Running C# programs • Compiling and Running C# programs
Compiling and Running C# programs • Using text editor, type the source text of a C# demo program like this: using System; namespace myNamespace { public class myClass { public static void Main(string[] args) { Console.WriteLine("Hello from C#"); Console.ReadLine(); } // end of Main } // end of class } // end of namespace Save the C# program as a prog3.cs file.
Compiling and Running C# programs • Using any text editor, type the source text of a C# demo program like this: // no using System; namespace myNamespace { public class myClass { public static void Main(string[] args) { System.Console.WriteLine("Hello from C#"); System.Console.ReadLine(); } } } Save the modified C# program as a prog3.cs file.
Compiling and Running C# programs • The C# compiler is named csc. • Run the compiler with statement like this: csc prog3.cs • Run the application with a statement like this: prog3
Compiling and Running Java programs • Compiling and Running Java programs
Compiling and Running Java programs • Using any text editor, type the source text of a Java demo program like this: public class prog4 { public static void main(String[] args) { System.out.println("Hello from Java"); } } • Save the Java program as a prog4.java file.
Compiling and Running Java programs • The Java compiler is named javac. • Run the compiler with statement like this: javac prog4.java • Run the application with a statement like this: java prog4
Prog Lan (PL) – common features • Data • Operators, operands, expressions • Statements • Input/Output • Routines – program units • Module structure • Program
PL – Data • Data by category • Literal values • Named constants • Variables • Data by type • Boolean • Symbolic • Numeric
PL – Expressions=Oprnds+Operators • Operands • Literal, named constant, scalar variable, indexed variable, function call, subexpression • Operators • Precedence • Associativity • Number of operands
PL – Statements • Declaration/definition stmts • Executable stmts • Assignment • Selection/Decision • Iteration/Repetition
PL – Input/Output • RTL functions • OO approach • Stream based I/O