CS 2130 - PowerPoint PPT Presentation

1 / 23
About This Presentation
Title:

CS 2130

Description:

Languages & Translation. Natural Languages. English. French. Russian. Japanese. Esperanto ... Add value on right side to variable on left side ... – PowerPoint PPT presentation

Number of Views:46
Avg rating:3.0/5.0
Slides: 24
Provided by: ble87
Category:

less

Transcript and Presenter's Notes

Title: CS 2130


1
CS 2130
  • Presentation 02
  • More Overview History
  • Some C Stuff

2
Tests
  • Test 1 Thursday, June 5, 2003
  • Test 2 Tuesday, July 1, 2003
  • Final Exam TBA
  • Note The final exam schedule published at the
    beginning of the semester is tentative.
  • Do not make plans around this tentative
    schedule!!!

3
Languages Translation
  • Natural Languages
  • English
  • French
  • Russian
  • Japanese
  • Esperanto
  • Very complex rules of grammar
  • Often ambiguous
  • Usually tied to speech
  • Constantly evolving
  • Often very context sensitive
  • Computer Languages
  • Assembler
  • Fortran, Cobol, Basic
  • C, Ada, Forth
  • Lisp, Scheme, SML
  • Prolog
  • Smalltalk, C, Java
  • Grammars more structured than natural languages
  • Precise?
  • Not often spoken
  • Fixed by version/standard
  • Context free?

4
Languages Translation
  • Converting one language into another
  • We will deal with translation of computer
    languages
  • Why do we need translation?
  • Efficiency
  • Abstraction (Want to write in HLL)

5
A Little History
  • Beginnings (30's and 40's)
  • Theoretical Foundations of Computer Science
  • Turing, Godel, Church, Markov, Post, Kleene
  • Binary logic/Idea of algorithms
  • First electronic computers in 40's
  • Programming by wiring then machine language
  • Development of Programming (50's)
  • Symbolic names
  • Assemblers
  • High Level Languages (60's)
  • High Level Languages (e.g. Fortran/Cobol/Lisp)
  • Data structures/Parameters
  • Transportability?/Program as assembly of parts

C70600000002
MOV X,2
X 2
6
A Little More History
  • Program Size Complexity Increasing (70's)
  • C and Pascal
  • Recursion and Dynamic Memory
  • Interactivity/Timesharing (80's)
  • Software Engineering
  • Object Oriented Approach Smalltalk C
  • Network Prominence (90's)
  • Internet/www
  • Separate compilation
  • Java
  • Next???

7
Translation by any other name...
  • Compiler
  • Translates program written in "source" language
    to "target" language
  • Interpreter
  • Translate and immediately execute
  • Assembler
  • Translate into machine language for particular
    machine
  • Macro Processor
  • Textual substitutions

8
Compilers
  • Fortran
  • .for ? .obj ? .exe
  • C
  • .c ? .o ? a.out
  • Java
  • .java ? .class
  • Compilation often used for speed and efficiency
    of executable code

9
Interpreters
  • Emulators
  • Basic
  • Beginner's All-purpose Symbolic Instruction Code
  • Lisp
  • Scheme
  • Java Virtual Machine
  • Interpreters often used for educational/rapid
    prototyping and portability in the case of Java

10
Assemblers
  • Typically processor/machine specific
  • Some compilers produce assembly code
  • Very close tie to hardware
  • Symbolic version of machine language
  • Still used for speed/size in performance critical
    apps
  • Needlepoint for nerds?

11
Macro Processors
  • C Preprocessor
  • Performs many useful tasks before "actual"
    compilation begins
  • Macro substitutions
  • C
  • Initially a preprocessor translated C program
    into C program
  • m4
  • UNIX macro processor

12
Other Items?
  • Linkers
  • Loaders
  • Editors
  • Debuggers
  • Profilers
  • Project Managers
  • Instant Messengers
  • Quake
  • Jolt/etc.

13
C Programming
  • 5 Weeks
  • Not a C Programming course
  • Focus on using for translation
  • C as translation target
  • Course designed to be taken at same time as ECE
    2030

14
C Review
  • BCPL (Typeless) - 1967 - Operating Systems
  • B - Ken Thompson - First version of Unix
  • C - 1972 - Dennis Ritchie - Implemented on PDP-11
  • Unix rewritten in C in 1974
  • Publication of "The C Programming Language" by
    Brian Kernighan and Dennis Ritchie
  • ...
  • ANSI C (1989)
  • Major updates to C standard in 1994 and 1999
  • We will use C89 in CS 2130 (GNU C compiler)

15
C Stuff
  • C Programs generally consist of one or more
    functions
  • Execution starts in a function called main
  • Arrays
  • Start at 0
  • No bounds checking
  • Strings
  • There are no strings...more later!
  • Structures
  • Like objects with only public fields i.e. no
    methods)
  • Pointers
  • Variable containing an address or location in
    memory

16
More C Stuff
  • Comments / /
  • Types
  • Character
  • Integers
  • Warning Hex constants...Octal Constants
  • Long and Short
  • Signed and Unsigned
  • Floating Point
  • Sizeof
  • sizeof(int) / sizeof a type /
  • sizeof x / sizeof a data object /

17
Expressions
  • A constant or variable by itself is an expression
  • Combinations of constants and variables with
    operators are also expressions
  • Examples
  • 7 / Constant /
  • x / Variable /
  • x 7 / with operator /
  • x x 7 / with operators /
  • x x 7 / Simple statement /

18
Operators
  • Assignment Operator Evaluate expression on
    right, store result in variable on the left
  • Add value on right side to variable on left
    side
  • - Subtract value on right side from variable on
    left side
  • Multiply variable on left side by value on
    right side
  • Assignment expression itself has a value!
  • a b c 0

19
Other Operators
  • Binary Arithmetic - /
  • Unary - --
  • Bitwise ltlt gtgt
  • Relational lt lt gt gt !
  • Logical !

Pretty much the same as Java except there is no
boolean value
20
Common Pitfalls
  • / Java /
  • int foo(int x)
  • for(int i0iltMAXi)
  • ...
  • / C /
  • int foo(int x)
  • int i
  • for(i0iltMAXi)
  • ...

21
Common Pitfalls
  • int foo(int x)
  • int a
  • int b 7
  • int c
  • c 9
  • int d
  • Cannot mix code and declarations...

22
Questions?
23
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com