Orlando Hill wrote:
 > Allowing individual characters in the AST is nice because, I'm able to
 > write things like this:
 >
 > Sum  <- Prod *([+-] Ws Prod)
 >
 > Prod <- Num *([*/] Ws Num)

Yes. And for these cases putting the characters into the AST is a good 
thing, as any AST reader will need to know which character is chosen.

You may be right; adding characters or strings might be the better 
default. It certainly makes grammars easier to write for cases like this.

 > ...
 > Number  <- ?'-'
 >            ('0' | [1-9] *[0-9])
 >            ?('.' +[0-9])
 >            ?([eE] ?[+-] +[0-9])

Isn't ('0' | [1-9] *[0-9]) equivalent to ([0-9] *[0-9])? Feel free to 
ignore this comment if you don't think it is interesting. One could 
nitpick grammars all day long. :)

 > ...
 > My guess is that, for most grammars, it's enough to just memoize the
 > non-terminals. Or, even just some of them.

Yes, that was what I was thinking. There are, in fact, a few PEG parsers 
out there that do no memoization at all. They are no less performant 
than most widely used regular expression implementations.

However, when you get around to implementing left recursion I expect 
you'll find another use for memos. That may render this discussion moot.

Bob


_______________________________________________
PEG mailing list
PEG@lists.csail.mit.edu
https://lists.csail.mit.edu/mailman/listinfo/peg

Reply via email to