mpc icon indicating copy to clipboard operation
mpc copied to clipboard

Greedy matching causes token matching issue

Open joshuacrotts opened this issue 3 years ago • 0 comments

I'm writing an interpreter for a subset of Scheme, and have ran into a bit of a roadblock when implementing conditions, i.e., cond. The parser is greedily matching the first case of my cond rule instead of attempting to terminate the condition via "else". Here's what I mean:

"symbol : /[a-zA-Z_+\-\/\\=<>!&]+[a-zA-Z0-9_+\-\/\\=<>!&]/ ;\n" "cond : '(' "cond" ('(' ')')+ '('"else" ')'')' ;\n" "application : '(' ')' ;\n"

Here's an example: (cond ((= 3 4) 3) ((= 4 5) 4) (else 5))

Because "else" in the last clause is registered as a "symbol", it is getting pattern-matched as an application, meaning the entire thing is misinterpreted. I'm not sure if I just need to write my rules differently or if there's a way to non-greedily match the rule.

joshuacrotts avatar Jul 04 '22 07:07 joshuacrotts