1 / 70

INF160 IS Development Environments AUBG, COS dept

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

vian
Download Presentation

INF160 IS Development Environments AUBG, COS dept

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. INF160 IS Development Environments AUBG, COS dept Lecture 03 Title: Programming Languages (Extract from Syllabus)

  2. 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

  3. 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.

  4. Hierarchy of PL C O M P U T E R - machine language - assembly language - high level language - natural language U S E R

  5. Natural Language Sentence Add contents of Price and Tax, save result to Cost.

  6. Typical HLL statement • High - Level Languages (C, C++, C#, VBasic, Java etc) • Resemble human language cost = price + tax;

  7. Format of Assembly Language • Mnemonic CodeOp • Symbolic names for operands MOV AX, PRICE ADD AX, TAX STO AX, COST

  8. 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

  9. 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

  10. 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

  11. 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

  12. data Object program Executing computer Results Source program compiler Run time Compile time

  13. Data Interpreter Results Source program Compile time Run time

  14. data Object program in IL form Interpreter Results Source program compiler Compile2 time Run time Compile1 time

  15. 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.

  16. How VB, C#, managed C++ work

  17. 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

  18. 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

  19. How native, unmanaged C++ works

  20. How Java works . Java Programming: From Problem Analysis to Program Design, 4e 22

  21. Problem-Analysis-Coding-Execution Cycle Java Programming: From Problem Analysis to Program Design, 4e 23

  22. 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.

  23. JVM emulation run on a physical machine

  24. JVM handles translations

  25. Creating, Compiling & Running HLL Programs • From Command Line Window • Details follow • From within IDE • Details in coming lectures

  26. Three ways to open command line window • First approach: • Click Start (bottom left button) • Type: cmd

  27. Three ways to open command line window • Second approach: • Click Start (bottom left button) • Select All Programs > • Select Accessories > • Click Command Prompt

  28. 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

  29. 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.

  30. Compiling and Running VB programs • Compiling and Running VB programs

  31. 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.

  32. 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

  33. Compiling and Running C++ programs • Compiling and Running C++ programs

  34. 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.

  35. 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

  36. Compiling and Running C# programs • Compiling and Running C# programs

  37. 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.

  38. 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.

  39. 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

  40. Compiling and Running Java programs • Compiling and Running Java programs

  41. 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.

  42. 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

  43. Prog Lan (PL) – common features • Data • Operators, operands, expressions • Statements • Input/Output • Routines – program units • Module structure • Program

  44. PL – Data • Data by category • Literal values • Named constants • Variables • Data by type • Boolean • Symbolic • Numeric

  45. PL – Expressions=Oprnds+Operators • Operands • Literal, named constant, scalar variable, indexed variable, function call, subexpression • Operators • Precedence • Associativity • Number of operands

  46. PL – Statements • Declaration/definition stmts • Executable stmts • Assignment • Selection/Decision • Iteration/Repetition

  47. PL – Input/Output • RTL functions • OO approach • Stream based I/O

More Related