diff --git a/alib2cli/src/lexer/Lexer.cpp b/alib2cli/src/lexer/Lexer.cpp index 79c758ac461aed0c84840c89a0e91d92e4aa2793..f0367e1ff54f6f1329d6c15f7dd4646b7c5d8dc8 100644 --- a/alib2cli/src/lexer/Lexer.cpp +++ b/alib2cli/src/lexer/Lexer.cpp @@ -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 ( ); diff --git a/alib2cli/src/lexer/Lexer.h b/alib2cli/src/lexer/Lexer.h index d373532db9fd722c84bd4046f7e3918f0f504594..76931865194d251f3fe14249385435cf8fc1b470 100644 --- a/alib2cli/src/lexer/Lexer.h +++ b/alib2cli/src/lexer/Lexer.h @@ -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 ) + "\""; diff --git a/alib2cli/src/parser/Parser.cpp b/alib2cli/src/parser/Parser.cpp index df6beb086b6074d1d934fccf679a6fc0652f04df..465587f9c5591e9ed3209ff58c5b14353dc69aa8 100644 --- a/alib2cli/src/parser/Parser.cpp +++ b/alib2cli/src/parser/Parser.cpp @@ -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" ); diff --git a/alib2cli/src/parser/Parser.h b/alib2cli/src/parser/Parser.h index a581f1f7913497342434d803e163ba50f2b5e702..eb66cd4d70bb5ec23a1a5c10b78d09b2c8e14c74 100644 --- a/alib2cli/src/parser/Parser.h +++ b/alib2cli/src/parser/Parser.h @@ -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 );