Printer
SetLanguageAttribute
add language attribute to Printer module
ApplyLanguageAttribute
apply language attribute to remaining arguments
GetLanguageAttribute
get language attribute from Printer module
Calling Sequence
Parameters
Description
Examples
Printer:-SetLanguageAttribute(expr, ...)
Printer:-GetLanguageAttribute(str)
Printer:-ApplyLanguageAttribute(str)
-
Printer module
expr
string (str) or equation of the form (str = val)
str
string; name of language attribute
val
algebraic, string, or procedure; value of language attribute
The SetLanguageAttribute command sets and clears language attributes. Multiple arguments are processed sequentially. If an argument has the form str=val, then the language attribute str is assigned the value val. If the language attribute str already has a value, it is overwritten. If an argument has the form str, then the language attribute str is cleared.
The GetLanguageAttribute command retrieves the current value of the language attribute str.
The ApplyLanguageAttribute behaves similarly to GetLanguageAttribute: if the value of language attribute str is of type algebraic or boolean, it is returned. However, if the value of language attribute str is of type procedure, it is applied to any remaining arguments of ApplyLanguageAttribute, and the result is returned.
For more information about language attributes and their function within CodeGeneration language definitions, see Language Attributes.
Change the string delimiter character to a single quote (') and define an equivalent for the Maple print command.
with⁡CodeGeneration:
LanguageDefinitionDefine⁡SingleQuoteLanguage,extend=default,SetLanguageAttribute⁡String_Delimiter=',AddFunction⁡print,anything::anything,echo:
Translate⁡print⁡hello,language=SingleQuoteLanguage
cg := (double) echo('hello');
Use language attributes to specify templates for printing procedures and if/then/else structures in a target language.
LanguageDefinition[Define]("IfSampleLanguage", extend="default", SetLanguageAttribute( "Procedure_Begin" = proc(rettype, params) (Printer:-Indent(), rettype, " ", Printer:-GetScopeName()," ", params, Printer:-Endline()) end proc, "Procedure_End" = "", "ParameterSequence_Begin" = "(", "ParameterSequence_Delimiter" = ",", "ParameterSequence_End" = ")", "If_Begin" = proc(x) "if (",x,")" end proc, "If_Elsif" = proc(x) "else if (",x,")" end proc, "If_Else" = "else", "If_End" = "" ) ):
my_signum := proc(x) if x>0 then 1 elif x = 0 then 0 else -1 end if: end proc:
Translate⁡my_signum,language=IfSampleLanguage
integer my_signum (integer x) if (0 < x) Return(1); else if (x = 0) Return(0); else Return(-1);
See Also
Define
Language Attributes
Download Help Document