Syntax – Programming Series (3 of 3)

Syntax is structure of the programming language. It can be thought of as the verbs, nouns and parts of speech that make up English, or a foreign language. Syntax can typically fall under 3 different categories: High level, low level, and graphical.

High level is what is most common today. This includes languages such as C, Visual Basic, PHP and others. These languages use human-readable elements such as if, then, else, while and return to control the flow of a program. Many of these languages share enough common elements that a programmer familiar with one language can often look at code written in a different language an often have an understanding of what it accomplishes. However, each of these languages is unique and many of them are designed around a particular task or programming concept. A thorough understanding of this underlying concept can help a programmer to make a decision on which language to use to accomplish a particular task.

A graphical language is a high level language that is often represented in a flowchart form to facilitate human readability. Flowcharts are mainly made up of decision branches, and function blocks, not unlike ones that are used to describe a process in a user manual. These languages are typically programmed using drag and drop. Grab the block you need and drop it in the appropriate place on the screen. Each block often has a few parameters associated with it. For example a decision block will have a two input values and a comparison operator, not unlike an if statement in a text based language. From this block you can then branch to a yes or no function block. Function blocks, like decision blocks, also have inputs. A block that performs and addition function, for example, would have two inputs for the values being added, and one output for the result. These languages often become very complex to follow because it is often difficult to place comments within the flowchart structure to help another programmer understand exactly what is happening, unlike comments in a text based program which can be placed nearly anywhere. Additionally, as the program becomes more complex, the flow of the program can become very difficult to follow as it will quickly begin to cover several pages, and connecting blocks between these pages can often be a challenge depending on exact language used.

Another example of a graphical language is ladder logic. It is typically used in industrial control systems, and is based directly on electrical schematics that look a lot like rungs of a ladder. This design was intentional, as an electrician familiar with common electrical symbols could very easily transition to programming in a ladder language, as the symbols and functions of the symbols was essentially the same. Over time, the language has evolved to add instructions and symbols that do not have an electrical counterpart. Ladder based languages also have the distinction of running continuously, unlike the text languages also discussed in this section. Again, this design is intentional as it is modeled after electrical schematics and components, which behave like a continuously running program, as long as the machine is turned on.

Low level languages are ultimately what is run on a processor, and the other two types of languages discussed here are ultimately turned into a low level language before they are executed. Low level languages often use mnemonics that help to make the language readable to programmers. A few lines from a typical low level language might read as follows:

LD A, 10
INC A
JP A,Z

In the above example LD, INC and JP are all opcodes, and are actual instructions that the processor carries out. The values following the opcodes are parameters for each code. In this case A is a register, 10 is a constant and Z is a label to jump to. Each of these opcodes is turned into a binary value that is the actual sequence of bits that the processor must see to carry out the command entered. Even though this has been made easier to read through the use of mnemonics, at first glance it is not entirely clear that this code loads the value 10 into register A, increments the value in A by 1 and then jumps to label Z if A is not zero. Programming in an assembly language requires a good understanding of the actual architecture of the processor, how memory is laid out, what functions it can perform and how to combine the rather primitive functions provided into more common functions such as if-then-else statements.