15
Code Grammar

Code Grammar. Syntax A set of rules that defines the combination of symbols and expressions

Embed Size (px)

Citation preview

Page 1: Code Grammar. Syntax A set of rules that defines the combination of symbols and expressions

Code Grammar

Page 2: Code Grammar. Syntax A set of rules that defines the combination of symbols and expressions

Syntax

• A set of rules that defines the combination of symbols and expressions

Page 3: Code Grammar. Syntax A set of rules that defines the combination of symbols and expressions

Curly Braces

• Always work in balanced pairs (an open and closed pair)

• Used to structure code blocks

Page 4: Code Grammar. Syntax A set of rules that defines the combination of symbols and expressions

Naming Convention

• Legal names can only contain letters, underscores, numbers, and the dollar sign

• The initial character must be a letter, underscore, or dollar sign - not a number

• The names you define are called identifiers

Legal identifiers

Illegal identifiers. Why?

Page 5: Code Grammar. Syntax A set of rules that defines the combination of symbols and expressions

Vocabulary

Page 6: Code Grammar. Syntax A set of rules that defines the combination of symbols and expressions

Comments

• Ignored by the computer• Helps us write notes• Helps remember what

that part of the program does

Page 7: Code Grammar. Syntax A set of rules that defines the combination of symbols and expressions

Functions

• Allow us to execute certain actions like draw shapes, set colors

• Usually lowercase followed by parentheses

Page 8: Code Grammar. Syntax A set of rules that defines the combination of symbols and expressions

Expressions, Statements

• An expression o like a phraseo Often a combination of

operators• A statement

o A set of expressionso Like a sentenceo Ends with the statement

terminator

Page 9: Code Grammar. Syntax A set of rules that defines the combination of symbols and expressions

Data types

• Processing can store and manipulate different kinds of data including numbers, letters, words, colors, etc

• The computer stores each in a different way so it needs to know which kind of data it is in order to manage it

• intinteger data

• floatfloating-point numbers that have a decimal point

• StringWords and sentences

• booleanTrue or false

Page 10: Code Grammar. Syntax A set of rules that defines the combination of symbols and expressions

Variables

• A container for storing data

• Allows a data element to be reused

• Every variable had a name, value and data type

• A variable must be declared before it is used

Page 11: Code Grammar. Syntax A set of rules that defines the combination of symbols and expressions

Operators

• Symbols used to write mathematical expressions

• + (Addition)• - (Subtraction)• * (Multiplication)• / (Division)

Page 12: Code Grammar. Syntax A set of rules that defines the combination of symbols and expressions

Relational Operators

• > (greater than)• >= (greater than and

equal to)• < (less than)• <= (less than and equal

to)• == (equal to)• != (not equal to)

Page 13: Code Grammar. Syntax A set of rules that defines the combination of symbols and expressions
Page 14: Code Grammar. Syntax A set of rules that defines the combination of symbols and expressions

References Processing: A programming Handbook for Visual

Designers - Casey Reas, Ben Fry

Processing: Creative Coding and Computational Art - Ira Greenberg

Page 15: Code Grammar. Syntax A set of rules that defines the combination of symbols and expressions

 

Op

Open CodeLabs Every Wednesday, 6:00pm - 8:00pm

10th Floor Lab, Building L