public inbox for ~johnnyrichard/olang-devel@lists.sr.ht
 help / color / mirror / code / Atom feed
From: Johnny Richard <johnny@johnnyrichard.com>
To: ~johnnyrichard/olang-devel@lists.sr.ht
Cc: Johnny Richard <johnny@johnnyrichard.com>,
	Ricardo Kagawa <ricardo_kagawa@disroot.org>
Subject: [PATCH olang v1] spec: ebnf: add binary expressions
Date: Mon, 15 Apr 2024 20:20:24 +0200	[thread overview]
Message-ID: <20240415184116.140292-1-johnny@johnnyrichard.com> (raw)

The parser already implements binary operations, but currently we are
missing it on the language specification.

This change adds the already implemented binary operations grammar and
also enables expression with parenthesis.  

It's important to mention that the precedence was highly inspired on C.

Signed-off-by: Johnny Richard <johnny@johnnyrichard.com>
---

Ricardo, this is the missing spec I mentioned on your reply on variable
PATCH[1].  Let me know if this change make sense.

NOTE: This PATCH has been implemented on top of the commit mentioned
(base-commit) in the bottom of this PATCH.

[1]: Message-ID: <sm7jzr3mklfxscefg25cdhnrtjqldawquvgq6cdczi5kfyt4my@upgwv63nrzw7>

 docs/pages/language-specification.md | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/docs/pages/language-specification.md b/docs/pages/language-specification.md
index 4d0eb36..ff0a215 100644
--- a/docs/pages/language-specification.md
+++ b/docs/pages/language-specification.md
@@ -46,7 +46,22 @@ language.
 <return-statement>    ::= 'return' <ws> <expression>
 
 (* Expressions *)
-<expression>          ::= <integer> | <identifier>
+<expression>                ::= <binary-expression>
+<binary-expression>         ::= <logical-or-expression>
+<logical-or-expression>     ::= <logical-and-expression> (<ows> '||' <ows> <logical-and-expression>)*
+<logical-and-expression>    ::= <bitwise-or-expression> (<ows> '&&' <ows> <bitwise-or-expression>)*
+<bitwise-or-expression>     ::= <bitwise-xor-expression> (<ows> '|' <ows> <bitwise-xor-expression>)*
+<bitwise-xor-expression>    ::= <bitwise-and-expression> (<ows> '^' <ows> <bitwise-and-expression>)*
+<bitwise-and-expression>    ::= <cmp-eq-and-neq-expression> (<ows> '&' <ows> <cmp-eq-and-neq-expression>)*
+<cmp-eq-and-neq-expression> ::= <cmp-lt-and-gt-expression> (<ows> ('==' | '!=') <ows> <cmp-lt-and-gt-expression>)*
+<cmp-lt-and-gt-expression>  ::= <bitwise-shift-expression> (<ows> ('<' | '>') <ows> <bitwise-shift-expression>)*
+<bitwise-shift-expression>  ::= <additive-expression> (<ows> ('<<' | '>>') <ows> <additive-expression>)*
+<additive-expression>       ::= <multiplicative-expression> (<ows> ('+' | '-') <ows> <multiplicative-expression>)*
+<multiplicative-expression> ::= <primary-expression> (<ows> ('*' | '/') <ows> <primary-expression>)*
+<primary-expression>        ::= <integer>
+                              | <identifier>
+                              | '(' <ows>  <expression> <ows> ')'
+
 <assign-expression>   ::= <variable-name> <ows> <assign-operator> <ows> <expression>
 <assign-operator>     ::= '='
                         | '*='

base-commit: 7cd840ea689751643d2dd022b81d12d9581800cb
-- 
2.44.0


             reply	other threads:[~2024-04-15 17:43 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-15 18:20 Johnny Richard [this message]
2024-04-15 17:43 ` [olang/patches/.build.yml] build success builds.sr.ht
2024-04-16  3:33 ` [PATCH olang v1] spec: ebnf: add binary expressions Carlos Maniero
2024-04-16 19:20   ` Johnny Richard
2024-04-16 23:17     ` ricardo_kagawa
2024-04-18 23:17       ` Johnny Richard
2024-04-16 23:41 ` 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=20240415184116.140292-1-johnny@johnnyrichard.com \
    --to=johnny@johnnyrichard.com \
    --cc=ricardo_kagawa@disroot.org \
    --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