I'm learning the PEGjs grammar and I request help or guide on the following:
I have functions like, PRODUCT(), SUM(), DIVIDE()
PRODUCT can take number/PRODUCT()/SUM()/DIVIDE(
) as parameters (any number but comma separated)
ex: PRODUCT(2, 5, SUM(5, 6, 7), DIVIDE(5, 2), PRODUCT(4, 6, 20, 12))
Same way the SUM can take any number of parameters separated by comma.
Ex: SUM(4, 5, 10, DIVIDE(SUM(2, 5, 6), 3))
DIVIDE will take two parameters (2 must), number's or another function
Ex: DIVIDE(3, PRODUCT(3, 4, SUM(2, 3)))
Could some one help or guide me how I can achieve?
The rules I have so far
start = sum
/multiply
multiply = "PRODUCT("a:digit "," __ b:digit ")" {return a * b}
sum = "SUM("a:digit "," b:digit ")" {return a + b}
digit = [0-9]
__ = WhiteSpace*
WhiteSpace "whitespace"
= [ \t\r\n]
The above rule only support product/sum of two number's. How can I achieve the above?
Thanks in Advance Manjunath Reddy