views:

16

answers:

1

Im writing a parser than can parse expressions like myfunc1(), myfunc2(param1) and myfunc3(param1, param2) (with an unknown amount of parameters). Now I'm trying to get my parse expressions right. I'm using the Lemon Parser Generator. Here is what I've come up with:

application(res) ::= APPLICATIONNAME(a) BRACE_OPEN params BRACE_CLOSE. {res = a;}
application(res) ::= APPLICATIONNAME(a) BRACE_OPEN BRACE_CLOSE. {res = a;}
params ::= PARAM(p). {res = p;}
params ::= SEPARATOR. 

Never mind the contents of the curly braces for the moment. The params definition allows empty params (several separators after each other), which is ok at the moment. But how would I have to change the definition to force non-empty parameters but still have all parameters separated by the SEPARATOR token?

+1  A: 

following the example from http://www.hwaci.com/sw/lemon/lemon.html which reads

list ::= list element.      // left-recursion.  Good!
list ::= .

where list is either empty (the second rule) or contains at least one element, with individual element s separated by whitespace, i'd say you want

params ::= params SEPARATOR PARAM(p).
params ::= PARAM(p).
just somebody
If I'd like to allow empty params, would I add the line params ::= SEPARATOR ?
chiborg