* [PATCH 1/4] docs: spec: refactor grammar specification
2024-04-16 20:17 [PATCH 0/4] docs: spec: constant initialization and assignments ricardo_kagawa
@ 2024-04-16 20:17 ` ricardo_kagawa
2024-04-16 22:32 ` Johnny Richard
2024-04-16 20:17 ` [PATCH 2/4] docs: spec: immediate constant initialization ricardo_kagawa
` (3 subsequent siblings)
4 siblings, 1 reply; 10+ messages in thread
From: ricardo_kagawa @ 2024-04-16 20:17 UTC (permalink / raw)
To: ~johnnyrichard/olang-devel; +Cc: Ricardo Kagawa
From: Ricardo Kagawa <ricardo_kagawa@disroot.org>
- Moved statements common to the translation unit and function bodies to
their own non-terminal.
- Moved some non-terminals from the "Statements" section to the
"Functions" section, as there will be some statements that are
function-body specific, some that are translation-unit specific, and
some that are common to both.
- Renamed "assign" to "assignment", for better wording.
- Renamed <integer> to <integer-literal> to make it more explicit that
this symbol represents a literal value.
- Replaced <identifier> in <expression> for <variable-name> to make it
more explicit that it must refer to a variable, and not just any
identifier.
Signed-off-by: Ricardo Kagawa <ricardo_kagawa@disroot.org>
---
docs/pages/language-specification.md | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/docs/pages/language-specification.md b/docs/pages/language-specification.md
index 4d0eb36..9f4383d 100644
--- a/docs/pages/language-specification.md
+++ b/docs/pages/language-specification.md
@@ -24,10 +24,11 @@ language.
(* Entry Point *)
<translation-unit> ::= (<ows> <external-declaration> <ows> (<end-of-statement> | <end-of-file>))*
-<external-declaration> ::= <function-definition> | <variable-definition>
+(* Translation Unit *)
+<external-declaration> ::= <common-statement> | <function-definition>
(* Variables *)
-<variable-definition> ::= <variable-qualifier> <ws> <variable-name> <ows> ':' <ows> <type> (<ows> <assign-operator> <ows> <expression>)?
+<variable-definition> ::= <variable-qualifier> <ws> <variable-name> <ows> ':' <ows> <type> (<ows> <assignment-operator> <ows> <expression>)?
<variable-qualifier> ::= 'var'
| 'const'
<variable-name> ::= <identifier>
@@ -38,17 +39,18 @@ language.
<function-parameters> ::= '(' <ows> ')'
<return-type> ::= <type>
<function-body> ::= <block>
+<block> ::= '{' <ows> <statement> <ows> (<end-of-statement> <ows> <statement> <ows>)* <end-of-statement>? <ows> '}'
+<statement> ::= <common-statement> | <return-statement>
+<return-statement> ::= 'return' <ws> <expression>
(* Statements *)
-<block> ::= '{' <ows> <statement> <ows> (<end-of-statement> <ows> <statement> <ows>)* <end-of-statement>? <ows> '}'
<end-of-statement> ::= ';' | <line-break>
-<statement> ::= <return-statement> | <variable-definition> | <assign-expression>
-<return-statement> ::= 'return' <ws> <expression>
+<common-statement> ::= <variable-definition> | <assignment-expression>
(* Expressions *)
-<expression> ::= <integer> | <identifier>
-<assign-expression> ::= <variable-name> <ows> <assign-operator> <ows> <expression>
-<assign-operator> ::= '='
+<expression> ::= <integer-literal> | <variable-name>
+<assignment-expression> ::= <variable-name> <ows> <assignment-operator> <ows> <expression>
+<assignment-operator> ::= '='
| '*='
| '/='
| '%='
@@ -65,7 +67,7 @@ language.
<identifier> ::= (<alpha> | '_') (<alpha> | <digit> | '_')*
(* Literals *)
-<integer> ::= <integer-base10> | <integer-base16>
+<integer-literal> ::= <integer-base10> | <integer-base16>
<integer-base10> ::= #'[1-9]' (<digit> | '_')* | '0'
<integer-base16> ::= #'0[Xx]' <hex-digit> (<hex-digit> | '_')*
--
2.44.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 2/4] docs: spec: immediate constant initialization
2024-04-16 20:17 [PATCH 0/4] docs: spec: constant initialization and assignments ricardo_kagawa
2024-04-16 20:17 ` [PATCH 1/4] docs: spec: refactor grammar specification ricardo_kagawa
@ 2024-04-16 20:17 ` ricardo_kagawa
2024-04-16 22:33 ` Johnny Richard
2024-04-16 20:17 ` [PATCH 3/4] docs: spec: remove assignment as expression ricardo_kagawa
` (2 subsequent siblings)
4 siblings, 1 reply; 10+ messages in thread
From: ricardo_kagawa @ 2024-04-16 20:17 UTC (permalink / raw)
To: ~johnnyrichard/olang-devel; +Cc: Ricardo Kagawa
From: Ricardo Kagawa <ricardo_kagawa@disroot.org>
This commit prevents declarations of uninitialized constants, as well as
prevents the use of assignment operators in variable and constant
declarations. This change was originally suggested by Maniero, with
different non-terminal names.
Signed-off-by: Ricardo Kagawa <ricardo_kagawa@disroot.org>
---
docs/pages/language-specification.md | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/docs/pages/language-specification.md b/docs/pages/language-specification.md
index 9f4383d..8d8544a 100644
--- a/docs/pages/language-specification.md
+++ b/docs/pages/language-specification.md
@@ -28,10 +28,10 @@ language.
<external-declaration> ::= <common-statement> | <function-definition>
(* Variables *)
-<variable-definition> ::= <variable-qualifier> <ws> <variable-name> <ows> ':' <ows> <type> (<ows> <assignment-operator> <ows> <expression>)?
-<variable-qualifier> ::= 'var'
- | 'const'
-<variable-name> ::= <identifier>
+<variable-definition> ::= 'var' <ws> <variable-name> <ows> ':' <ows> <type> <ows> <variable-initializer>?
+<constant-definition> ::= 'const' <ws> <variable-name> <ows> ':' <ows> <type> <ows> <variable-initializer>
+<variable-name> ::= <identifier>
+<variable-initializer> ::= '=' <ows> <expression>
(* Functions *)
<function-definition> ::= 'fn' <ws> <function-name> <ows> <function-parameters> <ows> ':' <ows> <return-type> <ows> <function-body>
--
2.44.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 3/4] docs: spec: remove assignment as expression
2024-04-16 20:17 [PATCH 0/4] docs: spec: constant initialization and assignments ricardo_kagawa
2024-04-16 20:17 ` [PATCH 1/4] docs: spec: refactor grammar specification ricardo_kagawa
2024-04-16 20:17 ` [PATCH 2/4] docs: spec: immediate constant initialization ricardo_kagawa
@ 2024-04-16 20:17 ` ricardo_kagawa
2024-04-16 22:34 ` Johnny Richard
2024-04-16 20:17 ` [PATCH 4/4] docs: spec: postpone assignment operators ricardo_kagawa
2024-04-16 21:58 ` [PATCH 0/4] docs: spec: constant initialization and assignments Carlos Maniero
4 siblings, 1 reply; 10+ messages in thread
From: ricardo_kagawa @ 2024-04-16 20:17 UTC (permalink / raw)
To: ~johnnyrichard/olang-devel; +Cc: Ricardo Kagawa
From: Ricardo Kagawa <ricardo_kagawa@disroot.org>
This commit prevents the use of assignments as expressions, to prevent
chained assignments and the use of assignments inside potential future
`if`, `while` and other statements. However, assignments are still
valid statements.
Signed-off-by: Ricardo Kagawa <ricardo_kagawa@disroot.org>
---
docs/pages/language-specification.md | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/docs/pages/language-specification.md b/docs/pages/language-specification.md
index 8d8544a..724ed67 100644
--- a/docs/pages/language-specification.md
+++ b/docs/pages/language-specification.md
@@ -45,11 +45,8 @@ language.
(* Statements *)
<end-of-statement> ::= ';' | <line-break>
-<common-statement> ::= <variable-definition> | <assignment-expression>
-
-(* Expressions *)
-<expression> ::= <integer-literal> | <variable-name>
-<assignment-expression> ::= <variable-name> <ows> <assignment-operator> <ows> <expression>
+<common-statement> ::= <variable-definition> | <constant-definition> | <assignment>
+<assignment> ::= <variable-name> <ows> <assignment-operator> <ows> <expression>
<assignment-operator> ::= '='
| '*='
| '/='
@@ -62,6 +59,9 @@ language.
| '^='
| '|='
+(* Expressions *)
+<expression> ::= <integer-literal> | <variable-name>
+
(* Identifiers *)
<type> ::= 'u32'
<identifier> ::= (<alpha> | '_') (<alpha> | <digit> | '_')*
--
2.44.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 4/4] docs: spec: postpone assignment operators
2024-04-16 20:17 [PATCH 0/4] docs: spec: constant initialization and assignments ricardo_kagawa
` (2 preceding siblings ...)
2024-04-16 20:17 ` [PATCH 3/4] docs: spec: remove assignment as expression ricardo_kagawa
@ 2024-04-16 20:17 ` ricardo_kagawa
2024-04-16 22:35 ` Johnny Richard
2024-04-16 21:58 ` [PATCH 0/4] docs: spec: constant initialization and assignments Carlos Maniero
4 siblings, 1 reply; 10+ messages in thread
From: ricardo_kagawa @ 2024-04-16 20:17 UTC (permalink / raw)
To: ~johnnyrichard/olang-devel; +Cc: Ricardo Kagawa
From: Ricardo Kagawa <ricardo_kagawa@disroot.org>
This commit temporarily removes the definition of assignment operators
from the grammar, since their corresponding binary operators are still
not in the grammar. The incomplete grammar would be ill defined,
although still syntactically valid.
Signed-off-by: Ricardo Kagawa <ricardo_kagawa@disroot.org>
---
docs/pages/language-specification.md | 10 ----------
1 file changed, 10 deletions(-)
diff --git a/docs/pages/language-specification.md b/docs/pages/language-specification.md
index 724ed67..3cf050e 100644
--- a/docs/pages/language-specification.md
+++ b/docs/pages/language-specification.md
@@ -48,16 +48,6 @@ language.
<common-statement> ::= <variable-definition> | <constant-definition> | <assignment>
<assignment> ::= <variable-name> <ows> <assignment-operator> <ows> <expression>
<assignment-operator> ::= '='
- | '*='
- | '/='
- | '%='
- | '+='
- | '-='
- | '<<='
- | '>>='
- | '&='
- | '^='
- | '|='
(* Expressions *)
<expression> ::= <integer-literal> | <variable-name>
--
2.44.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 0/4] docs: spec: constant initialization and assignments
2024-04-16 20:17 [PATCH 0/4] docs: spec: constant initialization and assignments ricardo_kagawa
` (3 preceding siblings ...)
2024-04-16 20:17 ` [PATCH 4/4] docs: spec: postpone assignment operators ricardo_kagawa
@ 2024-04-16 21:58 ` Carlos Maniero
4 siblings, 0 replies; 10+ messages in thread
From: Carlos Maniero @ 2024-04-16 21:58 UTC (permalink / raw)
To: ricardo_kagawa, ~johnnyrichard/olang-devel
Thank you so much for your contribution, Ricardo!
Just a few observations:
- In the future patches don't forget to define the
*format.subjectPrefix = PATCH olang*, this is how the olang CI is
triggered. This can be configured once at the repo's *.git/config*.
- We reword your first patch to "docs: spec: make non-terminals more
descriptivedocs: spec: make non-terminals more descriptive" just to
make clear at the short commit message, what the actual change is.
There is a concept we are trying to follow called git recipe history
[1].
Other than that everything is completely amazing! We are glad to
receive your inputs.
Applied!
To git.sr.ht:~johnnyrichard/olang
7cd840e..0046920 main -> main
^ permalink raw reply [flat|nested] 10+ messages in thread