Download presentation
Presentation is loading. Please wait.
Published byMatilda Stewart Modified over 8 years ago
1
Compiled and Interpreted Languages CS 480/680 – Comparative Languages
2
Compiling and Interpreting2 Compiling High Level Languages Source Code (text) Compiler Assembly (text) Assembler Relocatable Object Code (machine code without addresses) Linker/Loader Executable Code (machine code)
3
Compiling and Interpreting3 The Compilation Process (1) C++ int var1, var2; void main() { var1 = 5; var2 = 37; var2 /= var1; cout << var2 << endl; } Assembly SECTION MAIN,CODE XREFPRINTINT _MAINMOVE.W#5,VAR1 MOVE.W#7,VAR2 MOVE.WVAR1,D1 MOVE.WVAR2,D2 EXT.LD2 DIVS.WD1,D2 MOVE.WD2,VAR2 MOVE.WVAR2,-(SP) JSRPRINTINT MOVE.W#228,D7 TRAP#14 VAR1DS.L1 VAR2DS.L1 END
4
Compiling and Interpreting4 The Compilation Process (2) 1SECTION MAIN,CODE 2 XREFPRINTINT 00000000 33FC 0005 00000038 3 _MAINMOVE.W#5,VAR1 00000008 33FC 0007 0000003C 4 MOVE.W#7,VAR2 00000010 3239 00000038 5 MOVE.WVAR1,D1 00000016 3439 0000003C 6 MOVE.WVAR2,D2 0000001C 48C2 7 EXT.LD2 0000001E 85C1 8 DIVS.WD1,D2 00000020 33C2 0000003C 9 MOVE.WD2,VAR2 00000026 3F39 0000003C 10 MOVE.WVAR2,-(SP) 0000002C 4EB9 00000000 11 JSRPRINTINT 00000032 3E3C 00E4 12 MOVE.W#228,D7 00000036 4E4E 13 TRAP#14 00000038 14 VAR1DS.L1 0000003C 15 VAR2DS.L1 00000040 16 END
5
Compiling and Interpreting5 The Compilation Process (3) #SECTION_CODE 00000040 MAIN 000000 33FC00050000003833FC00070000003C 000010 32390000003834390000003C48C285C1 000020 33C20000003C3F390000003C4EB90000 000030 00003E3C00E44E4E0000000000000000 #LOCAL 00000004 0000000C 00000012 00000018 00000022 00000028 #XREF_32 PRINTINT 0000002E MOVE.W#5,VAR1 = loader = linker
6
Compiling and Interpreting6 Advantages of Compiled Higher Languages Abstraction of hardware details Allow a program to more easily be ported to other hardware platforms Can be tailored for specific types of applications Web programming Logic programming
7
Compiling and Interpreting7 Interpreted Languages Interpreted languages are not compiled The source code is run directly Often compiled into a more efficient pseudo- language just before running Only machine code can run on the CPU, so how does an interpreted language run? The interpreter is an executable program which interprets the source code and runs the appropriate machine code.
8
Compiling and Interpreting8 Compiled and Interpreted Languages Compilation Executable Input Output Interpreter ProgramInput Output Source Compiled Interpreted
9
Compiling and Interpreting9 Example of Interpreted Code #!/usr/bin/perl $var1 = 7; $var2 = ”008”; $var3 = $var1 * $var2; print ”Result: $var3\n”; $string = ’print ”program ending now\n”’; eval $string; exit; $> perl myscript Result: 56 program ending now
10
Compiling and Interpreting10 Eval() A key advantage of interpreted languages is that they can build and execute code on-the-fly Essentially, the “compiler” is built into the interpreter program How hard would this be for a compiled language?
11
Compiling and Interpreting11 Pros and Cons of Interpreted Languages Advantages of interpreted languages Fast (program development) and messy Untyped variables On-the-fly variable creation Eval() Extremely portable code Powerful Lean (only the interpreter is fat)
12
Compiling and Interpreting12 Pros and Cons of Interpreted Languages Disadvantages of interpreted languages Much slower to execute Can be very hard to debug: Linking is an issue – may not be appropriate for large-scale software development $count = 0; while ($counnt < 100) { … $count++; }
13
Compiling and Interpreting13 Programming Tradeoffs Efficiency Abstraction (Ease of use, specialization, paradigm enforcing, etc.) Assembly C C++ Java, Lisp Perl, Python, Ruby, etc. Fortran, Pascal
14
Compiling and Interpreting14 Some High Level Languages InterpretedCompiled Object-oriented Ruby, Python, Java C++ ImperativePerl C, C++, FORTRAN, Pascal FunctionalLISP, SchemeLISP, ML
15
Compiling and Interpreting15 A Brief History of Programming Languages
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.