Mynx Semantics and Code Generation One Leads into the Other
In implementing Mynx semantic checks, and clarifying Mynx semantics in the Mynx programming language manual (MPLM), reading and writing information from the symbol table in the context object is not the only thing involved in the process.
Since Mynx has operator overloading, a valid syntax (but questionable semantics) Mynx source text, can not simply be translated into the high-level language source code. Note: Mynx will not generate direct machine code to assemble, it will compile into high-level Java/C# (and C/C++) source code. By using code synthesis (a term to distinguish from code generation phase in a compiler) will make the back-end of the compiler simpler than the front-end, which uses a new parsing algorithm + new programming language = square of complexity.
The question is that semantics gathers information (such as type) and annotates the information in the sentence for code synthesis.
For example, the simple expression statement with assignment:
The Mynx variable identifier (presumption of declared in method used within) requires type annotation, such as Int.
The check for type that is type compatibility is based on the operator '=' that is translated into the method that is overloaded in the Int class for the operator '='. The external semantic information in a MOXI XML file is read, so that the '=' is the method 'set' that takes an Int parameter. The type of the operator is determined by the type of the variable identifier which is the l-val. Operator type checking is using external semantic MOXI file information, and instead of being hard and fast wired into the programming language, is determined by operator overloading with a method.
The type compatibility is valid, and the method is 'set' to be called for the operator '=' assignment. Thus the expression statement is type valid (presuming the types are declared before use in the method) and the expression statement is translated from the expression operators to the expression methods.
Hence semantic checks for sentence, context, and type are not just to verify that a Mynx source text is valid, but to annotate information in each sentence for the code synthesis stage. A syntactically valid Mynx source text cannot be used to synthesize the high-level language source code in Java/C# without semantic checks to annotate the needed information in the classes used in the Mynx source.
Since Mynx has operator overloading, a valid syntax (but questionable semantics) Mynx source text, can not simply be translated into the high-level language source code. Note: Mynx will not generate direct machine code to assemble, it will compile into high-level Java/C# (and C/C++) source code. By using code synthesis (a term to distinguish from code generation phase in a compiler) will make the back-end of the compiler simpler than the front-end, which uses a new parsing algorithm + new programming language = square of complexity.
The question is that semantics gathers information (such as type) and annotates the information in the sentence for code synthesis.
For example, the simple expression statement with assignment:
x = y;
The Mynx variable identifier (presumption of declared in method used within) requires type annotation, such as Int.
x:type=Int = y:type=Int
The check for type that is type compatibility is based on the operator '=' that is translated into the method that is overloaded in the Int class for the operator '='. The external semantic information in a MOXI XML file is read, so that the '=' is the method 'set' that takes an Int parameter. The type of the operator is determined by the type of the variable identifier which is the l-val. Operator type checking is using external semantic MOXI file information, and instead of being hard and fast wired into the programming language, is determined by operator overloading with a method.
x:type=Int .set(Int == y:type=Int)
The type compatibility is valid, and the method is 'set' to be called for the operator '=' assignment. Thus the expression statement is type valid (presuming the types are declared before use in the method) and the expression statement is translated from the expression operators to the expression methods.
x.set(y); //-> x = y;
Hence semantic checks for sentence, context, and type are not just to verify that a Mynx source text is valid, but to annotate information in each sentence for the code synthesis stage. A syntactically valid Mynx source text cannot be used to synthesize the high-level language source code in Java/C# without semantic checks to annotate the needed information in the classes used in the Mynx source.
Labels: code generation, code synthesis, context semantic, mynx, Mynx MOXI XSchema, semantics, type semantics

