cpsc 388 – compiler design and construction
DESCRIPTION
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. - PowerPoint PPT PresentationTRANSCRIPT
CPSC 388 – Compiler Design and Construction
Evolution of Programming LanguagesProgramming Language BasicsMake
Evolution of Programming Languages
1940 1950 1960 1970 1980 1990 2000
Machine Code
Assembly
FortranCobol
Lisp
C
SchemeBasic
Postscript
Java
PythonPascal
Prolog
Types of Programming Languages
Imperative Languages
Declarative Languages
Languages which specify HOW a computation is to be done.
Languages which specify WHAT computation is to be done.
C, C++, C#, Java, Python, Perl, …
ML, Prolog, Haskell, …
Programming Language Basics
Static/Dynamic Distinction Environments and States Static Scope and Block Structure Explicit Access Control Dynamic Scope Parameter Passing Aliasing
Static / Dynamic Distinction
Static
Dynamic
Example:public static int x;
Issue can be decided at compile time
Issue cannot be decided until runtime
Environments and States
Static vs. Dynamic binding of names to locationsGlobals can be static, others dynamic
Static vs. Dynamic binding of locations to valuesConstants can be static, others dynamic (Strings in
Java are imutable)
names locations(variables)
values
environment state
Static Scope and Block Structuremain() {
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;
}
Block
Declaration D “belongs” to block BIf B is the most closely nestedblock containing D.
Scope of declaration D is the blockContaining D and all sub-blocksThat don’t redeclare D.
Explicit Access Control
Classes introduce new scoping for data members.
Subclasses act like sub-blocks public, private, and protected limit
access to data members
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();…
Which declarationOf x() is called?
Dynamic Scoping vs. Static Scoping
Static is most closely related declaration in space
Dynamic is most closely related declaration in time
Parameter Passing
How do actual parameters associate to formal parameters?
Call by Value
Call by Reference
A copy of actual parameter is madeand placed in formal parameter
The address of actual parameter is passedas value of the formal parameter
Aliasing
When two names refer to the same location in memory
Effects optimization step of compilers
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).
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
Example makefileexamples.class: examples.java IO.class Sequence.class
javac examples.javaSequence.class: Sequence.java NoCurrentException.class
javac Sequence.javaNoCurrentException.class: NoCurrentException.java
javac NoCurrentException.javaIO.class: IO.java
javac IO.java
Target Dependencies Command
Line must begin with a tab
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?
Running Make
Typemake target-name
Or just type make
The first target will be created Try it out (login to linux machine)
More with Make
Create targets to do useful thingsclean:
rm –f *.class *~
Use variables in makefileJC = /usr/bin/javac
JFLAGS = -g
IO.class: IO.java
$(JC) $(JFLAGS) IO.java
More with Make
test: examples.class
java examples $(INPUT)
then type the command:make test INPUT=in.data
Make and Slow Javacexamples.class: examples.java Sequence.java NoCurrentException.java IO.java
javac examples.java Sequence.java NoCurrentException.java IO.javaSequence.class: Sequence.java NoCurrentException.class
javac Sequence.javaNoCurrentException.class: NoCurrentException.java
javac NoCurrentException.javaIO.class: IO.java
javac IO.java
More About Make
http://www.gnu.org/software/make/manual/make.html