Semantic Checks - Uniqueness Context Check--the Nuances of Semantics
The uniqueness context check is of two distinct parts:
The approach to verify that all attributes, constants, variables are unique is either a two pass approach, or a one pass approach through the source code.
Uniqueness is verified by storing the identifiers and the descriptor of the declaration in a symbol table structure. At the completion, all identifiers are known to be unique in both the global and local contexts within the class or program.
The decision to use a two or one pass approach for uniqueness seems overkill in design. However, the next step is existence in context semantic checks, in which the original declaration information of type is annotated to the syntactic descriptors (which are elements of essentially an abstract syntax tree (AST), and then type checking is performed. Hence a one or two pass approach to uniqueness will impact the existence semantic check, and then the type semantic check.
Either way there is at least one pass, but both approaches have trade-offs in terms of speed and storage a.k.a. time and space.
Both approaches, the two pass, and the one pass depend on the semantic rules of context constraint of existence. Within a class or program does declaration of a method or attribute preceed use?
The two pass approach uses two passes that are:
Requires 2-passes - one for class elements, second for methods.
Requires buffer of syntax descriptors.
The single pass approach handles both the global context and local context within a single pass through the source code, done on the fly as each sentence parsed.
The second pass is essentially integrated into the first, so instead of ignoring the body of a method, it is handled. If a method uses an attribute or other method that is declared later on, the use is stored in a forward attribute or forward method map. Later the maps must be processed with the attribute and method declarations.
Requires a map for forward declarations for attributes and methods. Requires post-pass processing of the forward declarations.
The declaration before use semantics allow one pass compilation, but make the language more rigid like Pascal which had a very strict order of declaration.
C-style of using separate headers dot-h, then everything is known in one central source when compiling the dot-c, but duplicates the declaration, and separates it from the definition.
Originally, I considered Mynx to have strict sections like the visiblity sections of a C++ class, but opted not to use that approach as it is too rigid.
Language design is not just about features and functionality, but also a strong bearing on compiler design and efficiency. A compiler for a given language is a trade-off in efficiency to features of the language.
I am opting towards some declaration before use semantics in some features such as attributes and methods (including the constructor) but not other elements. I am aiming for a single pass compiler to avoid the buffering and additional processing, as well as the time involved.
The uniqueness context check of semantics is followed by existence -- a check of existence in an expression or statement. Hence uniqueness checks are directly related to existence, the declaration before use semantics. The uniqueness checks ensure that identifiers are unique, and the existence checks that identifiers exist -- and that type information associated with the identifer is annotated to the syntax element.
The uniqueness semantic context check is the first context semantic check on the class/program and any constructors/methods/destructor written. How the uniqueness checks are implemented later will impact the further semantic check functionality.
The context semantic checks and actions are:
It should be noted that each is not a discrete check or action, all three will occur (once fully implemented) in the single pass on the fly as sentences are parsed.
- global - context of class or program.
- local - contex of constructor/destructor/method.
The approach to verify that all attributes, constants, variables are unique is either a two pass approach, or a one pass approach through the source code.
Uniqueness is verified by storing the identifiers and the descriptor of the declaration in a symbol table structure. At the completion, all identifiers are known to be unique in both the global and local contexts within the class or program.
Significance of Uniqueness - Existence and Type Semantic Checks
The decision to use a two or one pass approach for uniqueness seems overkill in design. However, the next step is existence in context semantic checks, in which the original declaration information of type is annotated to the syntactic descriptors (which are elements of essentially an abstract syntax tree (AST), and then type checking is performed. Hence a one or two pass approach to uniqueness will impact the existence semantic check, and then the type semantic check.
Either way there is at least one pass, but both approaches have trade-offs in terms of speed and storage a.k.a. time and space.
Both approaches, the two pass, and the one pass depend on the semantic rules of context constraint of existence. Within a class or program does declaration of a method or attribute preceed use?
Two Pass Approach to Context Uniqueness Check
The two pass approach uses two passes that are:
- first pass is for the global context, done on the fly as each sentence is parsed. The body of a method/constructor/destructor is ignored.
- second pass is for the local context, done afterward on a buffer of the parsed sentences -- the descriptors -- handling the body of the methods.
Requires 2-passes - one for class elements, second for methods.
Requires buffer of syntax descriptors.
One Pass Approach
The single pass approach handles both the global context and local context within a single pass through the source code, done on the fly as each sentence parsed.
The second pass is essentially integrated into the first, so instead of ignoring the body of a method, it is handled. If a method uses an attribute or other method that is declared later on, the use is stored in a forward attribute or forward method map. Later the maps must be processed with the attribute and method declarations.
Requires a map for forward declarations for attributes and methods. Requires post-pass processing of the forward declarations.
Language Design and Impact on the Compiler
The declaration before use semantics allow one pass compilation, but make the language more rigid like Pascal which had a very strict order of declaration.
C-style of using separate headers dot-h, then everything is known in one central source when compiling the dot-c, but duplicates the declaration, and separates it from the definition.
Originally, I considered Mynx to have strict sections like the visiblity sections of a C++ class, but opted not to use that approach as it is too rigid.
Language design is not just about features and functionality, but also a strong bearing on compiler design and efficiency. A compiler for a given language is a trade-off in efficiency to features of the language.
I am opting towards some declaration before use semantics in some features such as attributes and methods (including the constructor) but not other elements. I am aiming for a single pass compiler to avoid the buffering and additional processing, as well as the time involved.
Uniqueness Semantic Check as First Step in Context Semantic Check
The uniqueness context check of semantics is followed by existence -- a check of existence in an expression or statement. Hence uniqueness checks are directly related to existence, the declaration before use semantics. The uniqueness checks ensure that identifiers are unique, and the existence checks that identifiers exist -- and that type information associated with the identifer is annotated to the syntax element.
The uniqueness semantic context check is the first context semantic check on the class/program and any constructors/methods/destructor written. How the uniqueness checks are implemented later will impact the further semantic check functionality.
The context semantic checks and actions are:
- Uniqueness in Context (check)
- Existence in Context (check)
- Annotation in Context (action)
It should be noted that each is not a discrete check or action, all three will occur (once fully implemented) in the single pass on the fly as sentences are parsed.
Labels: annotation semantics, context semantic, existence semantics, semantic analysis, semantic check, uniqueness semantics

<< Home