mirror of
https://github.com/mii443/encrypt.git
synced 2025-08-22 15:05:33 +00:00
add CONJ and OR
This commit is contained in:
@ -13,6 +13,7 @@ MUL: '*' ;
|
||||
DIV: '/' ;
|
||||
CONJ: '&&' ;
|
||||
AND: '&' ;
|
||||
OR: '||' ;
|
||||
EQ: '=' ;
|
||||
EQEQ: '==' ;
|
||||
NE: '!=' ;
|
||||
|
@ -30,7 +30,7 @@ permission: DOLLER LPAREN ( IDENT LBRACKET ( IDENT COMMA? )* RBRACKET COMMA? )*
|
||||
|
||||
expr: 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)* ;
|
||||
add: mul (ADD mul | SUB mul | SUB_ASSIGNMENT mul | ADD_ASSIGNMENT mul)* ;
|
||||
mul: unary (MUL unary | DIV unary | DIV_ASSIGNMENT unary | MUL_ASSIGNMENT unary)* ;
|
||||
|
@ -9,10 +9,12 @@ pub enum NodeKind {
|
||||
SUB,
|
||||
MUL,
|
||||
DIV,
|
||||
EQ, // ==
|
||||
NE, // !=
|
||||
LT, // <
|
||||
LE, // <=
|
||||
CONJ, // &&
|
||||
OR, // ||
|
||||
EQ, // ==
|
||||
NE, // !=
|
||||
LT, // <
|
||||
LE, // <=
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
|
@ -426,6 +426,10 @@ impl Parser {
|
||||
node = Node::new_node(NodeKind::EQ, node, self.relational()?);
|
||||
} else if self.tokenizer.consume(String::from("!=")) {
|
||||
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 {
|
||||
return Ok(node);
|
||||
}
|
||||
|
@ -132,6 +132,7 @@ impl Tokenizer {
|
||||
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()),
|
||||
},
|
||||
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 => {
|
||||
if lhs == rhs {
|
||||
Ok(Some(Variable::Number { value: 1 }))
|
||||
|
Reference in New Issue
Block a user