I'm working on a small parser with PackCC and am having a bit of trouble knowing what to do when a rule is matched n times, where n is unknown at compile time. Essentially, I use C actions to create an abstract syntax tree for a given rule, then add its children if any exist. This works when the number of children is determined at compile time.
Consider the following rule:
application <- '(' e:expr* ')' { $$ = ??? }
/ '{' e:expr* '}' {}
/ '[' e:expr* ']' {}
This should match function applications, e.g., (+ 5 4 3 2)
. The issue is that I don't know how to retrieve the ith expression. Using the $n
prefixes is, again, limited to knowing how many matches there are at compile time. What's the solution?