char removal: update ABNF + adjust examples

This commit is contained in:
Mazdak Farrokhzad 2022-05-24 15:51:58 +02:00
parent 4237a52696
commit 0883126fef
11 changed files with 5 additions and 153 deletions

Binary file not shown.

View File

@ -72,7 +72,6 @@ end-of-line-comment = "//" *not-line-feed-or-carriage-return
keyword = %s"address"
/ %s"bool"
/ %s"char"
/ %s"console"
/ %s"const"
/ %s"constant"
@ -126,13 +125,6 @@ boolean-literal = %s"true" / %s"false"
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 ; \'
double-quote-escape = "\" double-quote ; \"
@ -176,7 +168,6 @@ numeric-literal = integer-literal
atomic-literal = numeric-literal
/ boolean-literal
/ address-literal
/ character-literal
/ string-literal
symbol = "!" / "&&" / "||"
@ -220,9 +211,7 @@ boolean-type = %s"bool"
address-type = %s"address"
character-type = %s"char"
primitive-type = boolean-type / arithmetic-type / address-type / character-type
primitive-type = boolean-type / arithmetic-type / address-type
type = primitive-type

View File

@ -1,7 +1,7 @@
[project]
name = "hello-world"
version = "0.1.0"
description = "Returns the sum of two u32 integers"
version = "0.2.0"
description = "Logs hello world"
license = "LICENSE-MIT"
[remote]

View File

@ -1,5 +1,3 @@
[main]
y: bool = true;
[registers]
r0: bool = false;

View File

@ -1,12 +1,3 @@
// The 'hello-world' main function.
type str = [char; _];
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];
function main() {
console.log("Hello World!");
}

View File

@ -1 +0,0 @@
outputs/

View File

@ -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

View File

@ -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
```

View File

@ -1,5 +0,0 @@
[main]
str: [char; 20] = "borrow or rob "; // char array can be defined as a string
[registers]
r0: bool = false;

View File

@ -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];

View File

@ -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 "));
}