music |
OSdata.com |
building blocks of a program
summary
An informal discussion of the basic buidling blocks of a program.
free computer programming text book projecttable of contents
|
music |
OSdata.com |
An informal discussion of the basic buidling blocks of a program.
free computer programming text book projecttable of contents
|
The terminology and details for constructing a program vary by language, but tend to follow a few common principles. The following presentation is very informal. All of these items will be discussed in more detail later.
Programs are created from a series of characters (letters, digits, punctuation, and other characters) from the source character set.
Characters are grouped into tokens. Each token, which can be one or more characters, has a distinct meaning in the language. Comments and white space are generally not considered to be tokens. Depending on how a language defines tokens, they can include operators, literals, keywords (or reserved words), and identifiers.
C has five classes of tokens: operators, separators, identifiers, reserved words, and constants.
A token is distinguished by the fact that if you try to break it up into smaller elements that it will lose or change its meaning. To use a simple example, the characters 3.5 collectively have the clear meaning of three and a half, but individually mean three, period, and five. A token is indivisible.
Literals are symbols used to indicate a specific value. Anytime you encounter a raw number, such as 2 or 573.9901, you are seeing an example of a numeric literal. There are other kinds of literals beyond just numbers.
Operators are symbols (usually one or two characters) that indicate an operation (such as the plus sign [+] for addition).
Separators are symbols that are used to separate portions of your source code. Some languages dont use this concept. Some languages consider whitespace to be a separator, while other languages dont (even if whitespace is used to separate tokens).
Key words or reserved words are the commands (and related terminology) of a programming language (such as the ubiquitious IF command). Reserved words can not be used for any other purpose. Some languages (such as PL/I) allow key words to be reassigned to other purposes (which creates massive confusion and is a horribly bad programming practice). In most languages, there is no distinction between the terms keywords and reserved words.
Identifiers are names. This includes the names of programs, modules, procedures, functions, variables, constants, etc. In some languages this may include reserved words or key words. Note that in the c programming language, constants are not considered an identifier.
Tokens can be grouped together into statements. Some languages have subgroups of statements called expessions.
In some languages (such as C) there is a special character (or characters) that terminates (or marks the end of) a statment. In some languages (such as Pascal) there is a special character (or characters) that seperates statements. This is a subtle but important difference. Some languages (such as FORTRAN) are line oriented, with one statement to a line (with a continuation character to allow for multiple line statements).
Statements may (in most modern languages) be grouped into blocks of code.
Most modern programming languages have a header and a body, although few call them by those exact names.
Generally declarations go into the header and statements and blocks of code go into the body.
Coding example: I am making heavily documented and explained open source code for a method to play music for free almost any song, no subscription fees, no download costs, no advertisements, all completely legal. This is done by building a front-end to YouTube (which checks the copyright permissions for you).
View music player in action: www.musicinpublic.com/.
Create your own copy from the original source code/ (presented for learning programming).
return to table of contents
free downloadable college text book
Because I no longer have the computer and software to make PDFs, the book is available as an HTML file, which you can convert into a PDF.
previous page | next page |
Tweets by @osdata |
free computer programming text book projectBuilding a free downloadable text book on computer programming for university, college, community college, and high school classes in computer programming. If you like the idea of this project, Supporting the entire project: If you have a business or organization that can support the entire cost of this project, please contact Pr Ntr Kmt (my church) free downloadable college text book on computer programming. |
This web site handcrafted on Macintosh computers using Tom Benders Tex-Edit Plus and served using FreeBSD .
UNIX used as a generic term unless specifically used as a trademark (such as in the phrase UNIX certified). UNIX is a registered trademark in the United States and other countries, licensed exclusively through X/Open Company Ltd.
Names and logos of various OSs are trademarks of their respective owners.
Copyright © 2007, 2010 Milo
Created: September 8, 2007
Last Updated: October 3, 2010
return to table of contents
free downloadable college text book
previous page | next page |