Skip to content

Commit

Permalink
PLC-lang#17 parsing support for comparison expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
riederm committed Dec 14, 2019
1 parent e7836d1 commit 17304c8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,6 @@ pub enum Operator {
Minus,
Multiplication,
Division,
OperatorEqual,
OperatorNotEqual,
}
6 changes: 6 additions & 0 deletions src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ pub enum Token {
#[token = "/"]
OperatorDivision,

#[token = "="]
OperatorEqual,

#[token = "<>"]
OperatorNotEqual,

#[regex = r"[0-9]+(\.(0-9)+)?"]
LiteralNumber,
}
Expand Down
20 changes: 20 additions & 0 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,26 @@ fn parse_primary_expression(lexer: &mut RustyLexer) -> Result<Statement, String>
parse_additive_expression(lexer)
}

fn parse_equality_expression(lexer: &mut RustyLexer) -> Result<Statement, String> {
let left = parse_compare_expression(lexer);
let operator = match lexer.token {
OperatorEqual => Operator::Equal,
OperatorNotEqual => Operator::NotEqual,
_ => return Ok(left),
};
lexer.advance();
let right = parse_primary_expression(lexer)?;
Ok(Statement::BinaryExpression {
operator,
left: Box::new(left),
right: Box::new(right),
})
}

fn parse_compare_expression(lexer: &mut RustyLexer) -> Result<Statement, String> {

}

fn parse_additive_expression(lexer: &mut RustyLexer) -> Result<Statement, String> {
let left = parse_multiplication_expression(lexer)?;
let operator = match lexer.token {
Expand Down

0 comments on commit 17304c8

Please sign in to comment.