I'm trying to create a parser using Treetop that is somewhat recursive. An expression can be a number but it also can be an addition of expressions, so I wrote this:
grammar Language
rule expression
"(" _ expression _ ")" / addition / integer
end
rule addition
expression _ "+" _ expression
/
expression _ "-" _ expression
end
rule integer
'-'? _ [0-9]+
end
# space
rule _
' '*
end
end
That just doesn't work. Any time I'm trying to parse anything I get an exception "SystemStackError: stack level too deep" (stack overflow! yay!). Any ideas why? what's the correct way to specify such a recursive definition with Treetop?