Mind map
Programming
Map content
Programming
Tools: high level languages, machine code, variables, constants, data types
- High level languages A high level language is a programming language that allows code to be written. It is similar to a natural human language, such as Welsh or English. Some programmers prefer to use high level programming languages as they are easier to understand, learn and program. Their commands are similar to natural languages like English or Welsh and identifiers can be long and meaningful. High level programming languages also allow the use of powerful commands that perform quite complex tasks such as MsgBox in Visual Basic or the SORT clause in COBOL. High level languages are used when the execution speed is not critical, e.g. in common productivity applications, such as a word processor. Examples of common high level programming languages include: • Basic • Java • Pascal • COBOL • C# • C++
- Machine code Machine code is the opposite of a high level language in that it does not resemble any natural language and is made up entirely of bit patterns (instructions or data) that can be executed directly by the CPU. Examples of machine code instructions are opcodes and operands, discussed on pages 31–2. High level languages have to be converted into machine code before they can be executed by the CPU. Although highly uncommon, some programmers may wish to program directly in machine code. This is primarily done when programming device drivers or where a fast execution speed are critical.
- Variables In computer programming, a variable may be required to store data that can change. Variables are given identifiers (names) that should reflect the data being stored in them. An example of a variable is txt_FirstName. This variable has a self-documenting identifier, which implies the type of data being stored in it is text containing a person’s first name.
- Constants Constants are used in computer programming to store data that does not change. Constants are also given self-documenting identifiers that should reflect the data being stored in them. An example of a constant would be Pi = 3.14, as this is a self-documenting identifier that does not change.
- Variables such as: local, global, static, dynamic
- Local and global variables A local variable is a variable that is defined within a sub procedure and as such is only accessible from within that same sub procedure. This is known as its scope. A global variable is a variable that has a larger scope as it is defined globally and is therefore accessible from anywhere within a program. The advantage of defining a local variable over a global variable is that it is easier to track the changes to a variable and the reason for the changes when it is only used within a sub procedure. An advantage of defining a global variable over a local variable is that sometimes it can be the most efficient way of ensuring that an important piece of data is accessible to all sub procedures, e.g. the details of the user currently logged into a program.
- Static and dynamic variables Each time a program is run, static variables are stored in a location in memory and have a lifespan that lasts the entire time that program is running. For example, if you assign the number 2.14 to a static variable (and do not change it), the static variable will still contain 2.14 the next time you run the sub procedure and until the whole program stops running. Each time a dynamic variable is defined, it is assigned a new location in memory and has a lifespan that ends when the sub procedure in which it was defined ends. For example, if within a sub procedure you assign the number 2.14 to a dynamic variable (and do not change it) and the sub procedure ends, the next time you run that sub procedure the dynamic variable will no longer contain any value.
Why translators, compilers, interpreters, and assemblers are needed
- Assemblers An assembler is a program which coverts the low level assembly programming language into machine code. The assembler does this by converting the one word assembly instructions into an opcode, e.g. converting AND to 0010. It also allocates memory to variables, often resulting in an operand.
- Interpreters Before high level programming languages can be run, code is converted by an interpreter, one line at a time, into machine code, which is then executed by the CPU
- Compilers A compiler is used when high level programming languages are converted into machine code, ready to be executed by the CPU. There are four main stages of compilation
- Lexical analysis • Comments and unneeded spaces are removed. • Keywords, constants and identifiers are replaced by 'tokens'. • A symbol table is created which holds the addresses of variables, labels and subroutines
- Syntax analysis • Tokens are checked to see if they match the spelling and grammar expected, using standard language definitions. This is done by parsing each token to determine if it uses the correct syntax for the programming language. • If syntax errors are found, error messages are produced
- Semantic analysis • Variables are checked to ensure that they have been properly declared and used. • Variables are checked to ensure that they are of the correct data type, e.g. real values are not being assigned to integers. • Operations are checked to ensure that they are legal for the type of variable being used, e.g. you would not try to store the result of a division operation as an integer
- Code generation • Machine code is generated. • Code optimisation may be employed to make it more efficient/faster/less resource intense.
- Translators A translator changes (translates) a program written in one language into an equivalent program written in a different language. For example, a program written using the PASCAL programming language may be translated into a program written in the C programming languages by a translator
Information
- Description
- Mind Map on Programming, created by bob thebuilder on 26/09/2016.
- Created by
- bob thebuilder
- Views
- 0
- Rating