Programming Languages CSE 340 Principles of Programming Languages

  • Slides: 15
Download presentation
Programming Languages CSE 340 – Principles of Programming Languages Fall 2016 Adam Doupé Arizona

Programming Languages CSE 340 – Principles of Programming Languages Fall 2016 Adam Doupé Arizona State University http: //adamdoupe. com

What is a programming language? • A structured way to define computation • Is

What is a programming language? • A structured way to define computation • Is this the only definition/purpose? – Communicate an algorithm – Describe a process – Communicate a system to another person – Communicate instructions to a machine Adam Doupé, Principles of Programming Languages 2

How does the hardware understand your instructions? NO! Adam Doupé, Principles of Programming Languages

How does the hardware understand your instructions? NO! Adam Doupé, Principles of Programming Languages 3

How does the computer understand your instructions? • The CPU understands assembly language Adam

How does the computer understand your instructions? • The CPU understands assembly language Adam Doupé, Principles of Programming Languages 4

How does the computer understand your instructions? • Programs translate your intentions to the

How does the computer understand your instructions? • Programs translate your intentions to the assembly language that the CPU understands • Compilers – Translate programming language to executable binary • Interpreters – Understand a programming language and perform the actual computation • Transpiler – Translate a programming language to another programming language Adam Doupé, Principles of Programming Languages 5

How do they work? • In this class, we will study how these programs

How do they work? • In this class, we will study how these programs are able to translate a high-level programming language into something the computer can understand • Theory – Enables us to define what we can and cannot do when defining a programming language • Practice – Empowers us to develop domain-specific languages, task-specific compilers, static analysis, parsing … Adam Doupé, Principles of Programming Languages 6

BF ++++[>++++[>++>+++>+<<<<]>+>+>->>+[<]<-]>>. >--. +++++++. >>. <-. <. +++. -------. >>+. >++. Output: Hello World!

BF ++++[>++++[>++>+++>+<<<<]>+>+>->>+[<]<-]>>. >--. +++++++. >>. <-. <. +++. -------. >>+. >++. Output: Hello World! http: //www. iwriteiam. nl/Ha_bf_online. html Adam Doupé, Principles of Programming Languages 7

Adam Doupé, Principles of Programming Languages 8

Adam Doupé, Principles of Programming Languages 8

Whitespace ____n___t___ntt____tn___tt__t_tntt____t_n___tt__ntt____ttn___tt __ntt____t__n___ttttntt____t_tn___t_tt__ntt____tt_n___t_____ntt____tt tn___tttntt____t___n___ttttntt____tn___ttt__t_ntt____t_t_n___tt__ntt____t_ttn___tt__ntt____tt__n___t_____ntt____tt_tn___ttttnt t____ttt_n___tt_ntt____ttn___t_____ntt____n___ttt__ttntt____t_ __tn___ttt____ntt____t_n___tt____tntt____ttn___ttntt____t_t__ n___tt__t_tntt____t_t_tn___ttt__ttntt____t_tt_n___t____tntt____t_tttn____ ntt_____nn_t_ttt_ttt__tt_t_ttt_t___tt__t_tnn_t_ttt__t_t_ ttt_tt_tt___tt_t_tt_ttt__t_tnnn___tt____t_tt__t__nt_ __ntnn___ttt_ttt__tt_t_ttt_t___tt__t_tn_n_ttt_n_nt__ttt_tt t__tt_t_ttt_t___tt__t_ttt_tt__t_t_ttt__t__ntn_____tnt___ n_n_ttt_ttt__tt_t_ttt_t___tt__t_tnn___ttt_ttt__tt_t_tt t_t___tt__t_ttt_tt__t_t_ttt__t__n_nnntnn___ttt__tt__t _t_tt____t_tt__n_n_tnt_ttt_n____t_t_nt__ttt__tt__t_t_tt___t_ttt_tt__t_t_ttt__t__n_nn___tnt___n_n_ttt__tt__t_

Whitespace ____n___t___ntt____tn___tt__t_tntt____t_n___tt__ntt____ttn___tt __ntt____t__n___ttttntt____t_tn___t_tt__ntt____tt_n___t_____ntt____tt tn___tttntt____t___n___ttttntt____tn___ttt__t_ntt____t_t_n___tt__ntt____t_ttn___tt__ntt____tt__n___t_____ntt____tt_tn___ttttnt t____ttt_n___tt_ntt____ttn___t_____ntt____n___ttt__ttntt____t_ __tn___ttt____ntt____t_n___tt____tntt____ttn___ttntt____t_t__ n___tt__t_tntt____t_t_tn___ttt__ttntt____t_tt_n___t____tntt____t_tttn____ ntt_____nn_t_ttt_ttt__tt_t_ttt_t___tt__t_tnn_t_ttt__t_t_ ttt_tt_tt___tt_t_tt_ttt__t_tnnn___tt____t_tt__t__nt_ __ntnn___ttt_ttt__tt_t_ttt_t___tt__t_tn_n_ttt_n_nt__ttt_tt t__tt_t_ttt_t___tt__t_ttt_tt__t_t_ttt__t__ntn_____tnt___ n_n_ttt_ttt__tt_t_ttt_t___tt__t_tnn___ttt_ttt__tt_t_tt t_t___tt__t_ttt_tt__t_t_ttt__t__n_nnntnn___ttt__tt__t _t_tt____t_tt__n_n_tnt_ttt_n____t_t_nt__ttt__tt__t_t_tt___t_ttt_tt__t_t_ttt__t__n_nn___tnt___n_n_ttt__tt__t_ t_tt____t_tt__nn___ttt__tt__t_t_tt____t_tt___t_ttt_tt__t_t_tt t__t__n_nn___tnt_______ntt_ntnn___ttt__t_t_ttt_tt___tt _t_tt_ttt__t_tn___t_t_n___tt_tn__tn__ntn Output: Hello, world of spaces! https: //github. com/hostilefork/whitespacers/ Adam Doupé, Principles of Programming Languages 9

Python print "Hello World!" Adam Doupé, Principles of Programming Languages 10

Python print "Hello World!" Adam Doupé, Principles of Programming Languages 10

Haskell module Main where main = put. Str. Ln "Hello, World!" Adam Doupé, Principles

Haskell module Main where main = put. Str. Ln "Hello, World!" Adam Doupé, Principles of Programming Languages 11

x 86 Assembly global _start section. text_start: mov rax, 1 mov rdi, 1 mov

x 86 Assembly global _start section. text_start: mov rax, 1 mov rdi, 1 mov rsi, message mov rdx, 13 syscall mov eax, 60 xor rdi, rdi syscall message: db "Hello, World", 10 Adam Doupé, Principles of Programming Languages 12

Which is actually a PL? • All of them? • None of them? •

Which is actually a PL? • All of them? • None of them? • Some of them? Adam Doupé, Principles of Programming Languages 13

Overview of Program Interpretation Bytes Lexer Tokens Parser Parse Tree Valid Parse Semantic Tree

Overview of Program Interpretation Bytes Lexer Tokens Parser Parse Tree Valid Parse Semantic Tree Analysis Source Valid Parse Tree Backend Computation x 86 binary Adam Doupé, Principles of Programming Languages 14

What makes a program valid? • Syntax – What does it mean to look

What makes a program valid? • Syntax – What does it mean to look like a valid program? • Semantics – What does it mean for a program to be valid? • Correctness? – Is the program the correct one for the job? Adam Doupé, Principles of Programming Languages 15