Mynx Sentential Semantic Check - I Check, Therefore Semantics - Alone
In implementing the semantic checks for Mynx particularly the class attribute, I’ve had to re-do and re-design (refactor) the original code. Code is rarely effective the first time, like writing prose, so requires re-thinking and re-writing.
The effective solution to implement semantic checks is guided by some heuristics or rules of thumb of:
The third heuristic is more object-oriented approach, each sentence does its own semantic check; the original implementation passed a sentence via the visitor design pattern to a class with semantic checks, but required many query and access methods to be annotated to the sentence. The difficulty was that information hiding and encapsulation created lots of data movement. It is more effective for the semantic check to be internal to the sentence, and pass a semantic context object as the locus of information.
In the original semantic checks, I found my original test cases (23-overall semantic checks, both for failure and success so 46-semantic checks) were causing one semantic error to squelch another, or created a spurious error - one error causing another by the code tangling within the semantic method. The state of a method can cause anomalous semantic errors.
The simplification into individual methods that are mutual exclusive and single purpose has avoided the problem of spurious and supression of semantic errors. The order of execution and other methods called during the semantic checks does not impact each semantic check or have any other interaction. Later as I implement higher-level semantic checks it is vital there is no side-effects.
The effective solution to implement semantic checks is guided by some heuristics or rules of thumb of:
- Each semantic check is responsible to determine if it should check (a generic class attribute semantic check would not execute if the class attribute is an integer constant semantic).
- Each semantic check only checks one thing, so one error message reported.
- Each semantic check is a method in the class, called from a central semantic check method after the sentence is parsed.
The third heuristic is more object-oriented approach, each sentence does its own semantic check; the original implementation passed a sentence via the visitor design pattern to a class with semantic checks, but required many query and access methods to be annotated to the sentence. The difficulty was that information hiding and encapsulation created lots of data movement. It is more effective for the semantic check to be internal to the sentence, and pass a semantic context object as the locus of information.
In the original semantic checks, I found my original test cases (23-overall semantic checks, both for failure and success so 46-semantic checks) were causing one semantic error to squelch another, or created a spurious error - one error causing another by the code tangling within the semantic method. The state of a method can cause anomalous semantic errors.
The simplification into individual methods that are mutual exclusive and single purpose has avoided the problem of spurious and supression of semantic errors. The order of execution and other methods called during the semantic checks does not impact each semantic check or have any other interaction. Later as I implement higher-level semantic checks it is vital there is no side-effects.
Labels: implementation semantic, mynx, semantic check, semantic rule


<< Home