0

私はこの文法を持っています:

name = /[_a-zA-Z][a-zA-Z0-9]*/;
expression = name '+' name;
def_body = 'def' name:name args:{name} body:expression;

しかし、解析しようとすると、常に式の名前が引数の一部として消費されます。args クロージャー内のすべての名前の前に、expression と一致し、渡された場合に終了できるかどうかをテストする方法はありますか?

前もって感謝します。

編集: セマンティクスを通じて解決しましたが、グラコ ebnf を通じて可能かどうかはまだ興味があります。

4

1 に答える 1

0

The lack of delimiters for the parameters requires looking further ahead in the input to decide if the closure should continue. A negative lookahead should solve the problem at the grammar level:

def_body = 'def' name:name args:{name !'+'} body:expression;

Lookahead are not "cheating". They're an integral part of the PEG definition for important reasons.

于 2015-04-12T12:11:34.110 に答える