I'm wondering if it's possible to create grammar syntax rules that include an infinite number of "things"... for example, I want to write a "chord" rule that includes an infinite number of "notes" (tokens matching the "note" rule), divided by the "/" character. So a chord could be "note / note," "note / note / note," "note / note / note / note / note / note / note / note / note / note" (epic chord!), and so on.
Can I do something like this?
Code: Select all
chord : note / note
| note / chord
Would that work the way I'm thinking? or is there another way to do it?
As a side note, I wonder if it wouldn't be too difficult to just write my parser from scratch/regex instead of using PLY? I started doing that anyway until someone suggested that PLY would make things easier. The syntax of my language isn't all that complicated. Basically the notes, chords, and other musical events are presented in order, and the parser needs to go through them one by one and add them (in order) to a MIDI file using the mingus module. I'm kind of considering ditching PLY and just doing it by hand... any thoughts on that?