Gentee Programming Language > Documentation > Syntax | Download documentation |
The conditional compilation command ifdef allows the compiler to include or ignore some parts of the program, it depends upon conditions to be evaluated. For example, you can use the expression which consists of macros and constants, i.e a number, a string and a data set.
<macro expression> ::= <macro> | <constant> | '!'<macro expression> | '('<macro expression>')' | <macro expression> ( '&&' | '||' | '==' | '!=' ) <macro expression>
Note that the result of any operation is 0 as False or 1 as True.
== the equality operator, a binary operator, is used to test both operands for equality. The result of a relational expression is 1 if the tested relationship is True and 0 if it is False. The types of the operands must be the same; if the operands are strings, they are compared character-by-character. != the inequality operator (a binary operator) is exactly the negation of equality. && the logical-AND operator (a binary operator) produces the value 1 if both operands have nonzero values, otherwise the result is 0. || the logical-OR operator (a binary operator) produces the value 1 if either operand has a nonzero value. ! the logical-NOT operator (a unary operator) produces the value 1 if its operand is 0 and vice versa.
Parenthesis can also be used to group operands.
Operator precedence in Gentee is defined below, from the higher to the lower one.
!
==, !=
&&
||
The logical operators ! perform numeric calculations, and the operands are strings or data sets, the values of which are converted to 0 or 1 by default. If the string or the data set is Null, they evaluate to False (0); otherwise, they evaluate to 1.
<ifdef> ::= ifdef <macro expression> '{' ... '}' { elif <macro expression> '{' ... '}' } [ else '{' ... '}']
The command ifdef description: first, the conditional-expression follows the ifdef command, then the block contains the text portion which is to be compiled, if the conditional expression is evaluated, i.e. it is not equal to 0.
ifdef $a == 5 { include "adv.g" //This file is to be included, if macro a equals 5. }
If another text portion is to be compiled and the conditional expression is False, the (optional) elsecommand is used.
ifdef $a==5 { include : "adv.g" // This file is to be included, if macro a equals 5. } else { include : "def.g" // This file is to be included, if macro a is not equal 5. }
elif, an abbreviation of "else if," lets you create a compound conditional command. You can use several elif commands one after another, which can be followed by the else command.
ifdef $a == 1 { include : "a.g" } elif $a == 2 { include : "b.g" } elif $a == 3 { include : "c.g" } else { include : "else.g" }
The ifdef command can be nested within any block of code.
See also![]() |
![]() Copyright © 2004-2006 Gentee Inc. All rights reserved. ![]() |