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

operators Lexing redesign

parent df8c979e
No related branches found
No related tags found
1 merge request!117Merge jt
...@@ -33,13 +33,13 @@ q0: if ( m_source.getCharacter ( ) == EOF ) { ...@@ -33,13 +33,13 @@ q0: if ( m_source.getCharacter ( ) == EOF ) {
res.m_raw += m_source.getCharacter ( ); res.m_raw += m_source.getCharacter ( );
m_source.advance ( readNextLine ); m_source.advance ( readNextLine );
res.m_type = TokenType::LESS_SIGN; res.m_type = TokenType::LESS_SIGN;
return res; goto q10;
} }
if ( m_source.getCharacter ( ) == '>' ) { if ( m_source.getCharacter ( ) == '>' ) {
res.m_raw += m_source.getCharacter ( ); res.m_raw += m_source.getCharacter ( );
m_source.advance ( readNextLine ); m_source.advance ( readNextLine );
res.m_type = TokenType::MORE_SIGN; res.m_type = TokenType::MORE_SIGN;
return res; goto q11;
} }
if ( m_source.getCharacter ( ) == '(' ) { if ( m_source.getCharacter ( ) == '(' ) {
res.m_raw += m_source.getCharacter ( ); res.m_raw += m_source.getCharacter ( );
...@@ -93,13 +93,13 @@ q0: if ( m_source.getCharacter ( ) == EOF ) { ...@@ -93,13 +93,13 @@ q0: if ( m_source.getCharacter ( ) == EOF ) {
res.m_raw += m_source.getCharacter ( ); res.m_raw += m_source.getCharacter ( );
m_source.advance ( readNextLine ); m_source.advance ( readNextLine );
res.m_type = TokenType::AMPERSAND_SIGN; res.m_type = TokenType::AMPERSAND_SIGN;
return res; goto q8;
} }
if ( m_source.getCharacter ( ) == '|' ) { if ( m_source.getCharacter ( ) == '|' ) {
res.m_raw += m_source.getCharacter ( ); res.m_raw += m_source.getCharacter ( );
m_source.advance ( readNextLine ); m_source.advance ( readNextLine );
res.m_type = TokenType::PIPE_SIGN; res.m_type = TokenType::PIPE_SIGN;
return res; goto q9;
} }
if ( m_source.getCharacter ( ) == '^' ) { if ( m_source.getCharacter ( ) == '^' ) {
res.m_raw += m_source.getCharacter ( ); res.m_raw += m_source.getCharacter ( );
...@@ -122,8 +122,8 @@ q0: if ( m_source.getCharacter ( ) == EOF ) { ...@@ -122,8 +122,8 @@ q0: if ( m_source.getCharacter ( ) == EOF ) {
if ( m_source.getCharacter ( ) == '=' ) { if ( m_source.getCharacter ( ) == '=' ) {
res.m_raw += m_source.getCharacter ( ); res.m_raw += m_source.getCharacter ( );
m_source.advance ( readNextLine ); m_source.advance ( readNextLine );
res.m_type = TokenType::EQUAL_SIGN; res.m_type = TokenType::ASSIGN_OPERATOR;
return res; goto q12;
} }
if ( m_source.getCharacter ( ) == '#' ) { if ( m_source.getCharacter ( ) == '#' ) {
res.m_raw += m_source.getCharacter ( ); res.m_raw += m_source.getCharacter ( );
...@@ -147,7 +147,7 @@ q0: if ( m_source.getCharacter ( ) == EOF ) { ...@@ -147,7 +147,7 @@ q0: if ( m_source.getCharacter ( ) == EOF ) {
res.m_raw += m_source.getCharacter ( ); res.m_raw += m_source.getCharacter ( );
m_source.advance ( readNextLine ); m_source.advance ( readNextLine );
res.m_type = TokenType::PLUS_SIGN; res.m_type = TokenType::PLUS_SIGN;
return res; goto q7;
} }
if ( m_source.getCharacter ( ) == '/' ) { if ( m_source.getCharacter ( ) == '/' ) {
res.m_raw += m_source.getCharacter ( ); res.m_raw += m_source.getCharacter ( );
...@@ -171,7 +171,7 @@ q0: if ( m_source.getCharacter ( ) == EOF ) { ...@@ -171,7 +171,7 @@ q0: if ( m_source.getCharacter ( ) == EOF ) {
res.m_raw += m_source.getCharacter ( ); res.m_raw += m_source.getCharacter ( );
m_source.advance ( readNextLine ); m_source.advance ( readNextLine );
res.m_type = TokenType::EXCLAMATION_SIGN; res.m_type = TokenType::EXCLAMATION_SIGN;
return res; goto q13;
} }
if ( m_source.getCharacter ( ) == '%' ) { if ( m_source.getCharacter ( ) == '%' ) {
res.m_raw += m_source.getCharacter ( ); res.m_raw += m_source.getCharacter ( );
...@@ -230,12 +230,18 @@ q1: if ( m_source.getCharacter ( ) == '\0' ) { ...@@ -230,12 +230,18 @@ q1: if ( m_source.getCharacter ( ) == '\0' ) {
res.m_type = TokenType::INTEGER; res.m_type = TokenType::INTEGER;
return res; return res;
} }
q2:
q2: if ( m_source.getCharacter ( ) == '\0' ) { if ( m_source.getCharacter ( ) == '\0' ) {
res.m_value = ""; res.m_value = "";
res.m_type = TokenType::MINUS_SIGN; res.m_type = TokenType::MINUS_SIGN;
return res; return res;
} }
if ( m_source.getCharacter ( ) == '-' ) {
res.m_raw += m_source.getCharacter ( );
res.m_value += m_source.getCharacter ( );
m_source.advance ( readNextLine );
goto q2Prime;
}
if ( ( m_source.getCharacter ( ) >= '0' && m_source.getCharacter ( ) <= '9' ) ) { if ( ( m_source.getCharacter ( ) >= '0' && m_source.getCharacter ( ) <= '9' ) ) {
res.m_raw += m_source.getCharacter ( ); res.m_raw += m_source.getCharacter ( );
res.m_value += m_source.getCharacter ( ); res.m_value += m_source.getCharacter ( );
...@@ -260,6 +266,36 @@ q2: if ( m_source.getCharacter ( ) == '\0' ) { ...@@ -260,6 +266,36 @@ q2: if ( m_source.getCharacter ( ) == '\0' ) {
res.m_type = TokenType::MINUS_SIGN; res.m_type = TokenType::MINUS_SIGN;
return res; return res;
   
q2Prime:
if ( m_source.getCharacter ( ) == '\0' ) {
res.m_value = "";
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' )
|| ( m_source.getCharacter ( ) >= 'A' && m_source.getCharacter ( ) <= 'Z' )
|| ( m_source.getCharacter ( ) == ':' ) ) {
res.m_raw += m_source.getCharacter ( );
res.m_value += m_source.getCharacter ( );
m_source.advance ( readNextLine );
goto q3;
} else if ( m_source.getCharacter ( ) == '\\' ) {
res.m_raw += m_source.getCharacter ( );
m_source.advance ( true );
goto q3Escape;
}
res.m_value = "";
res.m_type = TokenType::DEC_OPERATOR;
return res;
q3: if ( m_source.getCharacter ( ) == '\0' ) { q3: if ( m_source.getCharacter ( ) == '\0' ) {
res.m_type = is_kw ( res.m_value ); res.m_type = is_kw ( res.m_value );
return res; return res;
...@@ -350,6 +386,108 @@ q6: if ( m_source.getCharacter ( ) == '\0' ) { ...@@ -350,6 +386,108 @@ q6: if ( m_source.getCharacter ( ) == '\0' ) {
return res; return res;
} }
   
q7: if ( m_source.getCharacter ( ) == EOF ) {
return res;
}
if ( m_source.getCharacter ( ) == '\0' ) {
return res;
}
if ( m_source.getCharacter ( ) == '+' ) {
res.m_raw += m_source.getCharacter ( );
m_source.advance ( readNextLine );
res.m_type = TokenType::INC_OPERATOR;
} else {
return res;
}
q8: if ( m_source.getCharacter ( ) == EOF ) {
return res;
}
if ( m_source.getCharacter ( ) == '\0' ) {
return res;
}
if ( m_source.getCharacter ( ) == '&' ) {
res.m_raw += m_source.getCharacter ( );
m_source.advance ( readNextLine );
res.m_type = TokenType::AND_OPERATOR;
} else {
return res;
}
q9: if ( m_source.getCharacter ( ) == EOF ) {
return res;
}
if ( m_source.getCharacter ( ) == '\0' ) {
return res;
}
if ( m_source.getCharacter ( ) == '|' ) {
res.m_raw += m_source.getCharacter ( );
m_source.advance ( readNextLine );
res.m_type = TokenType::OR_OPERATOR;
} else {
return res;
}
q10:
if ( m_source.getCharacter ( ) == EOF ) {
return res;
}
if ( m_source.getCharacter ( ) == '\0' ) {
return res;
}
if ( m_source.getCharacter ( ) == '=' ) {
res.m_raw += m_source.getCharacter ( );
m_source.advance ( readNextLine );
res.m_type = TokenType::LESS_OR_EQUAL_OPERATOR;
} else {
return res;
}
q11:
if ( m_source.getCharacter ( ) == EOF ) {
return res;
}
if ( m_source.getCharacter ( ) == '\0' ) {
return res;
}
if ( m_source.getCharacter ( ) == '=' ) {
res.m_raw += m_source.getCharacter ( );
m_source.advance ( readNextLine );
res.m_type = TokenType::MORE_OR_EQUAL_OPERATOR;
} else {
return res;
}
q12:
if ( m_source.getCharacter ( ) == EOF ) {
return res;
}
if ( m_source.getCharacter ( ) == '\0' ) {
return res;
}
if ( m_source.getCharacter ( ) == '=' ) {
res.m_raw += m_source.getCharacter ( );
m_source.advance ( readNextLine );
res.m_type = TokenType::EQUAL_OPERATOR;
} else {
return res;
}
q13:
if ( m_source.getCharacter ( ) == EOF ) {
return res;
}
if ( m_source.getCharacter ( ) == '\0' ) {
return res;
}
if ( m_source.getCharacter ( ) == '=' ) {
res.m_raw += m_source.getCharacter ( );
m_source.advance ( readNextLine );
res.m_type = TokenType::NOT_EQUAL_OPERATOR;
} else {
return res;
}
qFile: qFile:
if ( m_source.getCharacter ( ) == EOF ) { if ( m_source.getCharacter ( ) == EOF ) {
res.m_type = TokenType::EOT; res.m_type = TokenType::EOT;
......
...@@ -31,7 +31,9 @@ public: ...@@ -31,7 +31,9 @@ public:
INTEGER, INTEGER,
STRING, STRING,
LESS_SIGN, LESS_SIGN,
LESS_OR_EQUAL_OPERATOR,
MORE_SIGN, MORE_SIGN,
MORE_OR_EQUAL_OPERATOR,
LEFT_PAREN, LEFT_PAREN,
RIGHT_PAREN, RIGHT_PAREN,
LEFT_BRACE, LEFT_BRACE,
...@@ -41,18 +43,24 @@ public: ...@@ -41,18 +43,24 @@ public:
DOLAR_SIGN, DOLAR_SIGN,
AT_SIGN, AT_SIGN,
AMPERSAND_SIGN, AMPERSAND_SIGN,
AND_OPERATOR,
PIPE_SIGN, PIPE_SIGN,
OR_OPERATOR,
CARET_SIGN, CARET_SIGN,
COLON_SIGN, COLON_SIGN,
SEMICOLON_SIGN, SEMICOLON_SIGN,
MINUS_SIGN, MINUS_SIGN,
DEC_OPERATOR,
PLUS_SIGN, PLUS_SIGN,
INC_OPERATOR,
SLASH_SIGN, SLASH_SIGN,
STAR_SIGN, STAR_SIGN,
TYLDE_SIGN, TYLDE_SIGN,
EXCLAMATION_SIGN, EXCLAMATION_SIGN,
PERCENTAGE_SIGN, PERCENTAGE_SIGN,
EQUAL_SIGN, ASSIGN_OPERATOR,
EQUAL_OPERATOR,
NOT_EQUAL_OPERATOR,
HASH_SIGN, HASH_SIGN,
COMMA, COMMA,
DOT, DOT,
...@@ -76,9 +84,13 @@ public: ...@@ -76,9 +84,13 @@ public:
case TokenType::STRING : case TokenType::STRING :
return "string"; return "string";
case TokenType::LESS_SIGN : case TokenType::LESS_SIGN :
return "in_redirect"; return "less_sign";
case TokenType::LESS_OR_EQUAL_OPERATOR :
return "less_or_equal_operator";
case TokenType::MORE_SIGN : case TokenType::MORE_SIGN :
return "out_redirect"; return "more_sign";
case TokenType::MORE_OR_EQUAL_OPERATOR :
return "more_or_equal_operator";
case TokenType::LEFT_PAREN : case TokenType::LEFT_PAREN :
return "left_paren"; return "left_paren";
case TokenType::RIGHT_PAREN : case TokenType::RIGHT_PAREN :
...@@ -97,8 +109,12 @@ public: ...@@ -97,8 +109,12 @@ public:
return "dolar_sign"; return "dolar_sign";
case TokenType::AMPERSAND_SIGN : case TokenType::AMPERSAND_SIGN :
return "ampersand_sign"; return "ampersand_sign";
case TokenType::AND_OPERATOR :
return "and_operator";
case TokenType::PIPE_SIGN : case TokenType::PIPE_SIGN :
return "pipe_sign"; return "pipe_sign";
case TokenType::OR_OPERATOR :
return "or_operator";
case TokenType::CARET_SIGN : case TokenType::CARET_SIGN :
return "caret_sign"; return "caret_sign";
case TokenType::COLON_SIGN : case TokenType::COLON_SIGN :
...@@ -107,8 +123,12 @@ public: ...@@ -107,8 +123,12 @@ public:
return "semicolon_sign"; return "semicolon_sign";
case TokenType::MINUS_SIGN : case TokenType::MINUS_SIGN :
return "minus_sign"; return "minus_sign";
case TokenType::DEC_OPERATOR :
return "dec_operator";
case TokenType::PLUS_SIGN : case TokenType::PLUS_SIGN :
return "plus_sign"; return "plus_sign";
case TokenType::INC_OPERATOR :
return "inc_operator";
case TokenType::SLASH_SIGN : case TokenType::SLASH_SIGN :
return "slash_sign"; return "slash_sign";
case TokenType::STAR_SIGN : case TokenType::STAR_SIGN :
...@@ -119,8 +139,12 @@ public: ...@@ -119,8 +139,12 @@ public:
return "exclemation_sign"; return "exclemation_sign";
case TokenType::PERCENTAGE_SIGN : case TokenType::PERCENTAGE_SIGN :
return "percentage_sign"; return "percentage_sign";
case TokenType::EQUAL_SIGN : case TokenType::ASSIGN_OPERATOR :
return "equal_sign"; return "assign_operator";
case TokenType::EQUAL_OPERATOR :
return "equal_operator";
case TokenType::NOT_EQUAL_OPERATOR :
return "not_equal_operator";
case TokenType::HASH_SIGN : case TokenType::HASH_SIGN :
return "hash_sign"; return "hash_sign";
case TokenType::COMMA : case TokenType::COMMA :
......
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