1.18k likes | 1.32k Views
http:// proglit.com /. a first language. SA. BY. pigeon. (a “fake” language). source code. (code as text). comment. this is code # this is a comment. value. (a piece of data). d ata types. number string boolean. number. 3 -724 8.93 -0.88881. string. (a piece of text)
E N D
a first language
SA BY
pigeon (a “fake” language)
source code (code as text)
comment this is code # this is a comment
value (a piece of data)
data types number string boolean
number 3 -724 8.93 -0.88881
string (a piece of text) “R. Nixon” “T” “Elementary, my dear Watson.” “%”
boolean (a true/false value) true false
null (a value representing nothing) null
literal (a value written in code) null “The owls are not what they seem.” 78 false
escape sequence “\”Hi,\” she said.” “Hello,\nworld.” “c:\\bla\\bla\\bla”
operation (takes input values and returns an output value)
operator operand (specifier of the operation to perform) (an input value)
(3+5) (+35)
variable (a memory location holding a value)
identifier (a name) NewYork foo asdf43qwerty78 illegal: New York f^$o*o 43asdf
case sensitive (letter case matters) NewYork newyork newYORK nEwYoRk NEWYORK
reserved word (an identifier reserved by the language) add, sub, mul, div, if, while…
assignment asdogtrue asnewt -87.2 asbirdnull ascat“rubber baby buggy bumper” (gives a variable a value)
asbar19 asfoobar asbar3 asfizz(addfoo11)
expression (evaluates into a value) null (addfoo2) “hello” bar
statement (the units of syntax that make up the code) asfoo53 (addfoo11)
computer (a cpu, memory, and i/o)
cpu (executes instructions)
memory (holds bits)
i/o (input/output)
print (display a value on the screen) (print“wakka wakka”) asbar19 (printbar)
prompt (return typed input from user) asfoo (prompt) (printfoo)
Hello, world! (print“Hello, world!”)
eq (eq“moo” “moo” “moo”) # true (eq-35 -35) # true (eq6 2) # false (equality test)
not (reverse the truth value) (nottrue) # false (notfalse) # true
conditional execution • (maybe do something, or maybe skip over it)
if (“run these statements if…”) ifcondition body
if (eqx3) (print“cat”) (print“dog”) (print“bird”) x equals 3 cat dog bird x doesn’t equal 3 bird
mutual exclusion • (do one thing or do the other, but NOT both)
if (eqx3) (print“hi”) if (not (eqx3)) (print“bye”) x equals 3 hi x doesn’t equal 3 bye
else ifcondition body1 else body2 (“…elsewise, run these other statements”)
if (eqx3) (print“hi”) else (print“bye”) x equals 3 hi x doesn’t equal 3 bye
if (eqx3) (print“hi”) else if (eqx5) (print“bye”) x equals 3 hi x equals 5 bye x doesn’t equal 3 or 5
elif ifcondition1 body1 elif condition2 body2 (a convenience for else if)
if (eqx3) (print“hi”) elif (eqx5) (print“bye”) x equals 3 hi x equals 5 bye x doesn’t equal 3 or 5
if (eqx3) (print“hi”) elif (eqx5) (print“bye”) elif (eqx-7) (print“moo”) elif (eqx14) (print“woof”) x equals 3 hi x equals 5 bye x equals -7 moo x equals 14 woof x doesn’t equal any of these values
if (eqx3) (print“hi”) elif (eqx5) (print“bye”) elif (eqx-7) (print“moo”) else (print“meow”) x equals 3 hi x equals 5 bye x equals -7 moo x doesn’t equal any of these values meow