One-pass compiler: Difference between revisions

Content deleted Content added
Advantages: Added Content
Tags: Mobile edit Mobile web edit
m Procedures and functions: Fixed capitalisation
Line 95:
 
===Procedures and functions===
Declaration before use is likewise an easy requirement to meet for procedures and functions, and this applies also to the nesting of procedures within procedures. As with AlgolALGOL, Pascal, plPL/iI and many others, MatlabMATLAB and (since 1995) fortranFortran allow a function (or procedure) to contain the definition of another function (or procedure), visible only within the containing function, but, these systems require that they be defined ''after'' the end of the containing procedure!.
 
But when recursion is allowed, a problem arises. Two procedures, each invoking the other, cannot both be declared before usage. One must be first in the source file. This need not matter if, as on the encounter with an unknown variable, sufficient can be deduced from the encounter that the compiler could generate suitable code for the invocation of the unknown procedure, with of course the "fixup" apparatus in place to come back and fill in the correct address for the destination when the procedure's definition is encountered. This would be the case for a procedure with no parameters, for example. The returned result from a function invocation may be of a type discernable from the invocation, but this may not always be correct: a function could return a floating-point result but have its value assigned to an integer.