From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Nikolay Kudryavtsev <nikolay.kudryavtsev@gmail.com>
Cc: "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
Subject: Re: SMIE grammar for C-style function expressions
Date: Tue, 28 Sep 2021 09:07:33 -0400 [thread overview]
Message-ID: <jwv35poyhz5.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <1a33ce2e-7083-5b2e-b063-a897b118e21a@gmail.com> (Nikolay Kudryavtsev's message of "Tue, 28 Sep 2021 14:47:32 +0300")
> 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.
No, the better way to work with SMIE is to fix the problems that occur
rather than to try and first reproduce all the details of the grammar:
the SMIE grammars are almost always an approximation of the real grammar
that accepts meaningless programs as well, but we don't care.
> 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"
Any sequence of "atomic" elements is automatically handled by SMIE
without having to specify it in the grammar. If SMIE knows that "("
matches ")" then "( a )" is such an "atomic" element (similarly, if
SMIE is told that "f" matches "f-end", then "f ... f-end" is also an
atomic element).
So for the above example, the grammar just needs something like:
(defvar foo-grammar
'((exp ("(" exp ")")
("{" exp "}")
("f" exp "f-end"))))
And you may even skip the first two entries because they're probably
already described in the syntax-table.
Now the above will understand
f n (a) {s} f-end
like you want it to. It will also "understand"
f {a} n f (haha) f-end f-end
even though it's non-sensical, but we usually don't care about what SMIE
does with such nonsensical code.
Stefan
next prev parent reply other threads:[~2021-09-28 13:07 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-27 14:39 SMIE grammar for C-style function expressions Nikolay Kudryavtsev
2021-09-27 18:41 ` Filipp Gunbin
2021-09-27 19:36 ` Nikolay Kudryavtsev
2021-09-28 2:34 ` Stefan Monnier
2021-09-28 11:47 ` Nikolay Kudryavtsev
2021-09-28 13:07 ` Stefan Monnier [this message]
2021-09-28 18:12 ` Nikolay Kudryavtsev
2021-09-28 18:45 ` Stefan Monnier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwv35poyhz5.fsf-monnier+emacs@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=help-gnu-emacs@gnu.org \
--cc=nikolay.kudryavtsev@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).