Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Algorithms Library Toolkit Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Container Registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Algorithms Library Toolkit
Algorithms Library Toolkit Core
Commits
a90cb6dc
"README.md" did not exist on "f87d9ef62b3295ddf6a861209f225691db4ca67d"
Commit
a90cb6dc
authored
5 years ago
by
Jan Travnicek
Browse files
Options
Downloads
Patches
Plain Diff
operators Lexing redesign
parent
df8c979e
No related branches found
No related tags found
1 merge request
!117
Merge jt
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
alib2cli/src/lexer/Lexer.cpp
+148
-10
148 additions, 10 deletions
alib2cli/src/lexer/Lexer.cpp
alib2cli/src/lexer/Lexer.h
+29
-5
29 additions, 5 deletions
alib2cli/src/lexer/Lexer.h
with
177 additions
and
15 deletions
alib2cli/src/lexer/Lexer.cpp
+
148
−
10
View file @
a90cb6dc
...
...
@@ -33,13 +33,13 @@ q0: if ( m_source.getCharacter ( ) == EOF ) {
res
.
m_raw
+=
m_source
.
getCharacter
(
);
m_source
.
advance
(
readNextLine
);
res
.
m_type
=
TokenType
::
LESS_SIGN
;
return
res
;
goto
q10
;
}
if
(
m_source
.
getCharacter
(
)
==
'>'
)
{
res
.
m_raw
+=
m_source
.
getCharacter
(
);
m_source
.
advance
(
readNextLine
);
res
.
m_type
=
TokenType
::
MORE_SIGN
;
return
res
;
goto
q11
;
}
if
(
m_source
.
getCharacter
(
)
==
'('
)
{
res
.
m_raw
+=
m_source
.
getCharacter
(
);
...
...
@@ -93,13 +93,13 @@ q0: if ( m_source.getCharacter ( ) == EOF ) {
res
.
m_raw
+=
m_source
.
getCharacter
(
);
m_source
.
advance
(
readNextLine
);
res
.
m_type
=
TokenType
::
AMPERSAND_SIGN
;
return
res
;
goto
q8
;
}
if
(
m_source
.
getCharacter
(
)
==
'|'
)
{
res
.
m_raw
+=
m_source
.
getCharacter
(
);
m_source
.
advance
(
readNextLine
);
res
.
m_type
=
TokenType
::
PIPE_SIGN
;
return
res
;
goto
q9
;
}
if
(
m_source
.
getCharacter
(
)
==
'^'
)
{
res
.
m_raw
+=
m_source
.
getCharacter
(
);
...
...
@@ -122,8 +122,8 @@ q0: if ( m_source.getCharacter ( ) == EOF ) {
if
(
m_source
.
getCharacter
(
)
==
'='
)
{
res
.
m_raw
+=
m_source
.
getCharacter
(
);
m_source
.
advance
(
readNextLine
);
res
.
m_type
=
TokenType
::
EQUAL_SIGN
;
return
res
;
res
.
m_type
=
TokenType
::
ASSIGN_OPERATOR
;
goto
q12
;
}
if
(
m_source
.
getCharacter
(
)
==
'#'
)
{
res
.
m_raw
+=
m_source
.
getCharacter
(
);
...
...
@@ -147,7 +147,7 @@ q0: if ( m_source.getCharacter ( ) == EOF ) {
res
.
m_raw
+=
m_source
.
getCharacter
(
);
m_source
.
advance
(
readNextLine
);
res
.
m_type
=
TokenType
::
PLUS_SIGN
;
return
res
;
goto
q7
;
}
if
(
m_source
.
getCharacter
(
)
==
'/'
)
{
res
.
m_raw
+=
m_source
.
getCharacter
(
);
...
...
@@ -171,7 +171,7 @@ q0: if ( m_source.getCharacter ( ) == EOF ) {
res
.
m_raw
+=
m_source
.
getCharacter
(
);
m_source
.
advance
(
readNextLine
);
res
.
m_type
=
TokenType
::
EXCLAMATION_SIGN
;
return
res
;
goto
q13
;
}
if
(
m_source
.
getCharacter
(
)
==
'%'
)
{
res
.
m_raw
+=
m_source
.
getCharacter
(
);
...
...
@@ -230,12 +230,18 @@ q1: if ( m_source.getCharacter ( ) == '\0' ) {
res
.
m_type
=
TokenType
::
INTEGER
;
return
res
;
}
q2:
if
(
m_source
.
getCharacter
(
)
==
'\0'
)
{
q2:
if
(
m_source
.
getCharacter
(
)
==
'\0'
)
{
res
.
m_value
=
""
;
res
.
m_type
=
TokenType
::
MINUS_SIGN
;
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'
)
)
{
res
.
m_raw
+=
m_source
.
getCharacter
(
);
res
.
m_value
+=
m_source
.
getCharacter
(
);
...
...
@@ -260,6 +266,36 @@ q2: if ( m_source.getCharacter ( ) == '\0' ) {
res
.
m_type
=
TokenType
::
MINUS_SIGN
;
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'
)
{
res
.
m_type
=
is_kw
(
res
.
m_value
);
return
res
;
...
...
@@ -350,6 +386,108 @@ q6: if ( m_source.getCharacter ( ) == '\0' ) {
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:
if
(
m_source
.
getCharacter
(
)
==
EOF
)
{
res
.
m_type
=
TokenType
::
EOT
;
...
...
This diff is collapsed.
Click to expand it.
alib2cli/src/lexer/Lexer.h
+
29
−
5
View file @
a90cb6dc
...
...
@@ -31,7 +31,9 @@ public:
INTEGER,
STRING,
LESS_SIGN,
LESS_OR_EQUAL_OPERATOR,
MORE_SIGN,
MORE_OR_EQUAL_OPERATOR,
LEFT_PAREN,
RIGHT_PAREN,
LEFT_BRACE,
...
...
@@ -41,18 +43,24 @@ public:
DOLAR_SIGN,
AT_SIGN,
AMPERSAND_SIGN,
AND_OPERATOR,
PIPE_SIGN,
OR_OPERATOR,
CARET_SIGN,
COLON_SIGN,
SEMICOLON_SIGN,
MINUS_SIGN,
DEC_OPERATOR,
PLUS_SIGN,
INC_OPERATOR,
SLASH_SIGN,
STAR_SIGN,
TYLDE_SIGN,
EXCLAMATION_SIGN,
PERCENTAGE_SIGN,
EQUAL_SIGN,
ASSIGN_OPERATOR,
EQUAL_OPERATOR,
NOT_EQUAL_OPERATOR,
HASH_SIGN,
COMMA,
DOT,
...
...
@@ -76,9 +84,13 @@ public:
case TokenType::STRING :
return "string";
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 :
return "out_redirect";
return "more_sign";
case TokenType::MORE_OR_EQUAL_OPERATOR :
return "more_or_equal_operator";
case TokenType::LEFT_PAREN :
return "left_paren";
case TokenType::RIGHT_PAREN :
...
...
@@ -97,8 +109,12 @@ public:
return "dolar_sign";
case TokenType::AMPERSAND_SIGN :
return "ampersand_sign";
case TokenType::AND_OPERATOR :
return "and_operator";
case TokenType::PIPE_SIGN :
return "pipe_sign";
case TokenType::OR_OPERATOR :
return "or_operator";
case TokenType::CARET_SIGN :
return "caret_sign";
case TokenType::COLON_SIGN :
...
...
@@ -107,8 +123,12 @@ public:
return "semicolon_sign";
case TokenType::MINUS_SIGN :
return "minus_sign";
case TokenType::DEC_OPERATOR :
return "dec_operator";
case TokenType::PLUS_SIGN :
return "plus_sign";
case TokenType::INC_OPERATOR :
return "inc_operator";
case TokenType::SLASH_SIGN :
return "slash_sign";
case TokenType::STAR_SIGN :
...
...
@@ -119,8 +139,12 @@ public:
return "exclemation_sign";
case TokenType::PERCENTAGE_SIGN :
return "percentage_sign";
case TokenType::EQUAL_SIGN :
return "equal_sign";
case TokenType::ASSIGN_OPERATOR :
return "assign_operator";
case TokenType::EQUAL_OPERATOR :
return "equal_operator";
case TokenType::NOT_EQUAL_OPERATOR :
return "not_equal_operator";
case TokenType::HASH_SIGN :
return "hash_sign";
case TokenType::COMMA :
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment