Add booleans
This commit is contained in:
parent
ceb1615aea
commit
93e6d490a0
@ -18,6 +18,7 @@ pub fn interpret(ast: Program) {
|
|||||||
Literal::FloatLiteral(f) => {
|
Literal::FloatLiteral(f) => {
|
||||||
args.push(format!("{}.{}f", f.trunc(), f.fract()))
|
args.push(format!("{}.{}f", f.trunc(), f.fract()))
|
||||||
}
|
}
|
||||||
|
Literal::BooleanLiteral(b) => args.push(format!("{}", b)),
|
||||||
},
|
},
|
||||||
Expression::Null => {
|
Expression::Null => {
|
||||||
args.push("null".to_owned());
|
args.push("null".to_owned());
|
||||||
|
@ -90,6 +90,15 @@ fn parse_expression(tokens: &Vec<Token>, current: &mut usize) -> Expression {
|
|||||||
let out = Expression::Literal(Literal::FloatLiteral(val));
|
let out = Expression::Literal(Literal::FloatLiteral(val));
|
||||||
*current += 1;
|
*current += 1;
|
||||||
out
|
out
|
||||||
|
} else if tokens[*current].kind == TokenKind::BooleanLiteral {
|
||||||
|
let mut val = false;
|
||||||
|
if tokens[*current].value == "true" {
|
||||||
|
val = true;
|
||||||
|
} else if tokens[*current].value == "false" {
|
||||||
|
val = false;
|
||||||
|
}
|
||||||
|
*current += 1;
|
||||||
|
Expression::Literal(Literal::BooleanLiteral(val))
|
||||||
} else {
|
} else {
|
||||||
Expression::Null
|
Expression::Null
|
||||||
}
|
}
|
||||||
@ -114,4 +123,5 @@ pub enum Literal {
|
|||||||
StringLiteral(String),
|
StringLiteral(String),
|
||||||
IntLiteral(i32),
|
IntLiteral(i32),
|
||||||
FloatLiteral(f32),
|
FloatLiteral(f32),
|
||||||
|
BooleanLiteral(bool),
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ pub enum TokenKind {
|
|||||||
StringLiteral,
|
StringLiteral,
|
||||||
IntLiteral,
|
IntLiteral,
|
||||||
FloatLiteral,
|
FloatLiteral,
|
||||||
|
BooleanLiteral,
|
||||||
LeftParen,
|
LeftParen,
|
||||||
RightParen,
|
RightParen,
|
||||||
Semicolon,
|
Semicolon,
|
||||||
@ -77,8 +78,12 @@ fn read_identifier(chars: &Vec<char>, current: &mut usize, tokens: &mut Vec<Toke
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
let mut kind = TokenKind::Identifier;
|
||||||
|
if identifier == "true" || identifier == "false" {
|
||||||
|
kind = TokenKind::BooleanLiteral;
|
||||||
|
}
|
||||||
tokens.push(Token {
|
tokens.push(Token {
|
||||||
kind: TokenKind::Identifier,
|
kind: kind,
|
||||||
value: identifier,
|
value: identifier,
|
||||||
index: original_current,
|
index: original_current,
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user