Skip to content
Snippets Groups Projects
Commit 121dddbf authored by Jan Travnicek's avatar Jan Travnicek
Browse files

drop parsing negative numbers in lexer

parent a90cb6dc
No related branches found
No related tags found
1 merge request!117Merge jt
......@@ -218,7 +218,7 @@ q0: if ( m_source.getCharacter ( ) == EOF ) {
return res;
 
q1: if ( m_source.getCharacter ( ) == '\0' ) {
res.m_type = TokenType::INTEGER;
res.m_type = TokenType::UNSIGNED;
return res;
}
if ( ( m_source.getCharacter ( ) >= '0' && m_source.getCharacter ( ) <= '9' ) ) {
......@@ -227,7 +227,7 @@ q1: if ( m_source.getCharacter ( ) == '\0' ) {
m_source.advance ( readNextLine );
goto q1;
} else {
res.m_type = TokenType::INTEGER;
res.m_type = TokenType::UNSIGNED;
return res;
}
q2:
......@@ -242,12 +242,6 @@ q2:
m_source.advance ( readNextLine );
goto q2Prime;
}
if ( ( m_source.getCharacter ( ) >= '0' && m_source.getCharacter ( ) <= '9' ) ) {
res.m_raw += m_source.getCharacter ( );
res.m_value += m_source.getCharacter ( );
m_source.advance ( readNextLine );
goto q1;
}
 
if ( ( m_source.getCharacter ( ) >= 'a' && m_source.getCharacter ( ) <= 'z' )
|| ( m_source.getCharacter ( ) >= 'A' && m_source.getCharacter ( ) <= 'Z' )
......@@ -272,14 +266,8 @@ q2Prime:
res.m_type = TokenType::DEC_OPERATOR;
return res;
}
if ( ( m_source.getCharacter ( ) >= '0' && m_source.getCharacter ( ) <= '9' ) ) {
res.m_raw += m_source.getCharacter ( );
res.m_value += m_source.getCharacter ( );
m_source.advance ( readNextLine );
goto q1;
}
if ( ( m_source.getCharacter ( ) >= 'a' && m_source.getCharacter ( ) <= 'z' )
if ( ( m_source.getCharacter ( ) >= '0' && m_source.getCharacter ( ) <= '9' )
|| ( m_source.getCharacter ( ) >= 'a' && m_source.getCharacter ( ) <= 'z' )
|| ( m_source.getCharacter ( ) >= 'A' && m_source.getCharacter ( ) <= 'Z' )
|| ( m_source.getCharacter ( ) == ':' ) ) {
res.m_raw += m_source.getCharacter ( );
......
......@@ -28,7 +28,7 @@ private:
public:
enum class TokenType : unsigned {
IDENTIFIER,
INTEGER,
UNSIGNED,
STRING,
LESS_SIGN,
LESS_OR_EQUAL_OPERATOR,
......@@ -79,8 +79,8 @@ public:
switch ( type ) {
case TokenType::IDENTIFIER :
return "identifier";
case TokenType::INTEGER :
return "number";
case TokenType::UNSIGNED :
return "unsigned";
case TokenType::STRING :
return "string";
case TokenType::LESS_SIGN :
......@@ -184,7 +184,7 @@ public:
switch ( m_type ) {
case TokenType::IDENTIFIER :
return res + ": " + m_value;
case TokenType::INTEGER :
case TokenType::UNSIGNED :
return res + ": " + ext::to_string ( m_value );
case TokenType::STRING :
return res + ": \"" + ext::to_string ( m_value ) + "\"";
......
......@@ -35,7 +35,7 @@ std::unique_ptr < CategoryOption > Parser::category_option ( ) {
if ( check ( cli::Lexer::TokenType::COLON_SIGN ) ) {
match ( cli::Lexer::TokenType::COLON_SIGN );
std::string value = getTokenValue ( );
match ( cli::Lexer::TokenType::INTEGER, cli::Lexer::TokenType::IDENTIFIER );
match ( cli::Lexer::TokenType::UNSIGNED, cli::Lexer::TokenType::IDENTIFIER );
return std::make_unique < CategoryOption > ( value );
} else {
return nullptr;
......@@ -46,7 +46,7 @@ std::unique_ptr < TypeOption > Parser::type_option ( ) {
if ( check ( cli::Lexer::TokenType::COLON_SIGN ) ) {
match ( cli::Lexer::TokenType::COLON_SIGN );
std::string value = getTokenValue ( );
match ( cli::Lexer::TokenType::INTEGER, cli::Lexer::TokenType::IDENTIFIER );
match ( cli::Lexer::TokenType::UNSIGNED, cli::Lexer::TokenType::IDENTIFIER );
return std::make_unique < TypeOption > ( std::move ( value ) );
} else {
throw exception::CommonException ( "Mismatched colon sign while expanding type_option rule. Token is " + Lexer::tokenTypeToString ( m_current.m_type ) + "." );
......@@ -66,7 +66,7 @@ std::unique_ptr < Arg > Parser::file ( ) {
if ( check ( cli::Lexer::TokenType::HASH_SIGN ) ) {
match ( cli::Lexer::TokenType::HASH_SIGN );
std::string value = getTokenValue ( );
match ( cli::Lexer::TokenType::INTEGER, cli::Lexer::TokenType::IDENTIFIER );
match ( cli::Lexer::TokenType::UNSIGNED, cli::Lexer::TokenType::IDENTIFIER );
return std::make_unique < BindedArg > ( std::move ( value ) );
} else if ( check ( cli::Lexer::TokenType::STRING ) ) {
return std::make_unique < ImmediateArg > ( matchString ( ) );
......@@ -88,7 +88,7 @@ std::unique_ptr < Arg > Parser::arg ( ) {
if ( check ( cli::Lexer::TokenType::HASH_SIGN ) ) {
match ( cli::Lexer::TokenType::HASH_SIGN );
std::string value = getTokenValue ( );
match ( cli::Lexer::TokenType::INTEGER, cli::Lexer::TokenType::IDENTIFIER );
match ( cli::Lexer::TokenType::UNSIGNED, cli::Lexer::TokenType::IDENTIFIER );
return std::make_unique < BindedArg > ( std::move ( value ) );
} else {
std::string value = matchIdentifier ( );
......@@ -122,7 +122,7 @@ std::unique_ptr < Arg > Parser::optional_variable ( ) {
if ( check ( cli::Lexer::TokenType::DOLAR_SIGN ) ) {
match ( cli::Lexer::TokenType::DOLAR_SIGN );
std::string value = getTokenValue ( );
match ( cli::Lexer::TokenType::INTEGER, cli::Lexer::TokenType::IDENTIFIER );
match ( cli::Lexer::TokenType::UNSIGNED, cli::Lexer::TokenType::IDENTIFIER );
return std::make_unique < ImmediateArg > ( value );
} else {
return nullptr;
......@@ -133,7 +133,7 @@ std::unique_ptr < Arg > Parser::optional_binding ( ) {
if ( check ( cli::Lexer::TokenType::HASH_SIGN ) ) {
match ( cli::Lexer::TokenType::HASH_SIGN );
std::string value = getTokenValue ( );
match ( cli::Lexer::TokenType::INTEGER, cli::Lexer::TokenType::IDENTIFIER );
match ( cli::Lexer::TokenType::UNSIGNED, cli::Lexer::TokenType::IDENTIFIER );
return std::make_unique < ImmediateArg > ( value );
} else {
return nullptr;
......@@ -180,13 +180,13 @@ std::shared_ptr < Statement > Parser::common ( ) {
} else if ( check ( cli::Lexer::TokenType::STRING ) ) {
std::string value = matchString ( );
return std::make_shared < ImmediateStatement < std::string > > ( value );
} else if ( check ( cli::Lexer::TokenType::INTEGER ) ) {
} else if ( check ( cli::Lexer::TokenType::UNSIGNED ) ) {
int value = matchInteger ( );
return std::make_shared < ImmediateStatement < int > > ( value );
} else if ( check ( cli::Lexer::TokenType::HASH_SIGN ) ) {
match ( cli::Lexer::TokenType::HASH_SIGN );
std::string value = getTokenValue ( );
match ( cli::Lexer::TokenType::INTEGER, cli::Lexer::TokenType::IDENTIFIER );
match ( cli::Lexer::TokenType::UNSIGNED, cli::Lexer::TokenType::IDENTIFIER );
return std::make_shared < ValueStatement > ( std::make_unique < BindedArg > ( std::move ( value ) ) );
} else if ( check ( cli::Lexer::TokenType::LEFT_BRACE ) ) {
match ( cli::Lexer::TokenType::LEFT_BRACE );
......@@ -208,7 +208,7 @@ std::shared_ptr < Statement > Parser::common ( ) {
}
 
std::shared_ptr < Statement > Parser::param ( ) {
if ( check ( cli::Lexer::TokenType::DOLAR_SIGN, cli::Lexer::TokenType::LESS_SIGN, cli::Lexer::TokenType::STRING, cli::Lexer::TokenType::INTEGER, cli::Lexer::TokenType::HASH_SIGN, cli::Lexer::TokenType::LEFT_BRACE ) ) {
if ( check ( cli::Lexer::TokenType::DOLAR_SIGN, cli::Lexer::TokenType::LESS_SIGN, cli::Lexer::TokenType::STRING, cli::Lexer::TokenType::UNSIGNED, cli::Lexer::TokenType::HASH_SIGN, cli::Lexer::TokenType::LEFT_BRACE ) ) {
return common ( );
} else if ( check ( cli::Lexer::TokenType::MINUS_SIGN ) ) {
match ( cli::Lexer::TokenType::MINUS_SIGN );
......@@ -229,7 +229,7 @@ std::shared_ptr < Statement > Parser::param ( ) {
}
 
std::shared_ptr < Statement > Parser::statement ( ) {
if ( check ( cli::Lexer::TokenType::DOLAR_SIGN, cli::Lexer::TokenType::LESS_SIGN, cli::Lexer::TokenType::STRING, cli::Lexer::TokenType::INTEGER, cli::Lexer::TokenType::HASH_SIGN, cli::Lexer::TokenType::LEFT_BRACE ) ) {
if ( check ( cli::Lexer::TokenType::DOLAR_SIGN, cli::Lexer::TokenType::LESS_SIGN, cli::Lexer::TokenType::STRING, cli::Lexer::TokenType::UNSIGNED, cli::Lexer::TokenType::HASH_SIGN, cli::Lexer::TokenType::LEFT_BRACE ) ) {
return common ( );
} else if ( check ( cli::Lexer::TokenType::IDENTIFIER ) ) {
std::unique_ptr < Arg > name = std::make_unique < ImmediateArg > ( matchIdentifier ( ) );
......@@ -404,9 +404,9 @@ std::unique_ptr < Command > Parser::command ( ) {
} else if ( check_nonreserved_kw ( "set" ) ) {
match_nonreserved_kw ( "set" );
std::string param = getTokenValue ( );
match ( cli::Lexer::TokenType::INTEGER, cli::Lexer::TokenType::IDENTIFIER );
match ( cli::Lexer::TokenType::UNSIGNED, cli::Lexer::TokenType::IDENTIFIER );
std::string value = getTokenValue ( );
match ( cli::Lexer::TokenType::INTEGER, cli::Lexer::TokenType::IDENTIFIER, cli::Lexer::TokenType::STRING );
match ( cli::Lexer::TokenType::UNSIGNED, cli::Lexer::TokenType::IDENTIFIER, cli::Lexer::TokenType::STRING );
return std::make_unique < SetCommand > ( std::move ( param ), std::move ( value ) );
} else if ( check_nonreserved_kw ( "load" ) ) {
match_nonreserved_kw ( "load" );
......
......@@ -93,7 +93,7 @@ public:
}
 
int matchInteger ( ) {
if ( ! check ( Lexer::TokenType::INTEGER ) )
if ( ! check ( Lexer::TokenType::UNSIGNED ) )
throw exception::CommonException ( "Mismatched token while matching an integer." );
int res = ext::from_string < int > ( m_current.m_value );
m_current = m_lexer.nextToken ( false );
......
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