Commit f3b095b7 authored by eckhart's avatar eckhart

- examples/ArithmeticExperimental: bugfixes

parent 25c1605d
......@@ -41,7 +41,7 @@ div = factor "/" term
#
#######################################################################
factor = [sign] [element] tail ~
factor = [sign] ([element] tail | element) ~
tail = seq | tail_elem
seq = tail_elem tail
sign = PLUS | MINUS
......@@ -55,7 +55,7 @@ sign = PLUS | MINUS
element = pow | value
pow = value `^` [sign] element
value = number | tail_value
value = (number | tail_value) [imaginary]
tail_elem = tail_pow | tail_value
tail_pow = tail_value `^` pow
......@@ -82,12 +82,11 @@ log = 'log(' §expression `)`
#
#######################################################################
number = special | imaginary | real
special = pi | e
number = NUMBER
special = (pi | e)
pi = `pi` | `π`
e = `e`
imaginary = [NUMBER] `i`
real = NUMBER !`i`
imaginary = `i`
#######################################################################
......@@ -99,4 +98,4 @@ real = NUMBER !`i`
PLUS = /\+/
MINUS = /-/
NUMBER = /(?:0|(?:[1-9]\d*))(?:\.\d+)?/
VARIABLE = /[j-z]/
VARIABLE = /[a-dj-z]/
......@@ -64,7 +64,7 @@ class ArithmeticExperimentalGrammar(Grammar):
sign = Forward()
tail = Forward()
term = Forward()
source_hash__ = "728734b427a80706ded8fe35fc451fdf"
source_hash__ = "275cee2bc98d92d9330bcc71dde3afe3"
static_analysis_pending__ = [True]
parser_initialization__ = ["upon instantiation"]
resume_rules__ = {}
......@@ -73,16 +73,15 @@ class ArithmeticExperimentalGrammar(Grammar):
WSP_RE__ = mixin_comment(whitespace=WHITESPACE__, comment=COMMENT__)
dwsp__ = DropWhitespace(WSP_RE__)
wsp__ = Whitespace(WSP_RE__)
VARIABLE = RegExp('[j-z]')
VARIABLE = RegExp('[a-dj-z]')
NUMBER = RegExp('(?:0|(?:[1-9]\\d*))(?:\\.\\d+)?')
MINUS = RegExp('-')
PLUS = RegExp('\\+')
real = Series(NUMBER, NegativeLookahead(DropToken("i")))
imaginary = Series(Option(NUMBER), DropToken("i"))
imaginary = Token("i")
e = Token("e")
pi = Alternative(DropToken("pi"), DropToken("π"))
special = Alternative(pi, e)
number = Alternative(special, imaginary, real)
number = Synonym(NUMBER)
log = Series(Series(DropToken('log('), dwsp__), expression, DropToken(")"), mandatory=1)
tan = Series(Series(DropToken('tan('), dwsp__), expression, DropToken(")"), mandatory=1)
cos = Series(Series(DropToken('cos('), dwsp__), expression, DropToken(")"), mandatory=1)
......@@ -92,13 +91,13 @@ class ArithmeticExperimentalGrammar(Grammar):
tail_value = Alternative(special, function, VARIABLE, group)
tail_pow = Series(tail_value, DropToken("^"), pow)
tail_elem = Alternative(tail_pow, tail_value)
value = Alternative(number, tail_value)
value = Series(Alternative(number, tail_value), Option(imaginary))
pow.set(Series(value, DropToken("^"), Option(sign), element))
element.set(Alternative(pow, value))
sign.set(Alternative(PLUS, MINUS))
seq = Series(tail_elem, tail)
tail.set(Alternative(seq, tail_elem))
factor = Series(Option(sign), Option(element), tail, dwsp__)
factor = Series(Option(sign), Alternative(Series(Option(element), tail), element), dwsp__)
div = Series(factor, Series(DropToken("/"), dwsp__), term)
mul = Series(factor, Series(DropToken("*"), dwsp__), term)
term.set(Alternative(mul, div, factor))
......
......@@ -22,11 +22,12 @@ F5: -22
M1: j
M2: x
M3: z
M4: a
[fail:VARIABLE]
F1: ä
F2: ab
F3: a
F3: A
F4: e
F5: i
F6: π
......
......@@ -2,17 +2,15 @@
M1: 2
M2: 2.5
M3: 0.3
M4: i
M5: 2i
M6: π
M7: pi
M8: e
[fail:number]
F1: j
F2: x
F3: X
F4: PI
F3: i
F4: 2i
F5: π
F6: pi
F7: e
[match:special]
......@@ -41,26 +39,12 @@ M1: e
[match:imaginary]
M1: i
M2: 2i
M3: 2.5i
[fail:imaginary]
# imaginary only represents the imaginary unit, not imaginary or complex numbers
F1: j
F2: 2j
F3: 3+2j
[match:real]
M1: 0
M2: 1
M3: 2.7818
M4: 3.1415
[fail:real]
F1: i
F2: 2i
F3: 2.5i
F4: 2,5
F4: 2+3i
[match:function]
M1: "sin(x+y)"
M2: "cos(2y)"
M3: "tan(3)"
M4: "log(2*x+3)"
[ast:function]
[fail:function]
F1: "f(x)"
[match:sin]
M1: "sin(x)"
[ast:sin]
[fail:sin]
F1: "cos(x)"
F2: "tan(x)"
F3: "log(x)"
[match:cos]
M1: "cos(x)"
[ast:cos]
[fail:cos]
F1: "sin(x)"
F2: "tan(x)"
F3: "log(x)"
[match:tan]
M1: "tan(x)"
[ast:tan]
[fail:tan]
F1: "sin(x)"
F2: "cos(x)"
F3: "log(x)"
[match:log]
M1: "log(x)"
[ast:log]
[fail:log]
F1: "sin(x)"
F2: "cos(x)"
F3: "tan(x)"
......@@ -15,6 +15,7 @@ M12: "1 + 2 - 3 - 4"
M13: "1 - 2 - 3 - 4"
M14: "1 - 2 * 3 - 4 + 5"
M15: "1 - 3 + 3 * 4"
M16: "a * b"
[ast:expression]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment