Arithmetic.ebnf 1.26 KB
Newer Older
eckhart's avatar
eckhart committed
1
2
3
4
5
6
7
8
# Arithmetic-grammar

#######################################################################
#
#  EBNF-Directives
#
#######################################################################

9
10
11
12
13
@ whitespace  = vertical           # implicit whitespace, includes any number of line feeds
@ literalws   = right              # literals have implicit whitespace on the right hand side
@ comment     = /#.*/              # comments range from a '#'-character to the end of the line
@ ignorecase  = False              # literals and regular expressions are case-sensitive
@ drop        = whitespace, token  # drop anonymous whitespace
eckhart's avatar
eckhart committed
14
15
16
17
18
19
20

#######################################################################
#
#  Structure and Components
#
#######################################################################

21
22
expression = term  { EXPR_OP~ term}
term       = factor  { TERM_OP~ factor}
23
factor     = [SIGN] ( NUMBER | VARIABLE | group ) { VARIABLE | group }
eckhart's avatar
eckhart committed
24
25
26
27
group      = "(" expression ")"

#######################################################################
#
28
# "Leaf"-Expressions
eckhart's avatar
eckhart committed
29
30
31
#
#######################################################################

32
33
EXPR_OP    = /\+/ | /-/
TERM_OP    = /\*/ | /\//
34
35
SIGN       = /-/

eckhart's avatar
eckhart committed
36
37
NUMBER     = /(?:0|(?:[1-9]\d*))(?:\.\d+)?/~
VARIABLE   = /[A-Za-z]/~