public inbox for ~johnnyrichard/olang-devel@lists.sr.ht
 help / color / mirror / code / Atom feed
b21846214de02db51d1c47d9856b576c0979d4eb blob 2830 bytes (raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
 
% O programming language specification

Abstract
--------

This document specifies the semantics and behavior of the O Programming
Language for compiler designers be informed how the language is designed.

This specification is a DRAFT and will be the discussions drive over olang-dev
mailing list.

Language Syntax
---------------

This is the O Programming Language EBNF grammar specification[^1]

[^1]: EBNF variant https://github.com/Engelberg/instaparse/tree/v1.4.12 and live
      test can be accessed here https://mdkrajnak.github.io/ebnftest/

NOTE: This grammar spec is a DRAFT and it covers only a small portion of the
language.

```
(* Entry Point *)
<translation-unit>     ::= (<ows> <external-declaration> <ows> (<end-of-statement> | <end-of-file>))*

(* Translation Unit *)
<external-declaration>  ::= <common-statement> | <function-definition>

(* Variables *)
<variable-definition>   ::= 'var' <ws> <variable-name> <ows> ':' <ows> <type> <ows> <variable-initializer>?
<const-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>
<function-name>       ::= <identifier>
<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 *)
<end-of-statement>    ::= ';' | <line-break>
<common-statement>    ::= <variable-definition> | <const-definition> | <assignment-expression>

(* Expressions *)
<expression>            ::= <integer> | <variable-name> | <assignment-expression>
<assignment-expression> ::= <variable-name> <ows> <assignment-operator> <ows> <expression>
<assignment-operator>   ::= '='

(* Identifiers *)
<type>                ::= 'u32'
<identifier>          ::= (<alpha> | '_') (<alpha> | <digit> | '_')*

(* Literals *)
<integer>             ::= <integer-base10> | <integer-base16>
<integer-base10>      ::= #'[1-9]' (<digit> | '_')* | '0'
<integer-base16>      ::= #'0[Xx]' <hex-digit> (<hex-digit> | '_')*

(* Utilities *)
<ws>                  ::= <white-space>+
<ows>                 ::= <white-space>*
<white-space>         ::= <linear-space> | <line-break>
<line-break>          ::= #'[\n\v\f\r]' | '\r\n'
<linear-space>        ::= #'[ \t]'
<alpha>               ::= #'[a-zA-Z]'
<digit>               ::= #'[0-9]'
<hex-digit>           ::= <digit> | #'[a-fA-F]'
<end-of-file>         ::= #'$'
```
debug log:

solving b218462 ...
found b218462 in http://lists.johnnyrichard.com/olang/20240411224539.42752-1-ricardo_kagawa@disroot.org/
found 2650dd9 in http://lists.johnnyrichard.com/olang/u7zpxqr57xx7ulhvzb35oinkz3ywnvjgq4i5x4b63kx4hvy6qq@7xnpwsr2w7y2/
found 708b679 in http://lists.johnnyrichard.com/olang/20240327032128.406911-3-carlos@maniero.me/
found 4541ba8 in http://lists.johnnyrichard.com/olang/20240327032128.406911-2-carlos@maniero.me/
found 5769d95 in https://git.johnnyrichard.com/olang.git
preparing index
index prepared:
100644 5769d957c3f358e43cfaf8d7cc70765fa8f017f2	docs/pages/language-specification.md

applying [1/4] http://lists.johnnyrichard.com/olang/20240327032128.406911-2-carlos@maniero.me/
diff --git a/docs/pages/language-specification.md b/docs/pages/language-specification.md
index 5769d95..4541ba8 100644


applying [2/4] http://lists.johnnyrichard.com/olang/20240327032128.406911-3-carlos@maniero.me/
diff --git a/docs/pages/language-specification.md b/docs/pages/language-specification.md
index 4541ba8..708b679 100644


applying [3/4] http://lists.johnnyrichard.com/olang/u7zpxqr57xx7ulhvzb35oinkz3ywnvjgq4i5x4b63kx4hvy6qq@7xnpwsr2w7y2/
diff --git a/docs/pages/language-specification.md b/docs/pages/language-specification.md
index 708b679..2650dd9 100644


applying [4/4] http://lists.johnnyrichard.com/olang/20240411224539.42752-1-ricardo_kagawa@disroot.org/
diff --git a/docs/pages/language-specification.md b/docs/pages/language-specification.md
index 2650dd9..b218462 100644

Checking patch docs/pages/language-specification.md...
Applied patch docs/pages/language-specification.md cleanly.
Checking patch docs/pages/language-specification.md...
Applied patch docs/pages/language-specification.md cleanly.
2:74: trailing whitespace.
<external-declaration> ::= <function-definition> 
Checking patch docs/pages/language-specification.md...
Applied patch docs/pages/language-specification.md cleanly.
Checking patch docs/pages/language-specification.md...
Applied patch docs/pages/language-specification.md cleanly.
warning: 1 line adds whitespace errors.

index at:
100644 b21846214de02db51d1c47d9856b576c0979d4eb	docs/pages/language-specification.md

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