diff --git a/README.md b/README.md index 6d0a7f321b..8f0dcf13ee 100644 --- a/README.md +++ b/README.md @@ -95,9 +95,9 @@ This will generate an executable under the `./target/release` directory. To run Use the Leo CLI to create a new project ```bash -# create a new `hello_world` Leo project -leo new hello_world -cd hello_world +# create a new `hello-world` Leo project +leo new hello-world +cd hello-world # build & setup & prove & verify leo run @@ -113,6 +113,7 @@ Congratulations! You've just run your first Leo program. * [Hello World - Next Steps](https://developer.aleo.org/developer/getting_started/hello_world) * [Leo Language Documentation](https://developer.aleo.org/developer/language/layout) +* [Leo ABNF Grammar](./grammar/README.md) * [Leo CLI Documentation](https://developer.aleo.org/developer/cli/new) * [Homepage](https://developer.aleo.org/developer/getting_started/overview) diff --git a/grammar/README.md b/grammar/README.md index 3a970eeafb..b62717d368 100644 --- a/grammar/README.md +++ b/grammar/README.md @@ -1,30 +1,18 @@ -Leo Library +Copyright (C) 2019-2021 Aleo Systems Inc. +This file is part of the Leo library. +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. +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. -Copyright (C) 2021 Aleo Systems Inc. - - --------- - - -Format Note ------------ - -The ABNF standard requires grammars to consist of lines terminated by CR LF -(i.e. carriage return followed by line feed, DOS/Windows-style), -as explained in the background on ABNF later in this file. -This file's lines are therefore terminated by CR LF. -To avoid losing this requirement across systems, -this file is marked as 'text eol=crlf' in .gitattributes: -this means that the file is textual, enabling visual diffs, -but its lines will always be terminated by CR LF on any system. - -Note that this CR LF requirement only applies to the grammar files themselves. -It does not apply to the lines of the languages described by the grammar. -ABNF grammars may describe any kind of languages, -with any kind of line terminators, -or even without line terminators at all (e.g. for "binary" languages). +You should have received a copy of the GNU General Public License +along with the Leo library. If not, see . -------- @@ -465,7 +453,7 @@ described above. newline = line-feed / carriage-return / carriage-return line-feed ``` -Go to: _[line-feed](#user-content-line-feed), [carriage-return](#user-content-carriage-return)_; +Go to: _[carriage-return](#user-content-carriage-return), [line-feed](#user-content-line-feed)_; Line terminators form whitespace, along with spaces and horizontal tabs. @@ -475,7 +463,7 @@ Line terminators form whitespace, along with spaces and horizontal tabs. whitespace = space / horizontal-tab / newline ``` -Go to: _[newline](#user-content-newline), [space](#user-content-space), [horizontal-tab](#user-content-horizontal-tab)_; +Go to: _[space](#user-content-space), [horizontal-tab](#user-content-horizontal-tab), [newline](#user-content-newline)_; There are two kinds of comments in Leo, as in other languages. @@ -493,7 +481,7 @@ the ones used in the Java language reference. comment = block-comment / end-of-line-comment ``` -Go to: _[end-of-line-comment](#user-content-end-of-line-comment), [block-comment](#user-content-block-comment)_; +Go to: _[block-comment](#user-content-block-comment), [end-of-line-comment](#user-content-end-of-line-comment)_; @@ -510,7 +498,7 @@ rest-of-block-comment = "*" rest-of-block-comment-after-star / not-star rest-of-block-comment ``` -Go to: _[not-star](#user-content-not-star), [rest-of-block-comment-after-star](#user-content-rest-of-block-comment-after-star), [rest-of-block-comment](#user-content-rest-of-block-comment)_; +Go to: _[rest-of-block-comment-after-star](#user-content-rest-of-block-comment-after-star), [not-star](#user-content-not-star), [rest-of-block-comment](#user-content-rest-of-block-comment)_; @@ -520,7 +508,7 @@ rest-of-block-comment-after-star = "/" / not-star-or-slash rest-of-block-comment ``` -Go to: _[rest-of-block-comment-after-star](#user-content-rest-of-block-comment-after-star), [not-star-or-slash](#user-content-not-star-or-slash), [rest-of-block-comment](#user-content-rest-of-block-comment)_; +Go to: _[rest-of-block-comment](#user-content-rest-of-block-comment), [not-star-or-slash](#user-content-not-star-or-slash), [rest-of-block-comment-after-star](#user-content-rest-of-block-comment-after-star)_; @@ -653,7 +641,7 @@ format-string-element = not-double-quote-or-open-brace / format-string-container ``` -Go to: _[not-double-quote-or-open-brace](#user-content-not-double-quote-or-open-brace), [format-string-container](#user-content-format-string-container), [not-double-quote-or-close-brace](#user-content-not-double-quote-or-close-brace)_; +Go to: _[not-double-quote-or-open-brace](#user-content-not-double-quote-or-open-brace), [not-double-quote-or-close-brace](#user-content-not-double-quote-or-close-brace), [format-string-container](#user-content-format-string-container)_; @@ -814,7 +802,7 @@ atomic-literal = untyped-literal / address-literal ``` -Go to: _[product-group-literal](#user-content-product-group-literal), [untyped-literal](#user-content-untyped-literal), [signed-literal](#user-content-signed-literal), [field-literal](#user-content-field-literal), [boolean-literal](#user-content-boolean-literal), [address-literal](#user-content-address-literal), [unsigned-literal](#user-content-unsigned-literal)_; +Go to: _[unsigned-literal](#user-content-unsigned-literal), [field-literal](#user-content-field-literal), [product-group-literal](#user-content-product-group-literal), [address-literal](#user-content-address-literal), [signed-literal](#user-content-signed-literal), [untyped-literal](#user-content-untyped-literal), [boolean-literal](#user-content-boolean-literal)_; After defining the (mostly) alphanumeric tokens above, @@ -887,7 +875,7 @@ token = keyword / symbol ``` -Go to: _[package-name](#user-content-package-name), [annotation-name](#user-content-annotation-name), [atomic-literal](#user-content-atomic-literal), [format-string](#user-content-format-string), [keyword](#user-content-keyword), [symbol](#user-content-symbol), [identifier](#user-content-identifier)_; +Go to: _[format-string](#user-content-format-string), [annotation-name](#user-content-annotation-name), [symbol](#user-content-symbol), [keyword](#user-content-keyword), [atomic-literal](#user-content-atomic-literal), [identifier](#user-content-identifier), [package-name](#user-content-package-name)_; @@ -923,7 +911,7 @@ signed-type = %s"i8" / %s"i16" / %s"i32" / %s"i64" / %s"i128" integer-type = unsigned-type / signed-type ``` -Go to: _[unsigned-type](#user-content-unsigned-type), [signed-type](#user-content-signed-type)_; +Go to: _[signed-type](#user-content-signed-type), [unsigned-type](#user-content-unsigned-type)_; The integer types, along with the field and group types, @@ -944,7 +932,7 @@ group-type = %s"group" arithmetic-type = integer-type / field-type / group-type ``` -Go to: _[integer-type](#user-content-integer-type), [field-type](#user-content-field-type), [group-type](#user-content-group-type)_; +Go to: _[group-type](#user-content-group-type), [field-type](#user-content-field-type), [integer-type](#user-content-integer-type)_; The arithmetic types, along with the boolean and address types, @@ -965,7 +953,7 @@ address-type = %s"address" scalar-type = boolean-type / arithmetic-type / address-type ``` -Go to: _[address-type](#user-content-address-type), [boolean-type](#user-content-boolean-type), [arithmetic-type](#user-content-arithmetic-type)_; +Go to: _[arithmetic-type](#user-content-arithmetic-type), [address-type](#user-content-address-type), [boolean-type](#user-content-boolean-type)_; Circuit types are denoted by identifiers and the keyword 'Self'. @@ -982,7 +970,7 @@ self-type = %s"Self" circuit-type = identifier / self-type ``` -Go to: _[self-type](#user-content-self-type), [identifier](#user-content-identifier)_; +Go to: _[identifier](#user-content-identifier), [self-type](#user-content-self-type)_; A tuple type consists of zero, two, or more component types. @@ -1005,7 +993,7 @@ or a tuple of one or more dimensions. array-type = "[" type ";" array-dimensions "]" ``` -Go to: _[array-dimensions](#user-content-array-dimensions), [type](#user-content-type)_; +Go to: _[type](#user-content-type), [array-dimensions](#user-content-array-dimensions)_; @@ -1114,7 +1102,7 @@ primary-expression = identifier / circuit-expression ``` -Go to: _[identifier](#user-content-identifier), [literal](#user-content-literal), [array-expression](#user-content-array-expression), [expression](#user-content-expression), [tuple-expression](#user-content-tuple-expression), [circuit-expression](#user-content-circuit-expression)_; +Go to: _[literal](#user-content-literal), [array-expression](#user-content-array-expression), [tuple-expression](#user-content-tuple-expression), [identifier](#user-content-identifier), [expression](#user-content-expression), [circuit-expression](#user-content-circuit-expression)_; Tuple expressions construct tuples. @@ -1167,7 +1155,7 @@ Go to: _[expression](#user-content-expression)_; array-repeat-construction = "[" expression ";" array-dimensions "]" ``` -Go to: _[expression](#user-content-expression), [array-dimensions](#user-content-array-dimensions)_; +Go to: _[array-dimensions](#user-content-array-dimensions), [expression](#user-content-expression)_; @@ -1175,7 +1163,7 @@ Go to: _[expression](#user-content-expression), [array-dimensions](#user-content array-construction = array-inline-construction / array-repeat-construction ``` -Go to: _[array-repeat-construction](#user-content-array-repeat-construction), [array-inline-construction](#user-content-array-inline-construction)_; +Go to: _[array-inline-construction](#user-content-array-inline-construction), [array-repeat-construction](#user-content-array-repeat-construction)_; @@ -1261,7 +1249,7 @@ postfix-expression = primary-expression / postfix-expression "[" [expression] ".." [expression] "]" ``` -Go to: _[circuit-type](#user-content-circuit-type), [natural](#user-content-natural), [postfix-expression](#user-content-postfix-expression), [primary-expression](#user-content-primary-expression), [identifier](#user-content-identifier), [function-arguments](#user-content-function-arguments), [expression](#user-content-expression)_; +Go to: _[primary-expression](#user-content-primary-expression), [expression](#user-content-expression), [postfix-expression](#user-content-postfix-expression), [natural](#user-content-natural), [identifier](#user-content-identifier), [function-arguments](#user-content-function-arguments), [circuit-type](#user-content-circuit-type)_; Unary operators have the highest operator precedence. @@ -1275,7 +1263,7 @@ unary-expression = postfix-expression / "-" unary-expression ``` -Go to: _[postfix-expression](#user-content-postfix-expression), [unary-expression](#user-content-unary-expression)_; +Go to: _[unary-expression](#user-content-unary-expression), [postfix-expression](#user-content-postfix-expression)_; Next in the operator precedence is exponentiation, @@ -1289,7 +1277,7 @@ exponential-expression = unary-expression / unary-expression "**" exponential-expression ``` -Go to: _[unary-expression](#user-content-unary-expression), [exponential-expression](#user-content-exponential-expression)_; +Go to: _[exponential-expression](#user-content-exponential-expression), [unary-expression](#user-content-unary-expression)_; Next in precedence come multiplication and division, both left-associative. @@ -1341,7 +1329,7 @@ equality-expression = ordering-expression / equality-expression "!=" ordering-expression ``` -Go to: _[equality-expression](#user-content-equality-expression), [ordering-expression](#user-content-ordering-expression)_; +Go to: _[ordering-expression](#user-content-ordering-expression), [equality-expression](#user-content-equality-expression)_; Next come conjunctive expressions, left-associative. @@ -1352,7 +1340,7 @@ conjunctive-expression = equality-expression / conjunctive-expression "&&" equality-expression ``` -Go to: _[equality-expression](#user-content-equality-expression), [conjunctive-expression](#user-content-conjunctive-expression)_; +Go to: _[conjunctive-expression](#user-content-conjunctive-expression), [equality-expression](#user-content-equality-expression)_; Next come disjunctive expressions, left-associative. @@ -1376,7 +1364,7 @@ conditional-expression = disjunctive-expression ":" conditional-expression ``` -Go to: _[conditional-expression](#user-content-conditional-expression), [expression](#user-content-expression), [disjunctive-expression](#user-content-disjunctive-expression)_; +Go to: _[disjunctive-expression](#user-content-disjunctive-expression), [conditional-expression](#user-content-conditional-expression), [expression](#user-content-expression)_; Those above are all the expressions. @@ -1408,7 +1396,7 @@ statement = expression-statement / block ``` -Go to: _[return-statement](#user-content-return-statement), [variable-definition-statement](#user-content-variable-definition-statement), [assignment-statement](#user-content-assignment-statement), [console-statement](#user-content-console-statement), [expression-statement](#user-content-expression-statement), [loop-statement](#user-content-loop-statement), [conditional-statement](#user-content-conditional-statement), [block](#user-content-block)_; +Go to: _[assignment-statement](#user-content-assignment-statement), [block](#user-content-block), [variable-definition-statement](#user-content-variable-definition-statement), [return-statement](#user-content-return-statement), [loop-statement](#user-content-loop-statement), [console-statement](#user-content-console-statement), [conditional-statement](#user-content-conditional-statement), [expression-statement](#user-content-expression-statement)_; @@ -1451,7 +1439,7 @@ variable-definition-statement = ( %s"let" / %s"const" ) [ ":" type ] "=" expression ";" ``` -Go to: _[type](#user-content-type), [identifier-or-identifiers](#user-content-identifier-or-identifiers), [expression](#user-content-expression)_; +Go to: _[identifier-or-identifiers](#user-content-identifier-or-identifiers), [expression](#user-content-expression), [type](#user-content-type)_; @@ -1496,7 +1484,7 @@ The body is a block. loop-statement = %s"for" identifier %s"in" expression ".." expression block ``` -Go to: _[identifier](#user-content-identifier), [expression](#user-content-expression), [block](#user-content-block)_; +Go to: _[block](#user-content-block), [identifier](#user-content-identifier), [expression](#user-content-expression)_; An assignment statement is straightforward. @@ -1513,7 +1501,7 @@ assignment-operator = "=" / "+=" / "-=" / "*=" / "/=" / "**=" assignment-statement = expression assignment-operator expression ";" ``` -Go to: _[assignment-operator](#user-content-assignment-operator), [expression](#user-content-expression)_; +Go to: _[expression](#user-content-expression), [assignment-operator](#user-content-assignment-operator)_; Console statements start with the 'console' keyword, @@ -1600,7 +1588,7 @@ function-declaration = *annotation %s"function" identifier block ``` -Go to: _[function-parameters](#user-content-function-parameters), [block](#user-content-block), [type](#user-content-type), [identifier](#user-content-identifier)_; +Go to: _[block](#user-content-block), [function-parameters](#user-content-function-parameters), [identifier](#user-content-identifier), [type](#user-content-type)_; @@ -1648,7 +1636,7 @@ member-declaration = member-variable-declaration / member-function-declaration ``` -Go to: _[member-variable-declaration](#user-content-member-variable-declaration), [member-function-declaration](#user-content-member-function-declaration)_; +Go to: _[member-function-declaration](#user-content-member-function-declaration), [member-variable-declaration](#user-content-member-variable-declaration)_; @@ -1656,7 +1644,7 @@ Go to: _[member-variable-declaration](#user-content-member-variable-declaration) member-variable-declaration = identifier ":" type ``` -Go to: _[identifier](#user-content-identifier), [type](#user-content-type)_; +Go to: _[type](#user-content-type), [identifier](#user-content-identifier)_; @@ -1676,7 +1664,7 @@ circuit-declaration = *annotation %s"circuit" identifier "{" member-declaration *( "," member-declaration ) "}" ``` -Go to: _[member-declaration](#user-content-member-declaration), [identifier](#user-content-identifier)_; +Go to: _[identifier](#user-content-identifier), [member-declaration](#user-content-member-declaration)_; An import declaration consists of the 'import' keyword @@ -1705,7 +1693,7 @@ package-path = "*" / "(" package-path *( "," package-path ) [","] ")" ``` -Go to: _[package-path](#user-content-package-path), [identifier](#user-content-identifier), [package-name](#user-content-package-name)_; +Go to: _[package-path](#user-content-package-path), [package-name](#user-content-package-name), [identifier](#user-content-identifier)_; Finally, we define a file as a sequence of zero or more declarations. @@ -1717,10 +1705,33 @@ declaration = import-declaration / circuit-declaration ``` -Go to: _[import-declaration](#user-content-import-declaration), [circuit-declaration](#user-content-circuit-declaration), [function-declaration](#user-content-function-declaration)_; +Go to: _[import-declaration](#user-content-import-declaration), [function-declaration](#user-content-function-declaration), [circuit-declaration](#user-content-circuit-declaration)_; ```abnf file = *declaration +``` + + +-------- + + +Format Note +----------- + +The ABNF standard requires grammars to consist of lines terminated by CR LF +(i.e. carriage return followed by line feed, DOS/Windows-style), +as explained in the background on ABNF earlier in this file. +This file's lines are therefore terminated by CR LF. +To avoid losing this requirement across systems, +this file is marked as 'text eol=crlf' in .gitattributes: +this means that the file is textual, enabling visual diffs, +but its lines will always be terminated by CR LF on any system. + +Note that this CR LF requirement only applies to the grammar files themselves. +It does not apply to the lines of the languages described by the grammar. +ABNF grammars may describe any kind of languages, +with any kind of line terminators, +or even without line terminators at all (e.g. for "binary" languages). diff --git a/grammar/abnf-grammar.txt b/grammar/abnf-grammar.txt index 8879db4002..8adbaee5ce 100644 --- a/grammar/abnf-grammar.txt +++ b/grammar/abnf-grammar.txt @@ -1,26 +1,18 @@ -; Leo Library -; -; Copyright (C) 2021 Aleo Systems Inc. +; Copyright (C) 2019-2021 Aleo Systems Inc. +; This file is part of the Leo library. -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; 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. -; Format Note -; ----------- +; 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. -; The ABNF standard requires grammars to consist of lines terminated by CR LF -; (i.e. carriage return followed by line feed, DOS/Windows-style), -; as explained in the background on ABNF later in this file. -; This file's lines are therefore terminated by CR LF. -; To avoid losing this requirement across systems, -; this file is marked as 'text eol=crlf' in .gitattributes: -; this means that the file is textual, enabling visual diffs, -; but its lines will always be terminated by CR LF on any system. - -; Note that this CR LF requirement only applies to the grammar files themselves. -; It does not apply to the lines of the languages described by the grammar. -; ABNF grammars may describe any kind of languages, -; with any kind of line terminators, -; or even without line terminators at all (e.g. for "binary" languages). +; You should have received a copy of the GNU General Public License +; along with the Leo library. If not, see . ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -1021,3 +1013,23 @@ declaration = import-declaration / circuit-declaration file = *declaration + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +; Format Note +; ----------- + +; The ABNF standard requires grammars to consist of lines terminated by CR LF +; (i.e. carriage return followed by line feed, DOS/Windows-style), +; as explained in the background on ABNF earlier in this file. +; This file's lines are therefore terminated by CR LF. +; To avoid losing this requirement across systems, +; this file is marked as 'text eol=crlf' in .gitattributes: +; this means that the file is textual, enabling visual diffs, +; but its lines will always be terminated by CR LF on any system. + +; Note that this CR LF requirement only applies to the grammar files themselves. +; It does not apply to the lines of the languages described by the grammar. +; ABNF grammars may describe any kind of languages, +; with any kind of line terminators, +; or even without line terminators at all (e.g. for "binary" languages).