GetPrecedence - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


Printer

  

GetPrecedence

  

get precedence for intermediate code name

  

SetPrecedence

  

set precedence for intermediate code name

 

Calling Sequence

Parameters

Description

Examples

Calling Sequence

Printer:-GetPrecedence(icname)

Printer:-SetPrecedence(icname, precedence)

Parameters

Printer

-

Printer module

icname

-

symbol; Intermediate Code name

precedence

-

integer

Description

• 

The procedure GetPrecedence returns the precedence of icname.

• 

The procedure SetPrecedence sets the precedence of icname to the value precedence.  The actual value is irrelevant except in comparison with the precedence of other Intermediate Code expressions for this language.

• 

Precedence controls how an expression is printed in the target language; specifically, it controls when it is necessary to print parentheses to protect an expression.  For example, in most programming languages the precedence of multiplication is higher than that of addition, enabling x+y*z to be interpreted as x added to the product of y and z.  But if, using SetPrecedence, you set the precedence of Sum to a higher value than that of Product, the previous expression must be printed with parentheses for correctness.

Examples

withCodeGeneration:

m := 'module() export PrintTarget, Printer;
   Printer := eval(LanguageDefinition[Get]("C")):-Printer;

   PrintTarget := proc(ic, digits::posint, prec::name, func_prec, namelist)::string;
      Printer:-PrintTarget(args);
   end proc:
   # set precedence of addition higher than that of multiplication
   Printer:-SetPrecedence(Names:-Sum = Printer:-GetPrecedence(Names:-Product)+5);
end module':

LanguageDefinitionAddMyLanguage,m

Translatexy+z,language=MyLanguage

cg = (x * y) + z;

See Also

Printer