Skip to content
Snippets Groups Projects
Commit acf0dbf5 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

error reporting in expression parser

parent a172d771
No related branches found
No related tags found
1 merge request!125procedural aql
......@@ -435,9 +435,14 @@ std::unique_ptr < Command > Parser::command ( ) {
std::unique_ptr < Expression > Parser::assign_expression ( ) {
std::unique_ptr < Expression > res = or_expression ( );
if ( check ( cli::Lexer::TokenType::ASSIGN_OPERATOR ) ) {
auto checkOptions = getCheckOptions ( );
clearCheckOptions ( );
match ( cli::Lexer::TokenType::ASSIGN_OPERATOR );
 
res = std::make_unique < BinaryExpression > ( abstraction::Operators::BinaryOperators::ASSIGN, std::move ( res ), assign_expression ( ) );
restoreCheckOptions ( checkOptions );
}
return res;
}
......@@ -445,9 +450,14 @@ std::unique_ptr < Expression > Parser::assign_expression ( ) {
std::unique_ptr < Expression > Parser::or_expression ( ) {
std::unique_ptr < Expression > res = and_expression ( );
while ( check ( cli::Lexer::TokenType::OR_OPERATOR ) ) {
auto checkOptions = getCheckOptions ( );
clearCheckOptions ( );
match ( cli::Lexer::TokenType::OR_OPERATOR );
 
res = std::make_unique < BinaryExpression > ( abstraction::Operators::BinaryOperators::LOGICAL_OR, std::move ( res ), and_expression ( ) );
restoreCheckOptions ( checkOptions );
}
return res;
}
......@@ -455,9 +465,14 @@ std::unique_ptr < Expression > Parser::or_expression ( ) {
std::unique_ptr < Expression > Parser::and_expression ( ) {
std::unique_ptr < Expression > res = bitwise_or_expression ( );
while ( check ( cli::Lexer::TokenType::AND_OPERATOR ) ) {
auto checkOptions = getCheckOptions ( );
clearCheckOptions ( );
match ( cli::Lexer::TokenType::AND_OPERATOR );
 
res = std::make_unique < BinaryExpression > ( abstraction::Operators::BinaryOperators::LOGICAL_AND, std::move ( res ), bitwise_or_expression ( ) );
restoreCheckOptions ( checkOptions );
}
return res;
}
......@@ -465,9 +480,14 @@ std::unique_ptr < Expression > Parser::and_expression ( ) {
std::unique_ptr < Expression > Parser::bitwise_or_expression ( ) {
std::unique_ptr < Expression > res = bitwise_and_expression ( );
while ( check ( cli::Lexer::TokenType::PIPE_SIGN ) ) {
auto checkOptions = getCheckOptions ( );
clearCheckOptions ( );
match ( cli::Lexer::TokenType::PIPE_SIGN );
 
res = std::make_unique < BinaryExpression > ( abstraction::Operators::BinaryOperators::BINARY_OR, std::move ( res ), bitwise_and_expression ( ) );
restoreCheckOptions ( checkOptions );
}
return res;
}
......@@ -475,9 +495,14 @@ std::unique_ptr < Expression > Parser::bitwise_or_expression ( ) {
std::unique_ptr < Expression > Parser::bitwise_and_expression ( ) {
std::unique_ptr < Expression > res = bitwise_xor_expression ( );
while ( check ( cli::Lexer::TokenType::AMPERSAND_SIGN ) ) {
auto checkOptions = getCheckOptions ( );
clearCheckOptions ( );
match ( cli::Lexer::TokenType::AMPERSAND_SIGN );
 
res = std::make_unique < BinaryExpression > ( abstraction::Operators::BinaryOperators::BINARY_AND, std::move ( res ), bitwise_xor_expression ( ) );
restoreCheckOptions ( checkOptions );
}
return res;
}
......@@ -485,15 +510,22 @@ std::unique_ptr < Expression > Parser::bitwise_and_expression ( ) {
std::unique_ptr < Expression > Parser::bitwise_xor_expression ( ) {
std::unique_ptr < Expression > res = equality_expression ( );
while ( check ( cli::Lexer::TokenType::CARET_SIGN ) ) {
auto checkOptions = getCheckOptions ( );
clearCheckOptions ( );
match ( cli::Lexer::TokenType::CARET_SIGN );
 
res = std::make_unique < BinaryExpression > ( abstraction::Operators::BinaryOperators::BINARY_XOR, std::move ( res ), equality_expression ( ) );
restoreCheckOptions ( checkOptions );
}
return res;
}
 
std::unique_ptr < Expression > Parser::equality_expression ( ) {
std::unique_ptr < Expression > res = relational_expression ( );
auto checkOptions = getCheckOptions ( );
clearCheckOptions ( );
if ( check ( cli::Lexer::TokenType::EQUAL_OPERATOR ) ) {
match ( cli::Lexer::TokenType::EQUAL_OPERATOR );
res = std::make_unique < BinaryExpression > ( abstraction::Operators::BinaryOperators::EQUALS, std::move ( res ), relational_expression ( ) );
......@@ -501,11 +533,14 @@ std::unique_ptr < Expression > Parser::equality_expression ( ) {
match ( cli::Lexer::TokenType::NOT_EQUAL_OPERATOR );
res = std::make_unique < BinaryExpression > ( abstraction::Operators::BinaryOperators::NOT_EQUALS, std::move ( res ), relational_expression ( ) );
}
restoreCheckOptions ( checkOptions );
return res;
}
 
std::unique_ptr < Expression > Parser::relational_expression ( ) {
std::unique_ptr < Expression > res = add_expression ( );
auto checkOptions = getCheckOptions ( );
clearCheckOptions ( );
if ( check ( cli::Lexer::TokenType::LESS_SIGN ) ) {
match ( cli::Lexer::TokenType::LESS_SIGN );
res = std::make_unique < BinaryExpression > ( abstraction::Operators::BinaryOperators::LESS, std::move ( res ), add_expression ( ) );
......@@ -519,12 +554,15 @@ std::unique_ptr < Expression > Parser::relational_expression ( ) {
match ( cli::Lexer::TokenType::MORE_OR_EQUAL_OPERATOR );
res = std::make_unique < BinaryExpression > ( abstraction::Operators::BinaryOperators::MORE_OR_EQUAL, std::move ( res ), add_expression ( ) );
}
restoreCheckOptions ( checkOptions );
return res;
}
 
std::unique_ptr < Expression > Parser::add_expression ( ) {
std::unique_ptr < Expression > res = mul_expression ( );
while ( check ( cli::Lexer::TokenType::PLUS_SIGN, cli::Lexer::TokenType::MINUS_SIGN ) ) {
auto checkOptions = getCheckOptions ( );
clearCheckOptions ( );
if ( check ( cli::Lexer::TokenType::PLUS_SIGN ) ) {
match ( cli::Lexer::TokenType::PLUS_SIGN );
res = std::make_unique < BinaryExpression > ( abstraction::Operators::BinaryOperators::ADD, std::move ( res ), mul_expression ( ) );
......@@ -532,6 +570,7 @@ std::unique_ptr < Expression > Parser::add_expression ( ) {
match ( cli::Lexer::TokenType::MINUS_SIGN );
res = std::make_unique < BinaryExpression > ( abstraction::Operators::BinaryOperators::SUB, std::move ( res ), mul_expression ( ) );
}
restoreCheckOptions ( checkOptions );
}
return res;
}
......@@ -539,6 +578,8 @@ std::unique_ptr < Expression > Parser::add_expression ( ) {
std::unique_ptr < Expression > Parser::mul_expression ( ) {
std::unique_ptr < Expression > res = prefix_expression ( );
while ( check ( cli::Lexer::TokenType::STAR_SIGN, cli::Lexer::TokenType::PERCENTAGE_SIGN, cli::Lexer::TokenType::SLASH_SIGN ) ) {
auto checkOptions = getCheckOptions ( );
clearCheckOptions ( );
if ( check ( cli::Lexer::TokenType::STAR_SIGN ) ) {
match ( cli::Lexer::TokenType::STAR_SIGN );
res = std::make_unique < BinaryExpression > ( abstraction::Operators::BinaryOperators::MUL, std::move ( res ), prefix_expression ( ) );
......@@ -549,11 +590,13 @@ std::unique_ptr < Expression > Parser::mul_expression ( ) {
match ( cli::Lexer::TokenType::SLASH_SIGN );
res = std::make_unique < BinaryExpression > ( abstraction::Operators::BinaryOperators::DIV, std::move ( res ), prefix_expression ( ) );
}
restoreCheckOptions ( checkOptions );
}
return res;
}
 
std::unique_ptr < Expression > Parser::prefix_expression ( ) {
clearCheckOptions ( );
if ( check_nonreserved_kw ( "cast" ) ) {
match_nonreserved_kw ( "cast" );
match ( cli::Lexer::TokenType::LEFT_PAREN );
......@@ -592,7 +635,10 @@ std::unique_ptr < Expression > Parser::prefix_expression ( ) {
 
std::unique_ptr < Expression > Parser::suffix_expression ( ) {
std::unique_ptr < Expression > res = atom ( );
clearCheckOptions ( );
while ( check ( cli::Lexer::TokenType::DOT, cli::Lexer::TokenType::INC_OPERATOR, cli::Lexer::TokenType::DEC_OPERATOR ) ) {
auto checkOptions = getCheckOptions ( );
clearCheckOptions ( );
if ( check ( cli::Lexer::TokenType::DOT ) ) {
match ( cli::Lexer::TokenType::DOT );
std::string memberName = getTokenValue ( );
......@@ -606,8 +652,9 @@ std::unique_ptr < Expression > Parser::suffix_expression ( ) {
match ( cli::Lexer::TokenType::DEC_OPERATOR );
res = std::make_unique < PostfixExpression > ( abstraction::Operators::PostfixOperators::DECREMENT, std::move ( res ) );
} else {
throw exception::CommonException ( "Mismatched set while expanding suffix expression rule. Token is " + Lexer::tokenTypeToString ( m_current.m_type ) + "." );
throw exception::CommonException ( "Mismatched set " + ext::to_string ( getCheckOptions ( ) ) + " while expanding suffix_expression rule. Token is " + ( ( std::string ) m_current ) + "." );
}
restoreCheckOptions ( checkOptions );
}
return res;
}
......@@ -634,7 +681,7 @@ std::unique_ptr < Expression > Parser::atom ( ) {
int value = matchInteger ( );
return std::make_unique < ImmediateExpression < int > > ( value );
} else {
throw exception::CommonException ( "Mismatched set while expanding parse rule. Token is " + ( ( std::string ) m_current ) + "." );
throw exception::CommonException ( "Mismatched set " + ext::to_string ( getCheckOptions ( ) ) + " while expanding prefix_expression and atom rules. Token is " + ( ( std::string ) m_current ) + "." );
}
}
 
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment