...
Let's first allow more complex expressions such as 1
or 1+2
or 1+2+3+4
This starts with a single number, then can add a plus sign and a number (possibly more than once):
Code Block | ||
---|---|---|
| ||
add: NUMBER (PLUS NUMBER)* | {code
The
...
*
...
symbol
...
means
...
"zero
...
or
...
more
...
times".
...
If
...
you
...
want
...
to
...
implement
...
both
...
addition
...
and
...
subtraction,
...
you
...
can
...
make
...
a
...
small
...
adjustment:
...
Code Block | ||
---|---|---|
| ||
add: NUMBER ((PLUS | MINUS) NUMBER)* MINUS : '-'; |
...