Top  Previous  Next

Scripts > Productions > Alternatives


Alternatives are separated by the pipe character "|".




"all" | "nothing" denotes an alternative occurrence of "all" and "nothing" in the input.


text | number denotes the alternative productions text and number



Special cases are empty alternatives. Empty alternatives make sense, to execute an action, if no other alternative matches. For example an error message might be written in this case:


"all" | "nothing" | {{out << "Error"; }}



The first set of an empty alternative contains the special token EPS with the number 2. In the special case, that no further token follows the empty alternative in the grammar, inside of the token box of the debugger the expected token will be denoted by "EPS":


It is important, not to create an inadvertent empty alternative. This is the case in the following production:



X ::= (

      | "empty"

      | "size"

      | "clear"




Each of the alternative token is preceded by a pipe character '|'. But in front of the first there is nothing, to which an alternative is formed. Equivalent one could have written:


X ::= (


      | "size"

      | "clear"





To prevent the inadvertent construction of empty alternatives, these formulations are disallowed. If you really want to create an empty alternative without calling an action, you either can make the whole set of alternatives optional:


( "all" | "nothing" )?


or you can construct an empty alternative with an empty action:


"all" | "nothing" | {{ /*Empty*/ }}


Remark: Empty alternatives are nullable.




This page belongs to the TextTransformer Documentation

Home  Content  German