The set of tokens of the language is
{
+,
-,
^,
(,
),
NUMBER}. The token
NUMBER represents unsigned integers, i.e., non-empty sequences of
digits. Examples of correct expressions are
- “-(1)”
- “2^(-3+-4)^5”
- “1++2”
- “3^-4”
whereas
- “1+”
- “1(^0)”
- “2^^3”
- “1 2”
are not. The generated AST must correspond to an interpretation of the
+
and
- binary operators as left-associative and exponentiation as
right-associative. The precedence differs from the usual in that exponentiation
has more precedence than unary operators. As an example, for input
-1^2^(-3)
the resulting AST must be
-(^(1,^(2,-(3))))
i.e., as if the implicit parenthesization was
-(1^(2^(-3)))