help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: SMIE grammar for C-style function expressions


From: Nikolay Kudryavtsev
Subject: Re: SMIE grammar for C-style function expressions
Date: Tue, 28 Sep 2021 14:47:32 +0300
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0

I understand that SMIE does not concern itself with the AST, but I think it's reasonable to start with describing the language grammar for it in the most naive way, until we have a good reason not to. "f n ( a ) { s }" is a single expression in the language, so someone implementing a grammar for such language may first try to declare it in SMIE as a single expression.

To try and keep the problem stated in practical terms, lets say the language grammar looks like this:

args = ( a )

stmts = { s }

"f" n args stmts "f-end"

With the point after "f-end", I want backward-sexp to put me past "f" and for this:

(A)I have to keep the entire expression within a single SMIE declaration.

(B)My lexer has to add some virtual keywords to separate nonterminals:

"f" n " : " args " : " stmts "f-end"

Is this the proper approach? Are my assumptions A and B correct?

P. S. I've add "f-end" here to wave off the ambiguity caused by the last token in the real C-style expression being both main and child expression closer, since that problem, while real, is not the issue here.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]