mirror of
https://github.com/AleoHQ/leo.git
synced 2024-12-19 23:52:02 +03:00
char removal: update ABNF + adjust examples
This commit is contained in:
parent
4237a52696
commit
0883126fef
Binary file not shown.
@ -72,7 +72,6 @@ end-of-line-comment = "//" *not-line-feed-or-carriage-return
|
|||||||
|
|
||||||
keyword = %s"address"
|
keyword = %s"address"
|
||||||
/ %s"bool"
|
/ %s"bool"
|
||||||
/ %s"char"
|
|
||||||
/ %s"console"
|
/ %s"console"
|
||||||
/ %s"const"
|
/ %s"const"
|
||||||
/ %s"constant"
|
/ %s"constant"
|
||||||
@ -126,13 +125,6 @@ boolean-literal = %s"true" / %s"false"
|
|||||||
|
|
||||||
address-literal = %s"aleo1" 58( lowercase-letter / decimal-digit )
|
address-literal = %s"aleo1" 58( lowercase-letter / decimal-digit )
|
||||||
|
|
||||||
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 ; \'
|
single-quote-escape = "\" single-quote ; \'
|
||||||
|
|
||||||
double-quote-escape = "\" double-quote ; \"
|
double-quote-escape = "\" double-quote ; \"
|
||||||
@ -176,7 +168,6 @@ numeric-literal = integer-literal
|
|||||||
atomic-literal = numeric-literal
|
atomic-literal = numeric-literal
|
||||||
/ boolean-literal
|
/ boolean-literal
|
||||||
/ address-literal
|
/ address-literal
|
||||||
/ character-literal
|
|
||||||
/ string-literal
|
/ string-literal
|
||||||
|
|
||||||
symbol = "!" / "&&" / "||"
|
symbol = "!" / "&&" / "||"
|
||||||
@ -220,9 +211,7 @@ boolean-type = %s"bool"
|
|||||||
|
|
||||||
address-type = %s"address"
|
address-type = %s"address"
|
||||||
|
|
||||||
character-type = %s"char"
|
primitive-type = boolean-type / arithmetic-type / address-type
|
||||||
|
|
||||||
primitive-type = boolean-type / arithmetic-type / address-type / character-type
|
|
||||||
|
|
||||||
type = primitive-type
|
type = primitive-type
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "hello-world"
|
name = "hello-world"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
description = "Returns the sum of two u32 integers"
|
description = "Logs hello world"
|
||||||
license = "LICENSE-MIT"
|
license = "LICENSE-MIT"
|
||||||
|
|
||||||
[remote]
|
[remote]
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
[main]
|
[main]
|
||||||
y: bool = true;
|
|
||||||
|
|
||||||
[registers]
|
[registers]
|
||||||
r0: bool = false;
|
|
||||||
|
@ -1,12 +1,3 @@
|
|||||||
// The 'hello-world' main function.
|
function main() {
|
||||||
type str = [char; _];
|
console.log("Hello World!");
|
||||||
|
|
||||||
function main(y: bool) -> bool {
|
|
||||||
let s = "abc";
|
|
||||||
let a: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j9;
|
|
||||||
return (first_el(s) == 'a') == y;
|
|
||||||
}
|
|
||||||
|
|
||||||
function first_el(s: str) -> char {
|
|
||||||
return s[0];
|
|
||||||
}
|
}
|
||||||
|
1
examples/palindrome/.gitignore
vendored
1
examples/palindrome/.gitignore
vendored
@ -1 +0,0 @@
|
|||||||
outputs/
|
|
@ -1,15 +0,0 @@
|
|||||||
[project]
|
|
||||||
name = "palindrome"
|
|
||||||
version = "0.1.0"
|
|
||||||
description = "The palindrome package"
|
|
||||||
license = "MIT"
|
|
||||||
|
|
||||||
[remote]
|
|
||||||
author = "aleo"
|
|
||||||
|
|
||||||
[target]
|
|
||||||
curve = "bls12_377"
|
|
||||||
proving_system = "groth16"
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
# none
|
|
@ -1,20 +0,0 @@
|
|||||||
# palindrome
|
|
||||||
|
|
||||||
## Build Guide
|
|
||||||
|
|
||||||
To compile this Leo program, run:
|
|
||||||
```bash
|
|
||||||
leo build
|
|
||||||
```
|
|
||||||
|
|
||||||
To test this Leo program, run:
|
|
||||||
```bash
|
|
||||||
leo test
|
|
||||||
```
|
|
||||||
|
|
||||||
## Development
|
|
||||||
|
|
||||||
To output the number of constraints, run:
|
|
||||||
```bash
|
|
||||||
leo build -d
|
|
||||||
```
|
|
@ -1,5 +0,0 @@
|
|||||||
[main]
|
|
||||||
str: [char; 20] = "borrow or rob "; // char array can be defined as a string
|
|
||||||
|
|
||||||
[registers]
|
|
||||||
r0: bool = false;
|
|
@ -1,26 +0,0 @@
|
|||||||
// The program state for palindrome/src/main.leo
|
|
||||||
[[public]]
|
|
||||||
|
|
||||||
[state]
|
|
||||||
leaf_index: u32 = 0;
|
|
||||||
root: [u8; 32] = [0; 32];
|
|
||||||
|
|
||||||
[[private]]
|
|
||||||
|
|
||||||
[record]
|
|
||||||
serial_number: [u8; 64] = [0; 64];
|
|
||||||
commitment: [u8; 32] = [0; 32];
|
|
||||||
owner: address = aleo1daxej63vwrmn2zhl4dymygagh89k5d2vaw6rjauueme7le6k2q8sjn0ng9;
|
|
||||||
is_dummy: bool = false;
|
|
||||||
value: u64 = 0;
|
|
||||||
payload: [u8; 32] = [0; 32];
|
|
||||||
birth_program_id: [u8; 48] = [0; 48];
|
|
||||||
death_program_id: [u8; 48] = [0; 48];
|
|
||||||
serial_number_nonce: [u8; 32] = [0; 32];
|
|
||||||
commitment_randomness: [u8; 32] = [0; 32];
|
|
||||||
|
|
||||||
[state_leaf]
|
|
||||||
path: [u8; 128] = [0; 128];
|
|
||||||
memo: [u8; 32] = [0; 32];
|
|
||||||
network_id: u8 = 0;
|
|
||||||
leaf_randomness: [u8; 32] = [0; 32];
|
|
@ -1,59 +0,0 @@
|
|||||||
// This Program takes in any 20-byte low register string and tells
|
|
||||||
// whether a string is a palindrome ignoring any spaces.
|
|
||||||
|
|
||||||
function main(str: [char; 20]) -> bool {
|
|
||||||
return is_palindrome(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
function is_palindrome(str: [char; 20]) -> bool {
|
|
||||||
const str_len = 20u32; // saving const for convenience
|
|
||||||
|
|
||||||
// By default we assume that input is a palindrome.
|
|
||||||
let result = true;
|
|
||||||
let processed = 0u8;
|
|
||||||
|
|
||||||
for start in 0..(str_len / 2) {
|
|
||||||
let start_sym = str[start];
|
|
||||||
if start_sym != ' ' {
|
|
||||||
let skipped = 0u8;
|
|
||||||
let end_empty = 0u8;
|
|
||||||
let end_sym = ' ';
|
|
||||||
|
|
||||||
for end in (str_len - 1)..start {
|
|
||||||
if str[end] != ' ' && skipped == processed && end_sym == ' ' {
|
|
||||||
end_sym = str[end];
|
|
||||||
} else {
|
|
||||||
end_empty = end_empty + 1;
|
|
||||||
if str[end] != ' ' {
|
|
||||||
skipped = skipped + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If there are symbols left to the right from the start.
|
|
||||||
if end_sym != ' ' {
|
|
||||||
console.log("Comparing: {} ? {}", start_sym, end_sym);
|
|
||||||
|
|
||||||
if result {
|
|
||||||
result = (start_sym == end_sym);
|
|
||||||
}
|
|
||||||
|
|
||||||
processed = processed + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log("Result is: {}", result);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@test
|
|
||||||
function test_is_palindrome() {
|
|
||||||
console.assert(is_palindrome("a b a "));
|
|
||||||
console.assert(is_palindrome("😀😀😀😀😀 😀😀😀😀😀"));
|
|
||||||
console.assert(is_palindrome("borrow or rob "));
|
|
||||||
console.assert(is_palindrome("bbbb aaaa aaaa bbbb"));
|
|
||||||
console.assert(is_palindrome("aaaaaaaaaaaaaaaaaaaa"));
|
|
||||||
console.assert(is_palindrome("taco cat "));
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user