Commit Graph

327 Commits

Author SHA1 Message Date
Alessandro Coglio
02ad2a390d [ABNF] Fix typo in rule that excludes bidi chars.
The 2070 should have been 206A all along.
2022-08-29 12:44:34 -07:00
Alessandro Coglio
460a46f115 [ABNF] Add mappings.
As discussed on Notion and Slack.
2022-08-27 16:58:19 -07:00
d0cd
297128af6d
Merge pull request #2024 from AleoHQ/abnf-console
[ABNF] Revise console statements.
2022-08-18 16:28:29 -07:00
Pranav Gaddamadugu
eb4ee1428c Cleanup out dated docs 2022-08-18 15:45:30 -07:00
Alessandro Coglio
eab2e4466d [ABNF] Revise console statements.
Add `console.assert_eq` and `console.assert_neq`.

Remove `console.log` and `console.error`.

Remove the format string grammar, since it was only used for console print
calls, which have been removed.

This matches #2023.
2022-08-17 21:45:40 -07:00
Alessandro Coglio
ce2d8f8a51 [ABNF] Add annotations.
This is to match the recent introduction of the `@program` annotation for
external functions (i.e. functions that may be called externally, passing to
them inputs through the input files).

This PR adds not just that annotation, but a more general notion of annotation
as a new kind of token of the form `@<identifier>`, and with the ability to
precede each function declaration with zero or more such annotations.

The fact that it has been added as a token to the lexical grammar, means that
there cannot be any whitespace or comments between the `@` and the identifier.
If that is undesired, we can add it to the syntactic grammar instead, defining
an annotation as consisting of the (new) symbol token `@` followed by an
identifier token.

We can of course extend annotations with arguments at some point, if needed.
2022-08-09 20:45:54 -07:00
collin
5f0a6573a5 Merge branch 'testnet3' of github.com:AleoHQ/leo into remove-unsafe 2022-08-05 11:52:09 -07:00
Alessandro Coglio
79bef6627a [ABNF] Add compound assignments. 2022-08-04 21:01:05 -07:00
Mazdak Farrokhzad
a77d3b4092 forbid unsafe_code in all crates 2022-08-05 00:36:41 +02:00
d0cd
140c2b31ad
Create operators.md 2022-08-03 12:04:39 -07:00
Alessandro Coglio
f5b62e913b [ABNF] Add the remainder operator. 2022-07-28 14:25:01 -07:00
d0cd
9bd4db47fb
Merge pull request #1962 from AleoHQ/grammar-add-record-name-and-inner-rule
[grammar] add missing record name identifier; factor circuit-componen…
2022-07-24 21:53:24 -07:00
Eric McCarthy
9756714fd2 [grammar] add missing record name identifier; factor circuit-component-declarations into separate grammar rule 2022-07-23 23:32:17 -07:00
Alessandro Coglio
949aac14db [ABNF] Generalize input type. 2022-07-23 21:05:19 -07:00
d0cd
2a9cc42493
Merge pull request #1950 from AleoHQ/remove-unused-errors
Remove unused errors
2022-07-23 10:28:04 -07:00
Alessandro Coglio
ba6c239964 [ABNF] Add inclusive loop bound.
This is now part of the Leo compiler, so we need to update the grammar
accordingly.
2022-07-21 13:35:39 -07:00
Alessandro Coglio
f93ed1b15f [ABNF] Fix rule for circuit declarations.
The identifier had been neglected.
2022-07-20 18:36:23 -07:00
Mazdak Farrokhzad
db42194d49 remove unused errors 2022-07-20 20:19:00 +02:00
collin
1e5142a8a2 prepare for testnet3 as repo branch 2022-07-18 18:28:23 -07:00
Alessandro Coglio
97d26a879a [ABNF] Actually exclude 1-tuples.
Thanks to @bendyarm for noticing and reporting this.
2022-07-11 21:38:05 +02:00
Alessandro Coglio
9c3d2e0941 [ABNF] Add tuples.
This adds tuple types, tuple expressions (which build tuples from components),
and tuple component expressions (which access tuple components).

Based on previous discussions on this topic, 1-tuples are excluded. This
exclusion is done at the grammar level, since it is the kind of requirement that
is easily captured in a context-free grammar.
2022-07-10 18:28:31 +02:00
Alessandro Coglio
6bfe530922 [ABNF] Improve some rule names.
Based on a recent discussion on Slack, and on some related slight terminological
changes in the documentation of the Aleo instructions, this commit similarly
improves the Leo nomenclature for expressions involving the logical operators.

The attribute 'bitwise' for `&` and `|` and `^` has been dropped, since the
operations also operate on booleans besides integers.

Given that the operation and method names `or` and `xor` for inclusive and
exclusive disjunctions (as opposed to `ior` and `xor`), the unqualified
'disjunction' now refers to the inclusive one.

The non-strict `&&` and `||` are now called 'conditional' (as done in other
languages), and thus the ternary one has been expanded to 'conditional ternary'.

This does not change the Leo language; it just improves the nomenclature derived
from the grammar.
2022-07-04 15:45:11 -07:00
Alessandro Coglio
884d46abe4 [ABNF] Revert previous accidentally pushed commit. 2022-07-04 15:36:43 -07:00
Alessandro Coglio
c35b977207 [ABNF] Improve some rule names.
Based on a recent discussion on Slack, and on some related slight terminological
changes in the documentation of the Aleo instructions, this commit similarly
improves the Leo nomenclature for expressions involving the logical operators.

The attribute 'bitwise' for `&` and `|` and `^` has been dropped, since the
operations also operate on booleans besides integers.

Given that the operation and method names `or` and `xor` for inclusive and
exclusive disjunctions (as opposed to `ior` and `xor`), the unqualified
'disjunction' now refers to the inclusive one.

The non-strict `&&` and `||` are now called 'conditional' (as done in other
languages), and thus the ternary one has been expanded to 'conditional ternary'.

This does not change the Leo language; it just improves the nomenclature derived
from the grammar.
2022-07-04 15:26:10 -07:00
Eric McCarthy
71bd874b69 [abnf grammar] fix a few typos 2022-07-02 22:34:50 -07:00
collin
0a4069fe39 merge testnet3 2022-07-02 14:08:02 -07:00
Collin Chin
9e2641b321
Merge pull request #1885 from AleoHQ/core-circuits
Core circuits
2022-06-27 09:08:26 -10:00
Alessandro Coglio
557cdf15c3 [ABNF] Add syntax for record types. 2022-06-27 11:26:34 -07:00
Alessandro Coglio
f8f944da39 [ABNF] Add forgotten symbols.
These are for the recently added shift and bitwise logical operators. They
should have been also included in the rule `symbol` for symbol tokens. This
commit remedies that.
2022-06-25 15:24:53 -07:00
Alessandro Coglio
93e9686972 [ABNF] Prohibit empty circuits.
These would flatten to nothing, component-wise.

This requirement actually slighly simplifies the grammar, avoiding the `[ ... ]`
around the circuit component declarations (in a circuit declaration) or the
circuit component initializers (in a circuit expression).
2022-06-23 21:13:24 -07:00
Alessandro Coglio
35485bea25 [ABNF] Add circuits and add associated constants. 2022-06-23 15:06:39 -07:00
Alessandro Coglio
abc50d8c3e [ABNF] Add syntax for static function calls.
Also renames pre-existing (generic) function calls to 'free function calls', now
that we are effectively introducing a new kind of functions, namely (associated)
static functions, distinguished from free (i.e. non-associated) functions.

Also introduces notion of named type, as a type that has a name, which may be
either a keyword (e.g. `u8`, `address`) or an identifier (e.g. `Pedersen64`).
2022-06-20 13:46:43 -07:00
Collin Chin
1971dd0aa1
Merge pull request #1880 from AleoHQ/abnf-new-operators
[ABNF] Add new operators.
2022-06-20 12:24:12 -07:00
Collin Chin
6b064d0227
Merge pull request #1873 from AleoHQ/abnf-operator-calls
[ABNF] Add operator calls.
2022-06-20 12:23:46 -07:00
Alessandro Coglio
5539ce11a6 [ABNF] Improve the grammar for operator calls.
Introduce the notion of postfix expression in the grammar, which will also go
well with some expected upcoming extensions to Leo.

This does not change the Leo language. It does not necessarily involve modifying
the parser. It merely reorganizes some rules slightly.
2022-06-18 15:45:33 -07:00
Alessandro Coglio
5f5124d2d0 [ABNF] Fix overlooked update.
Thanks to @gluax for reporting the issue.
2022-06-16 15:18:59 -07:00
Alessandro Coglio
64307d075c [ABNF] Add new operators.
This adds shift (`<<` `>>`) and bitwise logical (`&` `|` `^`) operators.

Their precedence is between the additive and ordering operations, in this order
(higher to lower):
- ... others, to additive
- `<<` and `>>`
- `&`
- `|`
- `^`
- ... others, from ordering

This is consistent with Rust, but not with C and Java, both of which make the
bitwise logical operators lower-precedence than equalities.

The previous ABNF rule names for `conjunctive-expression` and
`disjunctive-expression` have been renamed to be more consistent with the newly
added ones. Also, the rule names "abbreviate" 'conjunctive' and 'disjunctive'
with 'and' and 'or', otherwise the names were a bit too long.
2022-06-16 14:02:22 -07:00
Alessandro Coglio
846c976c63 [ABNF] Add operator calls.
Since these are a method-like syntax for unary and binary operators (as in fact
these are represented as operators in the AST), the nomenclature 'operator call'
seems appropriate, at least for now. There is no need yet to introduce notions
of associated functions (and constants).

The rules explicitly distinguish between unary and binary ones, corresponding to
unary and binary operators. This lets us exclude right away calls with too many
arguments, and gives us a way to distinguish the two kinds.

A trailing comma is allowed at the end of the one argument of binary operator
calls, if one is really inclined to use it, just for syntactic consistency with
other calls (namely, function calls).
2022-06-13 13:24:05 -07:00
Alessandro Coglio
894e0af225 [ABNF] Fix/improve handling of line terminators.
Prohibit line terminators inside string literals. (This does not prohibit
escapes for line feed and/or carriage return; it prohibits actual line feeds and
carriage returns, which would break the string literal across lines.)

Explicate line terminators in block comments, so that an accurate line count can
be obtained more readily from the CSTs. (This is more relevant to the ACL2
formal development than to the Rust implementation, which does not have explicit
CSTs.)

Also reorder slightly some rules within the file.
2022-06-11 15:56:49 -07:00
gluax
540fdccffe Update abnf, and give docs over parser keywords 2022-06-09 12:45:52 -07:00
gluax
f6990e75fc fixed some bugs 2022-06-08 06:46:54 -07:00
Collin Chin
2429b72312
Merge pull request #1856 from AleoHQ/abnf-string-type
[ABNF] Add string type.
2022-06-02 12:46:56 -04:00
Collin Chin
53e5dfbb02
Merge pull request #1853 from AleoHQ/abnf-in-out-exprs
[ABNF] Relax input and output expressions.
2022-06-02 11:45:50 -04:00
Alessandro Coglio
354974726c [ABNF] Add string type. 2022-06-01 20:39:27 -07:00
gluax
f34f63cea4 update abnf 2022-06-01 08:48:36 -07:00
Alessandro Coglio
9e1dad2b2a [ABNF] Relax input and output expressions.
In input and output files, literals are actually insufficient to represent the
most negative values of the signed integer types.

Given that we are likely to need richer forms of input and output expressions
anyways, at this point it seems best to allow any expression at the grammatical
level, and add static semantic requirements on the allowed expressions. As done
with all the other requirements, these will be stated in the Leo Reference,
formalized in ACL2, and enforced in the Leo compiler.
2022-05-31 19:20:11 -07:00
Alessandro Coglio
66e84ba689 [ABNF] Minor README fixes and improvements. 2022-05-28 18:47:27 -07:00
Alessandro Coglio
2cdcdb479d [ABNF] Simplify .gitattribute file.
No need to reference a file that's no longer here.
2022-05-28 18:35:03 -07:00
Alessandro Coglio
b16f9ae31e [ABNF] Remove unused rule.
Since character literals were removed, the rule `not-single-quote-or-backslash`
is no longer needed.
2022-05-28 18:31:02 -07:00
gluax
2117ee3ae8 resolve readme conflict 2022-05-25 11:55:23 -07:00
Collin Chin
c4b15ec17b
Merge pull request #1836 from AleoHQ/abnf-output-grammar
[ABNF] Add initial output grammar.
2022-05-25 14:49:36 -04:00
collin
dc08403899 remove readme 2022-05-25 14:40:06 -04:00
collin
8d79193474 merge testnet3 2022-05-25 14:02:10 -04:00
gluax
936360793c slight clean up & handle grammar readme 2022-05-25 10:45:25 -07:00
gluax
c9612625d1 regenerate readme after pulling upstream 2022-05-25 09:24:02 -07:00
gluax
a0abb01abd regenerate readme 2022-05-25 09:22:32 -07:00
gluax
8cb4b19e66 merge upstream changes 2022-05-25 09:21:47 -07:00
Alessandro Coglio
b26ed8e2ef [ABNF] Add initial output grammar.
This is for the current simplified version of Leo. When the main function is
executed, it returns a value. According to this grammar, the output (i.e.
`.out`) file contains a single literal, which describes the output value,
preceded by an `[output]` title. This may be extended in the future.
2022-05-24 23:05:14 -07:00
collin
3979061632 merge testnet3 2022-05-24 12:52:19 -04:00
Mazdak Farrokhzad
0883126fef char removal: update ABNF + adjust examples 2022-05-24 15:51:58 +02:00
Alessandro Coglio
09001004d4 [ABNF] Refine the rule for input titles.
Since we only allow four kinds of input section titles, corresponding to the
public/private/constant/const characterization of function inputs, it seems
beneficial to put this into the grammar, where it is easily captured.

Note that the previous version of the rule, which uses `identifier`, is not
quite right, because, for example, `public` is not an identiifer (it is a
keyword). So the rule would have to be modified anyways.
2022-05-20 21:58:51 -07:00
Alessandro Coglio
a9564552a9 [ABNF] Add scalar type. 2022-05-13 21:32:56 -07:00
collin
8f17d6294a rename scalar -> primitive 2022-05-11 14:09:12 -07:00
gluax
039a71359c merge upstream testnet3, update grammar readme 2022-05-03 15:20:45 -07:00
Alessandro Coglio
db823bf34d [ABNF] Keep file to 80 columns. 2022-04-29 22:01:54 -07:00
Alessandro Coglio
8b5c10a61f [ABNF] Improve doc comment.
Given that the Leo Reference explains well that the format string grammar
applies to the character sequence after processing escapes, we do not need to
say this here. Instead, we just explain the rule similarly to what we do for
others.
2022-04-29 21:58:34 -07:00
gluax
124e6b2e9b
[Impl] Ast Visitor (#1769)
* visitor pattern

* merge upstream, regen grammar readme

* rename reducer to passes

* update comments to properly reflect visitor

* fmt and clippy fixes

* fix comments

Co-authored-by: collin <16715212+collinc97@users.noreply.github.com>
2022-04-22 16:05:50 -07:00
Alessandro Coglio
a8c674a881 [ABNF] Improve doc comment about bidi exclusions.
This mentions embeddings and isolates besides overrides, in accordance with the
official terminology at https://www.unicode.org/reports/tr9/.

This update was discussed and agreed with @bendyarm.

Note: The Leo Reference includes text explaining these exclusions, with links to
the document above as well to the web site and paper about Trojan source
exploits.
2022-04-21 20:02:25 -07:00
Collin Chin
23fca6af47
Merge pull request #1751 from AleoHQ/abnf-bidi-overrides
[ABNF] disallow bidi override codepoints
2022-04-20 09:34:00 -07:00
Eric McCarthy
0611ddd94f [ABNF] fix merge of #1759 2022-04-19 13:34:56 -07:00
Eric McCarthy
3f9a51041f [ABNF] merge #1759 2022-04-19 13:28:51 -07:00
Eric McCarthy
ac005628fe [ABNF] merge #1752 2022-04-19 11:59:22 -07:00
Alessandro Coglio
cb30765ab5 [ABNF] Add rule for numeric literals.
This does not change the language. It just factors things better and introduces
more nomenclature in the grammar.
2022-04-18 17:35:14 -07:00
Collin Chin
92ddc88477
Merge pull request #1755 from AleoHQ/abnf-input-files
[ABNF] Add (first draft of) input grammar.
2022-04-18 14:38:08 -07:00
Alessandro Coglio
29f797efae [ABNF] Add (first draft of) input grammar.
This is the (sub)grammar for input files. It is an initial draft, written based
on the Notion page 'Leo Input File Doc/Spec'. This should be compared with the
currently implemented parser of input (i.e. .in) files.

As the Leo Reference will describe (that part has not been written yet), the
input grammar is based on the lexical grammar, i.e. an input file consists of
tokens, comments, and whitespace. However, only some tokens (compared to the
syntactic grammar for Leo code files) are used, namely the ones reachable from
the `input-file` nonterminal.

Currently (i.e. im this initial version of Leo) `input-type` is (any) `type` and
`input-expression` is just a `literal`, but these may evolve as we extend the
language (e.g. we'll probably disallow circuit types and allow tuple and array
constructions). The intent is that `input-type` will be a subset of `type` and
that `input-expression` will be a subset of `expression`.
2022-04-15 19:54:41 -07:00
Alessandro Coglio
7691e35d86 [ABNF] Add rule for binary expressions.
This does not change the language. It just adds a rule to name binary
expressions explicitly. This makes the relation with ternary expressions
clearer, and as usual it explicates more terminology.
2022-04-14 22:26:25 -07:00
Eric McCarthy
447e50f8b4 [ABNF] disallow bidi override codepoints 2022-04-14 02:04:20 -07:00
Alessandro Coglio
515e471c8b
[ABNF] Add a rule for function calls. (#1747)
* [ABNF] Add a rule for function calls.

This does not change the language. It just slightly reformulates the grammar for
greater clarity and to help establish a nomenclature for constructs.

Also remove a trailing space.

* [ABNF] Re-generate markdown.

Co-authored-by: collin <16715212+collinc97@users.noreply.github.com>
2022-04-13 12:22:04 -07:00
gluax
168080942b better match pattern for catching more error situations 2022-04-12 11:52:12 -07:00
gluax
304044546c add constant keyword to grammar, change parameter grammar 2022-04-11 10:01:54 -07:00
Alessandro Coglio
dc3363a858 [ABNF] Factor integer literals into a rule.
This mirrors the structure of the rules for types, where there is an
`integer-type` consisting of `unsigned-type` and `signed-type`.

There is no change to the language.
2022-04-08 19:08:47 +02:00
Alessandro Coglio
822da8009c [ABNF] Add public to keywords. 2022-04-07 22:07:37 +02:00
gluax
8482430299 update abnf to reflect recent changes 2022-04-06 10:41:18 -07:00
gluax
a5b692a765 merge upstream testnet3 2022-04-06 10:25:26 -07:00
gluax
1604170adc update grammar 2022-04-05 09:38:21 -07:00
Alessandro Coglio
c0ffe443c1 [ABNF] Add numerals to tokens.
In the currently restricted version of Leo, this is necessary for the numerals
in affine group literals to be tokens.

No change necessary to the lexer/parser, which already handle this properly.
2022-04-04 20:47:57 -07:00
Alessandro Coglio
0a35ad8006 [ABNF] Re-generate markdown. 2022-04-01 21:26:30 -07:00
Alessandro Coglio
52d820ad7b [ABNF] Also remove rule for expression statements.
Expression statements were removed from the rule for statements, but the rule
for expression statements itself had not been removed. This commit fixes that.
2022-04-01 21:25:37 -07:00
collin
4dce7a86cc Merge branch 'testnet3-dev' of https://github.com/AleoHQ/leo into abnf-expression-statements 2022-04-01 14:17:37 -07:00
collin
f60cf07fad fix merge conflict 2022-04-01 12:20:21 -07:00
collin
1025ab5b19 fix merge conflict 2022-04-01 12:04:37 -07:00
Alessandro Coglio
d08a4f814a [ABNF] Remove expression statements.
Since we do not have tuple in this version of Leo, we cannot have expression
statements, because normally expressions used as statements would have to return
the empty tuple, since we disallow throwing away values in Leo.
2022-03-29 21:20:26 -07:00
Alessandro Coglio
4cce09d5c8 [ABNF] Require function output type.
Since this pre-testnet3 version of Leo does not support tuple types, and since a
missing function type is meant to be interpreted as the empty tuple type `()` in
future versions of Leo, it seems appropriate to require a function output type
in this version of Leo. We could instead default to a different type
(e.g. bool), but it seems cleaner to require it for now, and make it optional
later.
2022-03-28 12:26:36 -07:00
gluax
398e6f5469 merge upstream testnet3 2022-03-28 06:21:17 -07:00
Eric McCarthy
45c731f74d [ABNF] remove extra comment on not-brace 2022-03-24 17:29:06 -07:00
Eric McCarthy
a96e44c49b [ABNF] trim down comments, which will move to the Leo Reference 2022-03-24 17:26:10 -07:00
Eric McCarthy
e6752d67a0 [ABNF] fix the code point range in the format string grammar, along with a note on what the code points mean 2022-03-24 17:13:58 -07:00
Eric McCarthy
3840e04f00 [ABNF] remove Unicode codepoints that can not occur 2022-03-24 11:55:35 -07:00
Alessandro Coglio
e3f87ad322 [ABNF] Remove some stray documentation comments.
Documentation comments were all removed from this grammar file, as readers of
this file in this branch are already familiar with Leo.
2022-03-21 17:49:38 -07:00
Alessandro Coglio
7b13ba58e4 [ABNF] Re-classify function call expressions.
This mirrors, in pre-testnet3, the change in PR #1699 in testnet3.

Since in pre-testnet3 we have fewer kinds expressions, the category of postfix
expressions disappears altogether with this re-classification.
2022-03-21 17:41:41 -07:00