add language attribute to Printer module - Maple Help

Online Help

All Products    Maple    MapleSim

Home : Support : Online Help : Programming : Code Generation Package : Language Definition : Printer : CodeGeneration/LanguageDefinition/Printer/SetLanguageAttribute

Printer:-SetLanguageAttribute - add language attribute to Printer module

Printer:-ApplyLanguageAttribute - apply language attribute to remaining arguments

Printer:-GetLanguageAttribute - get language attribute from Printer module

Calling Sequence

Printer:-SetLanguageAttribute(expr, ...)






Printer module



string (str) or equation of the form (str = val)



string; name of language attribute



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.




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",
        "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:


integer my_signum (integer x)

  if (0 < x)    Return(1);
  else if (x = 0)    Return(0);
  else    Return(-1);

See Also

Define, Language Attributes, Printer

Download Help Document

Copyright © MathResources Inc. All Rights Reserved.

Was this information helpful?

Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam