2022-02-02 21:07:27 +03:00
|
|
|
; Copyright (C) 2019-2022 Aleo Systems Inc.
|
2021-04-21 01:52:08 +03:00
|
|
|
; This file is part of the Leo library.
|
2021-03-23 19:11:42 +03:00
|
|
|
|
2021-04-21 01:52:08 +03:00
|
|
|
; The Leo library is free software: you can redistribute it and/or modify
|
|
|
|
; it under the terms of the GNU General Public License as published by
|
|
|
|
; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
; (at your option) any later version.
|
2021-03-23 19:11:42 +03:00
|
|
|
|
2021-04-21 01:52:08 +03:00
|
|
|
; The Leo library is distributed in the hope that it will be useful,
|
|
|
|
; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
; GNU General Public License for more details.
|
2021-03-23 19:11:42 +03:00
|
|
|
|
2021-04-21 01:52:08 +03:00
|
|
|
; You should have received a copy of the GNU General Public License
|
|
|
|
; along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
2021-03-23 19:11:42 +03:00
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
; Lexical Grammar
|
|
|
|
; ---------------
|
|
|
|
|
2022-04-14 12:04:20 +03:00
|
|
|
ascii = %x0-7F
|
|
|
|
|
|
|
|
safe-nonascii = %x80-2029 / %x202F-2065 / %x2070-D7FF / %xE000-10FFFF
|
2022-04-22 06:02:25 +03:00
|
|
|
; excludes bidi embeddings/overrides/isolates
|
|
|
|
; and excludes high/low surrogates
|
2022-04-14 12:04:20 +03:00
|
|
|
|
|
|
|
character = ascii / safe-nonascii
|
2021-03-23 19:11:42 +03:00
|
|
|
|
2021-04-22 07:56:27 +03:00
|
|
|
horizontal-tab = %x9 ; <HT>
|
2021-03-23 19:11:42 +03:00
|
|
|
|
2021-04-22 07:56:27 +03:00
|
|
|
line-feed = %xA ; <LF>
|
2021-03-23 19:11:42 +03:00
|
|
|
|
2021-04-22 07:56:27 +03:00
|
|
|
carriage-return = %xD ; <CR>
|
2021-03-23 19:11:42 +03:00
|
|
|
|
2021-04-22 07:56:27 +03:00
|
|
|
space = %x20 ; <SP>
|
2021-03-23 19:11:42 +03:00
|
|
|
|
2021-04-22 07:56:27 +03:00
|
|
|
double-quote = %x22 ; "
|
2021-03-23 19:11:42 +03:00
|
|
|
|
2021-05-13 04:41:58 +03:00
|
|
|
single-quote = %x27 ; '
|
|
|
|
|
2022-04-14 12:04:20 +03:00
|
|
|
not-star = %x0-29 / %x2B-7F / safe-nonascii ; anything but *
|
2021-03-23 19:11:42 +03:00
|
|
|
|
2022-04-14 12:04:20 +03:00
|
|
|
not-star-or-slash = %x0-29 / %x2B-2E / %x30-7F / safe-nonascii
|
2022-03-24 21:55:35 +03:00
|
|
|
; anything but * or /
|
2021-05-13 05:11:31 +03:00
|
|
|
|
2022-04-14 12:04:20 +03:00
|
|
|
not-line-feed-or-carriage-return = %x0-9 / %xB-C / %xE-7F / safe-nonascii
|
2021-04-21 20:44:40 +03:00
|
|
|
; anything but <LF> or <CR>
|
2021-03-23 19:11:42 +03:00
|
|
|
|
2022-04-14 12:04:20 +03:00
|
|
|
not-double-quote-or-backslash = %x0-21 / %x23-5B / %x5D-7F / safe-nonascii
|
2021-05-13 05:04:11 +03:00
|
|
|
; anything but " or \
|
|
|
|
|
2022-04-14 12:04:20 +03:00
|
|
|
not-single-quote-or-backslash = %x0-26 / %x28-5B / %x5D-7F / safe-nonascii
|
2021-05-13 04:41:58 +03:00
|
|
|
; anything but ' or \
|
|
|
|
|
2022-02-02 21:07:27 +03:00
|
|
|
line-terminator = line-feed / carriage-return / carriage-return line-feed
|
2021-03-23 19:11:42 +03:00
|
|
|
|
2022-02-02 21:07:27 +03:00
|
|
|
whitespace = space / horizontal-tab / line-terminator
|
2021-03-23 19:11:42 +03:00
|
|
|
|
|
|
|
comment = block-comment / end-of-line-comment
|
|
|
|
|
|
|
|
block-comment = "/*" rest-of-block-comment
|
|
|
|
|
|
|
|
rest-of-block-comment = "*" rest-of-block-comment-after-star
|
|
|
|
/ not-star rest-of-block-comment
|
|
|
|
|
|
|
|
rest-of-block-comment-after-star = "/"
|
|
|
|
/ "*" rest-of-block-comment-after-star
|
|
|
|
/ not-star-or-slash rest-of-block-comment
|
|
|
|
|
2022-02-02 21:07:27 +03:00
|
|
|
end-of-line-comment = "//" *not-line-feed-or-carriage-return
|
2021-03-23 19:11:42 +03:00
|
|
|
|
|
|
|
keyword = %s"address"
|
|
|
|
/ %s"bool"
|
2021-05-13 04:22:08 +03:00
|
|
|
/ %s"char"
|
2021-03-23 19:11:42 +03:00
|
|
|
/ %s"console"
|
|
|
|
/ %s"const"
|
2022-04-11 20:01:54 +03:00
|
|
|
/ %s"constant"
|
2021-03-23 19:11:42 +03:00
|
|
|
/ %s"else"
|
|
|
|
/ %s"field"
|
|
|
|
/ %s"for"
|
|
|
|
/ %s"function"
|
|
|
|
/ %s"group"
|
|
|
|
/ %s"i8"
|
|
|
|
/ %s"i16"
|
|
|
|
/ %s"i32"
|
|
|
|
/ %s"i64"
|
|
|
|
/ %s"i128"
|
|
|
|
/ %s"if"
|
|
|
|
/ %s"in"
|
|
|
|
/ %s"let"
|
2022-04-07 23:07:37 +03:00
|
|
|
/ %s"public"
|
2021-03-23 19:11:42 +03:00
|
|
|
/ %s"return"
|
2022-05-14 07:32:56 +03:00
|
|
|
/ %s"scalar"
|
2021-03-23 19:11:42 +03:00
|
|
|
/ %s"u8"
|
|
|
|
/ %s"u16"
|
|
|
|
/ %s"u32"
|
|
|
|
/ %s"u64"
|
|
|
|
/ %s"u128"
|
|
|
|
|
|
|
|
uppercase-letter = %x41-5A ; A-Z
|
|
|
|
|
|
|
|
lowercase-letter = %x61-7A ; a-z
|
|
|
|
|
|
|
|
letter = uppercase-letter / lowercase-letter
|
|
|
|
|
2021-08-03 03:59:13 +03:00
|
|
|
decimal-digit = %x30-39 ; 0-9
|
2021-08-03 03:56:47 +03:00
|
|
|
|
2021-05-13 04:41:58 +03:00
|
|
|
octal-digit = %x30-37 ; 0-7
|
|
|
|
|
2021-08-03 03:59:13 +03:00
|
|
|
hexadecimal-digit = decimal-digit / "a" / "b" / "c" / "d" / "e" / "f"
|
2021-05-13 04:41:58 +03:00
|
|
|
|
2021-08-03 03:59:13 +03:00
|
|
|
identifier = letter *( letter / decimal-digit / "_" )
|
2021-07-27 07:12:30 +03:00
|
|
|
; but not a keyword or a boolean literal or aleo1...
|
2021-03-23 19:11:42 +03:00
|
|
|
|
[ABNF] Rename 'natural' to 'numeral'.
This applies both to the rule name and to the terminology used for that, namely
for a non-empty sequence of decimal digits.
While 'natural' was meant to describe a natural number (i.e. a non-negative
integer: 0, 1, 2, ...), it is perhaps not a familiar term to many users.
On the other hand, 'integer', while often used in programming languages for this
kind of thing, is not ideal as integers may be negative.
Also, assuming type inference, a lone numeral like `17` may actually not denote
an integer number at all, because it may actually denote a group element if type
inference turns it into `17group`, and group elements are not integers.
All in all, 'numeral' seems like a good term, also according to its dictionary
definition. It is used in the Java grammar to denote this kind of thing, for
instance.
If, in the future, we want to allow hexadecimal, octal, or binary notation, we
could rename this to `decimal-numeral`, introduce `hexadecimal-numeral`,
`octal-numeral`, and `binary-numeral`, and `numeral` as the union of these.
2022-03-11 02:23:58 +03:00
|
|
|
numeral = 1*decimal-digit
|
2021-03-23 19:11:42 +03:00
|
|
|
|
[ABNF] Rename 'natural' to 'numeral'.
This applies both to the rule name and to the terminology used for that, namely
for a non-empty sequence of decimal digits.
While 'natural' was meant to describe a natural number (i.e. a non-negative
integer: 0, 1, 2, ...), it is perhaps not a familiar term to many users.
On the other hand, 'integer', while often used in programming languages for this
kind of thing, is not ideal as integers may be negative.
Also, assuming type inference, a lone numeral like `17` may actually not denote
an integer number at all, because it may actually denote a group element if type
inference turns it into `17group`, and group elements are not integers.
All in all, 'numeral' seems like a good term, also according to its dictionary
definition. It is used in the Java grammar to denote this kind of thing, for
instance.
If, in the future, we want to allow hexadecimal, octal, or binary notation, we
could rename this to `decimal-numeral`, introduce `hexadecimal-numeral`,
`octal-numeral`, and `binary-numeral`, and `numeral` as the union of these.
2022-03-11 02:23:58 +03:00
|
|
|
unsigned-literal = numeral ( %s"u8" / %s"u16" / %s"u32" / %s"u64" / %s"u128" )
|
2021-03-23 19:11:42 +03:00
|
|
|
|
[ABNF] Rename 'natural' to 'numeral'.
This applies both to the rule name and to the terminology used for that, namely
for a non-empty sequence of decimal digits.
While 'natural' was meant to describe a natural number (i.e. a non-negative
integer: 0, 1, 2, ...), it is perhaps not a familiar term to many users.
On the other hand, 'integer', while often used in programming languages for this
kind of thing, is not ideal as integers may be negative.
Also, assuming type inference, a lone numeral like `17` may actually not denote
an integer number at all, because it may actually denote a group element if type
inference turns it into `17group`, and group elements are not integers.
All in all, 'numeral' seems like a good term, also according to its dictionary
definition. It is used in the Java grammar to denote this kind of thing, for
instance.
If, in the future, we want to allow hexadecimal, octal, or binary notation, we
could rename this to `decimal-numeral`, introduce `hexadecimal-numeral`,
`octal-numeral`, and `binary-numeral`, and `numeral` as the union of these.
2022-03-11 02:23:58 +03:00
|
|
|
signed-literal = numeral ( %s"i8" / %s"i16" / %s"i32" / %s"i64" / %s"i128" )
|
2021-03-23 19:11:42 +03:00
|
|
|
|
[ABNF] Rename 'natural' to 'numeral'.
This applies both to the rule name and to the terminology used for that, namely
for a non-empty sequence of decimal digits.
While 'natural' was meant to describe a natural number (i.e. a non-negative
integer: 0, 1, 2, ...), it is perhaps not a familiar term to many users.
On the other hand, 'integer', while often used in programming languages for this
kind of thing, is not ideal as integers may be negative.
Also, assuming type inference, a lone numeral like `17` may actually not denote
an integer number at all, because it may actually denote a group element if type
inference turns it into `17group`, and group elements are not integers.
All in all, 'numeral' seems like a good term, also according to its dictionary
definition. It is used in the Java grammar to denote this kind of thing, for
instance.
If, in the future, we want to allow hexadecimal, octal, or binary notation, we
could rename this to `decimal-numeral`, introduce `hexadecimal-numeral`,
`octal-numeral`, and `binary-numeral`, and `numeral` as the union of these.
2022-03-11 02:23:58 +03:00
|
|
|
field-literal = numeral %s"field"
|
2021-03-23 19:11:42 +03:00
|
|
|
|
[ABNF] Rename 'natural' to 'numeral'.
This applies both to the rule name and to the terminology used for that, namely
for a non-empty sequence of decimal digits.
While 'natural' was meant to describe a natural number (i.e. a non-negative
integer: 0, 1, 2, ...), it is perhaps not a familiar term to many users.
On the other hand, 'integer', while often used in programming languages for this
kind of thing, is not ideal as integers may be negative.
Also, assuming type inference, a lone numeral like `17` may actually not denote
an integer number at all, because it may actually denote a group element if type
inference turns it into `17group`, and group elements are not integers.
All in all, 'numeral' seems like a good term, also according to its dictionary
definition. It is used in the Java grammar to denote this kind of thing, for
instance.
If, in the future, we want to allow hexadecimal, octal, or binary notation, we
could rename this to `decimal-numeral`, introduce `hexadecimal-numeral`,
`octal-numeral`, and `binary-numeral`, and `numeral` as the union of these.
2022-03-11 02:23:58 +03:00
|
|
|
product-group-literal = numeral %s"group"
|
2021-03-23 19:11:42 +03:00
|
|
|
|
2022-05-14 07:32:56 +03:00
|
|
|
scalar-literal = numeral %s"scalar"
|
|
|
|
|
2021-03-23 19:11:42 +03:00
|
|
|
boolean-literal = %s"true" / %s"false"
|
|
|
|
|
2021-08-03 03:59:13 +03:00
|
|
|
address-literal = %s"aleo1" 58( lowercase-letter / decimal-digit )
|
2021-03-23 19:11:42 +03:00
|
|
|
|
2021-05-13 04:41:58 +03:00
|
|
|
character-literal = single-quote character-literal-element single-quote
|
|
|
|
|
|
|
|
character-literal-element = not-single-quote-or-backslash
|
|
|
|
/ simple-character-escape
|
|
|
|
/ ascii-character-escape
|
|
|
|
/ unicode-character-escape
|
|
|
|
|
|
|
|
single-quote-escape = "\" single-quote ; \'
|
|
|
|
|
|
|
|
double-quote-escape = "\" double-quote ; \"
|
|
|
|
|
|
|
|
backslash-escape = "\\"
|
|
|
|
|
|
|
|
line-feed-escape = %s"\n"
|
|
|
|
|
|
|
|
carriage-return-escape = %s"\r"
|
|
|
|
|
|
|
|
horizontal-tab-escape = %s"\t"
|
|
|
|
|
|
|
|
null-character-escape = "\0"
|
|
|
|
|
|
|
|
simple-character-escape = single-quote-escape
|
|
|
|
/ double-quote-escape
|
|
|
|
/ backslash-escape
|
|
|
|
/ line-feed-escape
|
|
|
|
/ carriage-return-escape
|
|
|
|
/ horizontal-tab-escape
|
|
|
|
/ null-character-escape
|
|
|
|
|
|
|
|
ascii-character-escape = %s"\x" octal-digit hexadecimal-digit
|
|
|
|
|
|
|
|
unicode-character-escape = %s"\u{" 1*6hexadecimal-digit "}"
|
|
|
|
|
2021-07-21 00:52:35 +03:00
|
|
|
string-literal = double-quote *string-literal-element double-quote
|
2021-05-13 05:04:11 +03:00
|
|
|
|
|
|
|
string-literal-element = not-double-quote-or-backslash
|
|
|
|
/ simple-character-escape
|
|
|
|
/ ascii-character-escape
|
|
|
|
/ unicode-character-escape
|
|
|
|
|
2022-04-08 20:05:57 +03:00
|
|
|
integer-literal = unsigned-literal
|
2022-04-13 22:22:04 +03:00
|
|
|
/ signed-literal
|
2022-04-08 20:05:57 +03:00
|
|
|
|
2022-04-19 03:35:14 +03:00
|
|
|
numeric-literal = integer-literal
|
|
|
|
/ field-literal
|
|
|
|
/ product-group-literal
|
2022-05-14 07:32:56 +03:00
|
|
|
/ scalar-literal
|
2022-04-19 03:35:14 +03:00
|
|
|
|
|
|
|
atomic-literal = numeric-literal
|
2021-04-05 23:55:05 +03:00
|
|
|
/ boolean-literal
|
|
|
|
/ address-literal
|
2021-05-13 04:41:58 +03:00
|
|
|
/ character-literal
|
2021-05-13 05:04:11 +03:00
|
|
|
/ string-literal
|
2021-03-23 19:11:42 +03:00
|
|
|
|
2022-03-17 07:39:17 +03:00
|
|
|
symbol = "!" / "&&" / "||"
|
2021-03-23 19:11:42 +03:00
|
|
|
/ "==" / "!="
|
|
|
|
/ "<" / "<=" / ">" / ">="
|
|
|
|
/ "+" / "-" / "*" / "/" / "**"
|
2022-03-17 07:39:17 +03:00
|
|
|
/ "="
|
2021-03-23 19:11:42 +03:00
|
|
|
/ "(" / ")"
|
2022-04-16 05:54:41 +03:00
|
|
|
/ "[" / "]"
|
2021-03-23 19:11:42 +03:00
|
|
|
/ "{" / "}"
|
2022-03-17 07:39:17 +03:00
|
|
|
/ "," / "." / ".." / ";" / ":" / "?"
|
2021-03-24 18:40:26 +03:00
|
|
|
/ "->" / "_"
|
2021-04-05 23:55:05 +03:00
|
|
|
/ %s")group"
|
2021-03-23 19:11:42 +03:00
|
|
|
|
|
|
|
token = keyword
|
|
|
|
/ identifier
|
2021-04-05 23:55:05 +03:00
|
|
|
/ atomic-literal
|
2022-04-05 06:47:57 +03:00
|
|
|
/ numeral
|
2021-03-23 19:11:42 +03:00
|
|
|
/ symbol
|
|
|
|
|
2021-07-29 02:33:14 +03:00
|
|
|
lexeme = token / comment / whitespace
|
|
|
|
|
2021-03-23 19:11:42 +03:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
; Syntactic Grammar
|
|
|
|
; -----------------
|
|
|
|
|
|
|
|
unsigned-type = %s"u8" / %s"u16" / %s"u32" / %s"u64" / %s"u128"
|
|
|
|
|
|
|
|
signed-type = %s"i8" / %s"i16" / %s"i32" / %s"i64" / %s"i128"
|
|
|
|
|
|
|
|
integer-type = unsigned-type / signed-type
|
|
|
|
|
|
|
|
field-type = %s"field"
|
|
|
|
|
|
|
|
group-type = %s"group"
|
|
|
|
|
2022-05-14 07:32:56 +03:00
|
|
|
scalar-type = %s"scalar"
|
|
|
|
|
|
|
|
arithmetic-type = integer-type / field-type / group-type / scalar-type
|
2021-03-23 19:11:42 +03:00
|
|
|
|
|
|
|
boolean-type = %s"bool"
|
|
|
|
|
|
|
|
address-type = %s"address"
|
|
|
|
|
2021-05-13 04:22:08 +03:00
|
|
|
character-type = %s"char"
|
|
|
|
|
2022-05-12 00:09:12 +03:00
|
|
|
primitive-type = boolean-type / arithmetic-type / address-type / character-type
|
2021-03-23 19:11:42 +03:00
|
|
|
|
2022-05-12 00:09:12 +03:00
|
|
|
type = primitive-type
|
2021-04-05 23:55:05 +03:00
|
|
|
|
2022-03-17 08:42:30 +03:00
|
|
|
group-coordinate = ( [ "-" ] numeral ) / "+" / "-" / "_"
|
2021-04-05 23:55:05 +03:00
|
|
|
|
2021-04-07 02:39:07 +03:00
|
|
|
affine-group-literal = "(" group-coordinate "," group-coordinate %s")group"
|
2021-04-05 23:55:05 +03:00
|
|
|
|
|
|
|
literal = atomic-literal / affine-group-literal
|
|
|
|
|
|
|
|
group-literal = product-group-literal / affine-group-literal
|
|
|
|
|
2021-03-23 19:11:42 +03:00
|
|
|
primary-expression = identifier
|
|
|
|
/ literal
|
|
|
|
/ "(" expression ")"
|
2022-04-13 22:22:04 +03:00
|
|
|
/ function-call
|
|
|
|
|
|
|
|
function-call = identifier function-arguments
|
2021-03-23 19:11:42 +03:00
|
|
|
|
2022-03-17 07:39:17 +03:00
|
|
|
function-arguments = "(" [ expression *( "," expression ) [ "," ] ] ")"
|
2021-03-23 19:11:42 +03:00
|
|
|
|
2022-03-22 03:41:41 +03:00
|
|
|
unary-expression = primary-expression
|
2021-03-23 19:11:42 +03:00
|
|
|
/ "!" unary-expression
|
|
|
|
/ "-" unary-expression
|
|
|
|
|
2021-04-14 23:17:57 +03:00
|
|
|
exponential-expression = unary-expression
|
|
|
|
/ unary-expression "**" exponential-expression
|
2021-03-23 19:11:42 +03:00
|
|
|
|
|
|
|
multiplicative-expression = exponential-expression
|
|
|
|
/ multiplicative-expression "*" exponential-expression
|
|
|
|
/ multiplicative-expression "/" exponential-expression
|
|
|
|
|
|
|
|
additive-expression = multiplicative-expression
|
|
|
|
/ additive-expression "+" multiplicative-expression
|
|
|
|
/ additive-expression "-" multiplicative-expression
|
|
|
|
|
|
|
|
ordering-expression = additive-expression
|
|
|
|
/ additive-expression "<" additive-expression
|
|
|
|
/ additive-expression ">" additive-expression
|
|
|
|
/ additive-expression "<=" additive-expression
|
|
|
|
/ additive-expression ">=" additive-expression
|
|
|
|
|
|
|
|
equality-expression = ordering-expression
|
2021-07-01 23:40:29 +03:00
|
|
|
/ ordering-expression "==" ordering-expression
|
|
|
|
/ ordering-expression "!=" ordering-expression
|
2021-03-23 19:11:42 +03:00
|
|
|
|
|
|
|
conjunctive-expression = equality-expression
|
|
|
|
/ conjunctive-expression "&&" equality-expression
|
|
|
|
|
|
|
|
disjunctive-expression = conjunctive-expression
|
|
|
|
/ disjunctive-expression "||" conjunctive-expression
|
|
|
|
|
2022-04-15 08:26:25 +03:00
|
|
|
binary-expression = disjunctive-expression
|
|
|
|
|
|
|
|
conditional-expression = binary-expression
|
|
|
|
/ binary-expression "?" expression ":" expression
|
2021-03-23 19:11:42 +03:00
|
|
|
|
|
|
|
expression = conditional-expression
|
|
|
|
|
2022-03-30 07:20:26 +03:00
|
|
|
statement = return-statement
|
2021-04-28 19:41:42 +03:00
|
|
|
/ variable-declaration
|
|
|
|
/ constant-declaration
|
2021-03-23 19:11:42 +03:00
|
|
|
/ conditional-statement
|
|
|
|
/ loop-statement
|
|
|
|
/ assignment-statement
|
|
|
|
/ console-statement
|
|
|
|
/ block
|
|
|
|
|
|
|
|
block = "{" *statement "}"
|
|
|
|
|
2021-04-14 23:59:07 +03:00
|
|
|
return-statement = %s"return" expression ";"
|
2021-03-23 19:11:42 +03:00
|
|
|
|
2022-03-17 07:39:17 +03:00
|
|
|
variable-declaration = %s"let" identifier ":" type "=" expression ";"
|
2021-04-28 19:41:42 +03:00
|
|
|
|
2022-03-17 07:39:17 +03:00
|
|
|
constant-declaration = %s"const" identifier ":" type "=" expression ";"
|
2021-03-23 19:11:42 +03:00
|
|
|
|
|
|
|
branch = %s"if" expression block
|
|
|
|
|
|
|
|
conditional-statement = branch
|
|
|
|
/ branch %s"else" block
|
|
|
|
/ branch %s"else" conditional-statement
|
|
|
|
|
2022-03-06 10:52:34 +03:00
|
|
|
loop-statement = %s"for" identifier ":" type
|
2022-03-17 07:39:17 +03:00
|
|
|
%s"in" expression ".." expression
|
[ABNF] Improve nomenclature.
Replace 'circuit-or-alias-type' with 'identifier-or-self-type'.
This makes the nomenclature for types more clear and extensible:
- A type may be an identifier, which may be the name of a circuit type or the
name of a type alias.
- In the future, an identifier used as a type could refer to other kinds of
types that we may add, such as enumerations.
- While both 'alias type' and 'type alias' could be acceptable terms, it seems
best to standardize on 'type alias': the latter describes an alias of a type
(which is the right concept), while the former suggests a type of the "alias"
kind (cf. 'circuit type', 'field type', 'integer type', etc.). Type aliases
are not another kind of types like the other: they are aliases of (any of)
those kinds of types. So by not having 'circuit-or-alias-type' we avoid
suggesting a notion of 'alias type'.
This does not change the language described by the grammar, it merely changes
some nomenclature in the grammar. Thus, no change to the parser is
needed. Aligning the nomenclature in the abstract syntax and parser to the ABNF
would be good, but entirely optional at this point.
2021-09-03 07:54:42 +03:00
|
|
|
block
|
2021-03-23 19:11:42 +03:00
|
|
|
|
2022-03-17 07:39:17 +03:00
|
|
|
assignment-operator = "="
|
2021-03-23 19:11:42 +03:00
|
|
|
|
|
|
|
assignment-statement = expression assignment-operator expression ";"
|
|
|
|
|
2021-10-20 04:01:48 +03:00
|
|
|
console-statement = %s"console" "." console-call ";"
|
2021-03-23 19:11:42 +03:00
|
|
|
|
|
|
|
console-call = assert-call
|
|
|
|
/ print-call
|
|
|
|
|
|
|
|
assert-call = %s"assert" "(" expression ")"
|
|
|
|
|
2022-02-26 00:45:49 +03:00
|
|
|
print-function = %s"error" / %s"log"
|
2021-03-23 19:11:42 +03:00
|
|
|
|
2022-03-17 07:39:17 +03:00
|
|
|
print-arguments = "(" string-literal *( "," expression ) [ "," ] ")"
|
2021-03-23 19:11:42 +03:00
|
|
|
|
|
|
|
print-call = print-function print-arguments
|
|
|
|
|
2022-03-17 07:39:17 +03:00
|
|
|
function-declaration = %s"function" identifier
|
2022-03-28 22:26:36 +03:00
|
|
|
"(" [ function-parameters ] ")" "->" type
|
2021-03-23 19:11:42 +03:00
|
|
|
block
|
|
|
|
|
2022-03-17 07:39:17 +03:00
|
|
|
function-parameters = function-parameter *( "," function-parameter ) [ "," ]
|
|
|
|
|
2022-04-30 08:01:54 +03:00
|
|
|
function-parameter = [ %s"public" / %s"constant" / %s"const" ]
|
|
|
|
identifier ":" type
|
2022-03-17 07:39:17 +03:00
|
|
|
|
|
|
|
declaration = function-declaration
|
2021-03-23 19:11:42 +03:00
|
|
|
|
|
|
|
file = *declaration
|
2021-04-21 01:46:48 +03:00
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2022-03-17 07:39:17 +03:00
|
|
|
; Format String Grammar
|
|
|
|
; ---------------------
|
|
|
|
|
2022-04-30 07:58:34 +03:00
|
|
|
not-brace = %x0-7A / %x7C / %x7E-10FFFF ; anything but { or }
|
2022-03-17 07:39:17 +03:00
|
|
|
|
|
|
|
format-string-container = "{}"
|
|
|
|
|
|
|
|
format-string-open-brace = "{{"
|
|
|
|
|
|
|
|
format-string-close-brace = "}}"
|
|
|
|
|
|
|
|
format-string-element = not-brace
|
2022-03-17 08:42:30 +03:00
|
|
|
/ format-string-container
|
|
|
|
/ format-string-open-brace
|
|
|
|
/ format-string-close-brace
|
2022-03-17 07:39:17 +03:00
|
|
|
|
|
|
|
format-string = *format-string-element
|
2022-04-16 05:54:41 +03:00
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
; Input Grammar
|
|
|
|
; -------------
|
|
|
|
|
|
|
|
input-type = type
|
|
|
|
|
|
|
|
input-expression = literal
|
|
|
|
|
|
|
|
input-item = identifier ":" input-type "=" input-expression ";"
|
|
|
|
|
2022-05-21 07:58:51 +03:00
|
|
|
input-title = "[" ( %s"public" / %s"private" / %s"constant" / %s"const" ) "]"
|
2022-04-16 05:54:41 +03:00
|
|
|
|
|
|
|
input-section = input-title *input-item
|
|
|
|
|
|
|
|
input-file = *input-section
|