Understanding Modular Programming: Procedures, Functions, and Syntax Definitions
Modular programming breaks complex programs into simpler parts, known as "Modules". These include "Procedures" and "Functions", allowing multiple programmers to work simultaneously on a project. Modules can utilize parameters passed as "Local" variables that reset after use, while "Global" variables can be accessed by multiple modules. The calling of procedures uses a stack to manage locations. The syntax of programming languages is defined by specific rules, enabling precise communication with the computer. This includes terminal symbols, BNF for defining combinations, and syntax diagrams for visual representation.
Understanding Modular Programming: Procedures, Functions, and Syntax Definitions
E N D
Presentation Transcript
Standard prog. techniques • Complex programs can be broken down into simpler parts called “Modules” • These come in 2 types,“Procedures” and “Functions • This allows multiple programmers to work on the same project at the same time • This means you can assign more complex modules to higher level programmers
Parameters • variables passed to modules • Can be declared when calling the module or declared inside the module itself • These are known as “Local” variables • Local variables reset once the module is exited • Variables that have to be used by multiple modules are called “Global” variables
Calling procedures • When a procedure is called, the computer has to save the location of the current module so that it can return once finished • This is ok for simple programs when only 1 procedure is called at a time but when multiple procedures need to be called, the computer has to store the locations in order • This can be done through the use of a stack (first in, last out)
Defining syntax • Languages do not evolve but are invented • The language must stick to a set of rules so that the translator can run correctly • Each set of rules are language specific • “for i = 0 to 5” in VB • For(i=0;i<=5;i++){ in AS2
Terminal symbols • These are the base characters (e.g. A, B, C, 1, 2, 3, etc) • ABC is a combination of letters – can be described as “Letter, letter, letter” • A is not a combination as it is a base character
BNF • In BNF, you can define combinations using this syntax • ::= “Is defined as” • | “Or” • E.g. <WORD>::=<LETTER><LETTER><LETTER> • This allows words exactly 3 characters large • To allow for unlimited characters, you can nest the definition • E.G <WORD>::=<LETTER><LETTER>|<WORD><LETTER>
Syntax Diagrams • This is a more visual method for defining syntax • Combinations are shown in flow graph format • E.G