mirror of
https://github.com/mii443/encrypt.git
synced 2025-08-22 23:15:43 +00:00
add CONJ and OR
This commit is contained in:
@ -13,6 +13,7 @@ MUL: '*' ;
|
|||||||
DIV: '/' ;
|
DIV: '/' ;
|
||||||
CONJ: '&&' ;
|
CONJ: '&&' ;
|
||||||
AND: '&' ;
|
AND: '&' ;
|
||||||
|
OR: '||' ;
|
||||||
EQ: '=' ;
|
EQ: '=' ;
|
||||||
EQEQ: '==' ;
|
EQEQ: '==' ;
|
||||||
NE: '!=' ;
|
NE: '!=' ;
|
||||||
|
@ -30,7 +30,7 @@ permission: DOLLER LPAREN ( IDENT LBRACKET ( IDENT COMMA? )* RBRACKET COMMA? )*
|
|||||||
|
|
||||||
expr: assign ;
|
expr: assign ;
|
||||||
assign: equality (EQ assign)? ;
|
assign: equality (EQ assign)? ;
|
||||||
equality: relational (EQEQ relational | NE relational | CONJ)* ;
|
equality: relational (EQEQ relational | NE relational | OR relational | CONJ relational)* ;
|
||||||
relational: add (LE add | LT add | BE add | BT add)* ;
|
relational: add (LE add | LT add | BE add | BT add)* ;
|
||||||
add: mul (ADD mul | SUB mul | SUB_ASSIGNMENT mul | ADD_ASSIGNMENT mul)* ;
|
add: mul (ADD mul | SUB mul | SUB_ASSIGNMENT mul | ADD_ASSIGNMENT mul)* ;
|
||||||
mul: unary (MUL unary | DIV unary | DIV_ASSIGNMENT unary | MUL_ASSIGNMENT unary)* ;
|
mul: unary (MUL unary | DIV unary | DIV_ASSIGNMENT unary | MUL_ASSIGNMENT unary)* ;
|
||||||
|
@ -9,6 +9,8 @@ pub enum NodeKind {
|
|||||||
SUB,
|
SUB,
|
||||||
MUL,
|
MUL,
|
||||||
DIV,
|
DIV,
|
||||||
|
CONJ, // &&
|
||||||
|
OR, // ||
|
||||||
EQ, // ==
|
EQ, // ==
|
||||||
NE, // !=
|
NE, // !=
|
||||||
LT, // <
|
LT, // <
|
||||||
|
@ -426,6 +426,10 @@ impl Parser {
|
|||||||
node = Node::new_node(NodeKind::EQ, node, self.relational()?);
|
node = Node::new_node(NodeKind::EQ, node, self.relational()?);
|
||||||
} else if self.tokenizer.consume(String::from("!=")) {
|
} else if self.tokenizer.consume(String::from("!=")) {
|
||||||
node = Node::new_node(NodeKind::NE, node, self.relational()?);
|
node = Node::new_node(NodeKind::NE, node, self.relational()?);
|
||||||
|
} else if self.tokenizer.consume(String::from("&&")) {
|
||||||
|
node = Node::new_node(NodeKind::CONJ, node, self.relational()?);
|
||||||
|
} else if self.tokenizer.consume(String::from("||")) {
|
||||||
|
node = Node::new_node(NodeKind::OR, node, self.relational()?);
|
||||||
} else {
|
} else {
|
||||||
return Ok(node);
|
return Ok(node);
|
||||||
}
|
}
|
||||||
|
@ -132,6 +132,7 @@ impl Tokenizer {
|
|||||||
String::from(")"),
|
String::from(")"),
|
||||||
String::from("["),
|
String::from("["),
|
||||||
String::from("]"),
|
String::from("]"),
|
||||||
|
String::from("||"),
|
||||||
String::from("=="),
|
String::from("=="),
|
||||||
String::from("!="),
|
String::from("!="),
|
||||||
String::from(">="),
|
String::from(">="),
|
||||||
|
@ -465,6 +465,24 @@ impl GPSL {
|
|||||||
},
|
},
|
||||||
_ => Err("Cannot subtract non-number.".to_string()),
|
_ => Err("Cannot subtract non-number.".to_string()),
|
||||||
},
|
},
|
||||||
|
NodeKind::CONJ => {
|
||||||
|
if lhs.extract_number() == Some(1)
|
||||||
|
&& rhs.extract_number() == Some(1)
|
||||||
|
{
|
||||||
|
Ok(Some(Variable::Number { value: 1 }))
|
||||||
|
} else {
|
||||||
|
Ok(Some(Variable::Number { value: 0 }))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
NodeKind::OR => {
|
||||||
|
if lhs.extract_number() == Some(1)
|
||||||
|
|| rhs.extract_number() == Some(1)
|
||||||
|
{
|
||||||
|
Ok(Some(Variable::Number { value: 1 }))
|
||||||
|
} else {
|
||||||
|
Ok(Some(Variable::Number { value: 0 }))
|
||||||
|
}
|
||||||
|
}
|
||||||
NodeKind::EQ => {
|
NodeKind::EQ => {
|
||||||
if lhs == rhs {
|
if lhs == rhs {
|
||||||
Ok(Some(Variable::Number { value: 1 }))
|
Ok(Some(Variable::Number { value: 1 }))
|
||||||
|
Reference in New Issue
Block a user