CSCE 314 Programming Languages

Download Report

Transcript CSCE 314 Programming Languages

CSCE 314
Programming Languages
John Keyser
Spring 2016
CSCE 314 – Programming Studio
About the course (syllabus overview)
• Instructor
• John Keyser
• Office Hours
• Generally, MW 2:00-3:00
• Today: 1:30-2:30
• Monday 1/25: cancelled
• TA
• Mengyuan Chao
• Peer Teachers
• Other section (taught by Dylan Shell)
Spring 2016
CSCE 314 – Programming Studio
Course stuff
• Prerequisite:
• CSCE 221
• Textbooks
• Hutton: Programming in Haskell
• Arnold, Gosling, Holmes: The Java Programming Language
• Course webpage
• Will be up soon (today?)
• http://courses.cse.tamu.edu/keyser/csce314
• Piazza
• Will be used for class discussions
• Get a head start – sign up now...
Spring 2016
CSCE 314 – Programming Studio
Grades
• Exams (60%):
•
•
•
•
Midterm: 25% (just before Spring Break)
Final: 35% (at time assigned)
Final will be comprehensive, but weighted toward later material
Expect exams to be open book (details will come later)
• Assignments (40%):
• Turn in via CSNet
• Late penalty: 10% first day, 20% second day, 100% thereafter
Spring 2016
CSCE 314 – Programming Studio
Collaboration
• Work should be your own
• The rest should be common sense…
• Make sure you acknowledge any outside help
Spring 2016
CSCE 314 – Programming Studio
So, what’s the point of this course?
Understanding programming languages!
Spring 2016
CSCE 314 – Programming Studio
The Big Picture
Haskell
sum [] = 0
sum (x:xs) = x +
sum xs
C
a = 13
if (a>3)
c=10
Spring 2016
ASSEMBLY
mov rdx, 7
mov eax, 3
jmp eax
100100101101
101010010010
001010000111
CSCE 314 – Programming Studio
Purpose of Programming Languages
• To help PEOPLE communicate ideas
• To the computer
• To other people
• To their future selves
• Programming languages are designed to help people express ideas
precisely and concisely.
• The more “natural” the language is the better people can express ideas
• Different languages do this in different ways
Spring 2016
CSCE 314 – Programming Studio
Abstraction
Haskell, Prolog
sum[1..100]
Scheme, Java
mynum.add(5)
C
i++;
Assembly Language
iadd
Machine Language
10010010010
More Abstract
Less Abstract
Spring 2016
CSCE 314 – Programming Studio
History of programming languages
•
•
•
•
•
•
•
•
1940s: connecting wires to represent 0s and 1s
1950s: assemblers, FORTRAN, COBOL, LISP
1960s: ALGOL, BCPL(-> B -> C), SIMULA
1970s: Prolog, FP, ML, Miranda
1980s: Eiffel, C++
1990s: Haskell, Java, Python
2000s: D, C#, Spec#, F#, X10, Fortress, Scala, Ruby
2010s: Agda, Coq, …
The evolution has been and is toward higher levels of abstraction
Spring 2016
CSCE 314 – Programming Studio
Defining a Programming Language
• Syntax: Defines the set of valid programs
Usually defined with the help of grammars and other
conditions
if-statement ::= if cond-expr then stmt else stmt
| if cond-expr then stmt
cond-expr ::= . . .
stmt ::= . . .
• Semantics: Defines the meaning of programs
Defined, e.g., as the effect of individual language
constructs to the values of program variables
if cond then true-part else false-part
If cond evaluates to true, the meaning is that of true-part; if
cond evaluates to false, the meaning is that of false-part.
Spring 2016
CSCE 314 – Programming Studio
Implementing a Programming Language
• Task is to undo abstraction. From the source:
int i;
i = 2;
i = i + 7;
• to assembly (this is actually Java bytecode):
iconst_2 // Put integer 2 on stack
istore_1 // Store the top stack value at location 1
iload_1 // Put the value at location 1 on stack
bipush 7 // Put the value 7 on the stack
iadd
// Add two top stack values together
istore_1 // The sum, on top of stack, stored at location 1
• to machine language:
00101001010110
01001010100101
Spring 2016
CSCE 314 – Programming Studio
Implementing a Programming Language – How
to Undo the Abstraction
Source
program
Optimizer
I/O
Lexer
Parser
Type
checker
Code
generator
Machine code
JIT
Bytecode
Interpreter
Virtual machine
I/O
I/O
Spring 2016
Machine
CSCE 314 – Programming Studio
Compiling and Interpreting (1)
• Typically compiled languages:
• C, C++, Eiffel, FORTRAN
• Java, C# (compiled to bytecode)
• Typically interpreted languages:
• Python, Perl, Prolog, LISP
• Both compiled and interpreted:
• Haskell, ML, Scheme
Spring 2016
CSCE 314 – Programming Studio
Compiling and Interpreting (2)
• Borderline between interpretation and compilation
not clear (not that important either)
• Same goes with machine code vs. byte code.
• Examples of modern
compiling/interpreting/executing scenarios:
• C and C++ can be compiled to LLVM bytecode
• Java compiled to bytecode, bytecode interpreted
by JVM, unless it is first JITted to native code,
which can then be run on a virtual machine such
as VMWare
Spring 2016
CSCE 314 – Programming Studio
Our Goal:
To Understand Programming Languages!
• How languages are designed - how they help people express ideas
• Language constructs
• Abstraction mechanisms
• Efficiency considerations
• How languages work – how they become the code that runs
•
•
•
•
Parsing
Internal program representation
Type checking
Interpretation
• Formal verification – how we know that code will work
Spring 2016
CSCE 314 – Programming Studio
Learn ideas through examples
• Functional language: Haskell
• Object-oriented language: Java
• These languages are the means, not the goals
Spring 2016
CSCE 314 – Programming Studio
Next time
• More in-depth look at the “flowchart” of programs being processed
• Begin looking at Haskell, a functional programming language
Spring 2016