public inbox for ~johnnyrichard/olang-devel@lists.sr.ht
 help / color / mirror / code / Atom feed
From: Johnny Richard <johnny@johnnyrichard.com>
To: Carlos Maniero <carlos@maniero.me>
Cc: ~johnnyrichard/olang-devel@lists.sr.ht
Subject: Re: [PATCH olang v1 2/2] docs: spec: add variables and constants specification
Date: Mon, 1 Apr 2024 19:48:24 +0200	[thread overview]
Message-ID: <vhttsxxhkcqxoomgjrsxjx5abccbgwcykbkznnr4dldswnamhx@7oszwyib65zc> (raw)
In-Reply-To: <D05G059PH0LF.36U2JXZFJ1EU6@maniero.me>

On Thu, Mar 28, 2024 at 11:11:38AM -0300, Carlos Maniero wrote:
> On Wed Mar 27, 2024 at 6:37 PM -03, Johnny Richard wrote:
> > On Wed, Mar 27, 2024 at 12:21:28AM -0300, Carlos Maniero wrote:
> > > This commit introduces the specification for variables and constants. A
> > > valid program under this specification is as follows:
> > > 
> > >   var x: u32 = 1
> >
> > Since this patch adds support to assignments, lets also add support to
> > all assignment operators like "-=" "+=" "<<=" and so on.
> >
> > >   const y: u32 = 2
> >
> > This patch lacks support to the following valid assignment expression
> > (which I think adds flexibility to the language):
> >
> >     var x: u32 = a = b = c = 1
> >     var y: u32
> >     y = a = b = c = 1
> >
> > > -<global-statements>   ::= <function-definition>
> > > +<global-statements>   ::= <function-definition> | <variable-definition> | <variable-reassign> | <const-definition>
> >
> > nitpick: maybe _external-declaration_ sounds better since definitions are
> > not statements?
> 
> What do you think about *file-declarations* a file declaration? Does not
> mean that it is external. At least while we try to define a file.

hmm.. It sounds weird mention file. Feels like you are going to declare
files... But I don't want to spend a lot of time on it.  It was a
nitpick... If you think *external-declaration* is not good enough we can
keep *global-statement* (no blocking here).

> > > +
> > > +(* Variables *)
> > > +<variable-definition> ::= 'var' <ws> <variable-name> <ows> ':' <ows> <type> <ows> <variable-assign>?
> > > +<const-definition>    ::= 'const' <ws> <variable-name> <ows> ':' <ows> <type> <ows> <variable-assign>
> >
> > We don't need to define twice the variable-definition for "var" and
> > "const", let's combine both in a single rule.
> 
> I don't know if you noticed, but variables has an optional assignment
> while const has required assignment.

Sure, I noticed.  I took a look to how C solve this problem and seems
like it allows defining a const without assignment  (I don't know why...).

I would do the same to keep the gramma simple. And if we really want to
advice the developer about weird declaration, we could warning message
during semantics checking phase.

> > +<variable-definition>  ::= <variable-qualifier> <ws> <variable-name> <ows> ':' <ows> <type> (<ows> <assign-operator> <ows> <expression>)?
>
> This is invalid for const unless we want to allow unassigned constants.
> It also can be interpreted as a semantic error, in that case I believe
> the spec should not check for semantics.

Let's handle it during semantics analysis.

  reply	other threads:[~2024-04-01 16:47 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-27  3:21 [PATCH olang v1 0/2] docs: variables specification Carlos Maniero
2024-03-27  3:21 ` [PATCH olang v1 1/2] docs: spec: rename program to translation-unit Carlos Maniero
2024-03-27 21:20   ` Johnny Richard
2024-03-28 13:50     ` Carlos Maniero
2024-03-27  3:21 ` [PATCH olang v1 2/2] docs: spec: add variables and constants specification Carlos Maniero
2024-03-27  3:22   ` [olang/patches/.build.yml] build failed builds.sr.ht
2024-03-27 21:37   ` [PATCH olang v1 2/2] docs: spec: add variables and constants specification Johnny Richard
2024-03-28 14:11     ` Carlos Maniero
2024-04-01 17:48       ` Johnny Richard [this message]
2024-03-30  1:14     ` Carlos Maniero
2024-04-01 17:54       ` Johnny Richard
2024-04-11 22:39     ` [PATCH] fixup! " ricardo_kagawa
2024-04-12 22:36       ` Johnny Richard
2024-04-13  2:18         ` Carlos Maniero
2024-04-16 19:01         ` Johnny Richard

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=vhttsxxhkcqxoomgjrsxjx5abccbgwcykbkznnr4dldswnamhx@7oszwyib65zc \
    --to=johnny@johnnyrichard.com \
    --cc=carlos@maniero.me \
    --cc=~johnnyrichard/olang-devel@lists.sr.ht \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.johnnyrichard.com/olang.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox