1 / 21

CPSC 388 – Compiler Design and Construction

CPSC 388 – Compiler Design and Construction. Evolution of Programming Languages Programming Language Basics Make. 1940. 1950. 1960. 1970. 1980. 1990. 2000. Evolution of Programming Languages. Postscript. Machine Code. Prolog. Assembly. Pascal. Python. Fortran. C. Java. Cobol.

alessa
Télécharger la présentation

CPSC 388 – Compiler Design and Construction

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. CPSC 388 – Compiler Design and Construction Evolution of Programming Languages Programming Language Basics Make

  2. 1940 1950 1960 1970 1980 1990 2000 Evolution of Programming Languages Postscript Machine Code Prolog Assembly Pascal Python Fortran C Java Cobol Basic Lisp Scheme

  3. Types of Programming Languages • Imperative Languages • Declarative Languages Languages which specify HOW a computation is to be done. C, C++, C#, Java, Python, Perl, … Languages which specify WHAT computation is to be done. ML, Prolog, Haskell, …

  4. Programming Language Basics • Static/Dynamic Distinction • Environments and States • Static Scope and Block Structure • Explicit Access Control • Dynamic Scope • Parameter Passing • Aliasing

  5. Static / Dynamic Distinction • Static • Dynamic Issue can be decided at compile time Issue cannot be decided until runtime Example: public static int x;

  6. Environments and States environment state • Static vs. Dynamic binding of names to locations Globals can be static, others dynamic • Static vs. Dynamic binding of locations to values Constants can be static, others dynamic (Strings in Java are imutable) names values locations (variables)

  7. Block Static Scope and Block Structure main() { int a = 1; int b = 1; { int b = 2; { int a = 3; cout << a << b; } { int b = 4; cout << a << b; } cout << a << b; } cout << a << b; } Declaration D “belongs” to block B If B is the most closely nested block containing D. Scope of declaration D is the block Containing D and all sub-blocks That don’t redeclare D.

  8. Explicit Access Control • Classes introduce new scoping for data members. • Subclasses act like sub-blocks • public, private, and protected limit access to data members

  9. Which declaration Of x() is called? Dynamic Scope Use of name x refers to the declaration of x in the most recently called,not-yet-terminated, procedure with such a declaration. class Foo { public void x(){ } } class Bar extends Foo { public void x(){ } } … Foo foo; … foo.x(); …

  10. Dynamic Scoping vs. Static Scoping • Static is most closely related declaration in space • Dynamic is most closely related declaration in time

  11. Parameter Passing How do actual parameters associate to formal parameters? • Call by Value • Call by Reference A copy of actual parameter is made and placed in formal parameter The address of actual parameter is passed as value of the formal parameter

  12. Aliasing • When two names refer to the same location in memory • Effects optimization step of compilers

  13. Make Utility • Defines which components go together to make a program. • Defines how to "put the pieces together". • Keeps track of dependencies among components. • Helps avoid doing unnecessary work and forgetting to do necessary work (in particular, it is usually used to control (re)compilation of code that depends on code in other files).

  14. Using Make • Create a file named “makefile” or “Makefile” • A makefile contains a set of rules containing • a target (usually a file name) • a list of files on which the target depends • a command to be executed to create the target file

  15. Target Dependencies Command Example makefile examples.class: examples.java IO.class Sequence.class javac examples.java Sequence.class: Sequence.java NoCurrentException.class javac Sequence.java NoCurrentException.class: NoCurrentException.java javac NoCurrentException.java IO.class: IO.java javac IO.java Line must begin with a tab

  16. Dependencies • "A depends on B" means: if B changes, then A may need to be recreated • Target xxx.class dependency list should include all files that define classes that are used in xxx.java (and xxx.java) • What classes use what other class in last example?

  17. Running Make • Type make target-name • Or just type make The first target will be created • Try it out (login to linux machine)

  18. More with Make • Create targets to do useful things clean: rm –f *.class *~ • Use variables in makefile JC = /usr/bin/javac JFLAGS = -g IO.class: IO.java $(JC) $(JFLAGS) IO.java

  19. More with Make test: examples.class java examples $(INPUT) then type the command: make test INPUT=in.data

  20. Make and Slow Javac examples.class: examples.java Sequence.java NoCurrentException.java IO.java javac examples.java Sequence.java NoCurrentException.java IO.java Sequence.class: Sequence.java NoCurrentException.class javac Sequence.java NoCurrentException.class: NoCurrentException.java javac NoCurrentException.java IO.class: IO.java javac IO.java

  21. More About Make http://www.gnu.org/software/make/manual/make.html

More Related