文字列の結合機能

This commit is contained in:
Masato Imai
2022-07-25 14:08:36 +09:00
parent 4842bf561b
commit 78f923360f
4 changed files with 53 additions and 26 deletions

View File

@ -1,15 +1,12 @@
#[server(ip = "172.25.5.189:8080")]
fn encrypt_add(a: eep, b: eep) {
print("a: ");
println(a);
print("b: ");
println(b);
return a + b;
print("a: ")
println(a)
print("b: ")
println(b)
return a + b
}
fn main() {
print("Input a: ")
let a = to_u512(read_line())
@ -17,14 +14,12 @@ fn main() {
print("Input b: ")
let b = to_u512(read_line())
println("a: " + a);
let enc_a = encrypt(a)
let enc_b = encrypt(b)
let enc_res = encrypt_add(enc_a, enc_b)
println(decrypt(enc_res))
for (let i=0 i<10 i+=1) {
println(i)
}
}

View File

@ -36,7 +36,7 @@ add: mul (ADD mul | SUB mul | SUB_ASSIGNMENT mul | ADD_ASSIGNMENT mul)* ;
mul: unary (MUL unary | DIV unary | DIV_ASSIGNMENT unary | MUL_ASSIGNMENT unary)* ;
primary: LPAREN expr RPAREN | function_call | TEXT | NUM ;
function_call: IDENT LPAREN (unary COMMA?)* RPAREN ;
function_call: IDENT LPAREN (stmt COMMA?)* RPAREN ;
unary: ADD primary
| SUB primary

View File

@ -480,7 +480,7 @@ impl Parser {
if self.tokenizer.consume(String::from("(")) {
let mut args: Vec<Box<Node>> = vec![];
while self.tokenizer.current_token().str != ")" {
args.push(self.unary()?);
args.push(self.stmt()?);
self.tokenizer.consume(String::from(","));
}

View File

@ -301,20 +301,52 @@ impl GPSL {
if let Some(lhs) = lhs.clone() {
if let Some(rhs) = rhs {
match kind {
NodeKind::ADD => match GPSL::extract_number(lhs.clone()) {
Ok(lhs) => match GPSL::extract_number(rhs) {
Ok(rhs) => Ok(Some(Variable::Number { value: lhs + rhs })),
Err(err) => Err(err),
NodeKind::ADD => match lhs.clone() {
Variable::Number { value: lhs } => match rhs {
Variable::Number { value: rhs } => {
Ok(Some(Variable::Number { value: lhs + rhs }))
}
Variable::Text { value: rhs } => Ok(Some(Variable::Text {
value: format!("{}{}", lhs, rhs),
})),
_ => Err("Cannot add non-number to number.".to_string()),
},
Err(_) => match GPSL::extract_eep(lhs) {
Ok(lhs) => match GPSL::extract_eep(rhs) {
Ok(rhs) => {
Ok(Some(Variable::PureEncrypted { value: lhs + rhs }))
}
Err(err) => Err(err),
},
Err(err) => Err(err),
Variable::PureEncrypted { value: lhs } => match rhs {
Variable::PureEncrypted { value: rhs } => {
Ok(Some(Variable::PureEncrypted { value: lhs + rhs }))
}
Variable::Text { value: rhs } => Ok(Some(Variable::Text {
value: format!("{}{}", lhs, rhs),
})),
_ => Err("Cannot add non-number to number.".to_string()),
},
Variable::U512 { value: lhs } => match rhs {
Variable::U512 { value: rhs } => {
Ok(Some(Variable::U512 { value: lhs + rhs }))
}
Variable::Text { value: rhs } => Ok(Some(Variable::Text {
value: lhs.to_string() + &rhs,
})),
_ => Err("Cannot add non-number to number.".to_string()),
},
Variable::Text { value: lhs } => match rhs {
Variable::Text { value: rhs } => Ok(Some(Variable::Text {
value: format!("{}{}", lhs, rhs),
})),
Variable::Number { value: rhs } => Ok(Some(Variable::Text {
value: format!("{}{}", lhs, rhs),
})),
Variable::PureEncrypted { value: rhs } => {
Ok(Some(Variable::Text {
value: format!("{}{}", lhs, rhs),
}))
}
Variable::U512 { value: rhs } => Ok(Some(Variable::Text {
value: format!("{}{}", lhs, rhs),
})),
_ => Err("Cannot add non-number to number.".to_string()),
},
_ => Err("Cannot add non-number.".to_string()),
},
NodeKind::DIV => match GPSL::extract_number(lhs) {
Ok(lhs) => match GPSL::extract_number(rhs) {