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
a5f3f1b0
Commit
a5f3f1b0
authored
5 years ago
by
Jan Trávníček
Committed by
Jan Travnicek
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
extend lexer with some needed symbols
parent
251e7e4f
No related branches found
No related tags found
1 merge request
!117
Merge jt
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
alib2cli/src/lexer/Lexer.cpp
+52
-4
52 additions, 4 deletions
alib2cli/src/lexer/Lexer.cpp
alib2cli/src/lexer/Lexer.h
+31
-7
31 additions, 7 deletions
alib2cli/src/lexer/Lexer.h
alib2cli/src/parser/Parser.cpp
+9
-9
9 additions, 9 deletions
alib2cli/src/parser/Parser.cpp
with
92 additions
and
20 deletions
alib2cli/src/lexer/Lexer.cpp
+
52
−
4
View file @
a5f3f1b0
...
...
@@ -32,13 +32,13 @@ q0: if ( m_source.getCharacter ( ) == EOF ) {
if
(
m_source
.
getCharacter
(
)
==
'<'
)
{
res
.
m_raw
+=
m_source
.
getCharacter
(
);
m_source
.
advance
(
readNextLine
);
res
.
m_type
=
TokenType
::
IN_REDIRECT
;
res
.
m_type
=
TokenType
::
LESS_SIGN
;
return
res
;
}
if
(
m_source
.
getCharacter
(
)
==
'>'
)
{
res
.
m_raw
+=
m_source
.
getCharacter
(
);
m_source
.
advance
(
readNextLine
);
res
.
m_type
=
TokenType
::
OUT_REDIRECT
;
res
.
m_type
=
TokenType
::
MORE_SIGN
;
return
res
;
}
if
(
m_source
.
getCharacter
(
)
==
'('
)
{
...
...
@@ -131,12 +131,60 @@ q0: if ( m_source.getCharacter ( ) == EOF ) {
res
.
m_type
=
TokenType
::
HASH_SIGN
;
return
res
;
}
if
(
m_source
.
getCharacter
(
)
==
','
)
{
res
.
m_raw
+=
m_source
.
getCharacter
(
);
m_source
.
advance
(
readNextLine
);
res
.
m_type
=
TokenType
::
COMMA
;
return
res
;
}
if
(
m_source
.
getCharacter
(
)
==
'-'
)
{
res
.
m_raw
+=
m_source
.
getCharacter
(
);
res
.
m_value
+=
m_source
.
getCharacter
(
);
m_source
.
advance
(
readNextLine
);
goto
q2
;
}
if
(
m_source
.
getCharacter
(
)
==
'+'
)
{
res
.
m_raw
+=
m_source
.
getCharacter
(
);
m_source
.
advance
(
readNextLine
);
res
.
m_type
=
TokenType
::
PLUS_SIGN
;
return
res
;
}
if
(
m_source
.
getCharacter
(
)
==
'/'
)
{
res
.
m_raw
+=
m_source
.
getCharacter
(
);
m_source
.
advance
(
readNextLine
);
res
.
m_type
=
TokenType
::
SLASH_SIGN
;
return
res
;
}
if
(
m_source
.
getCharacter
(
)
==
'*'
)
{
res
.
m_raw
+=
m_source
.
getCharacter
(
);
m_source
.
advance
(
readNextLine
);
res
.
m_type
=
TokenType
::
STAR_SIGN
;
return
res
;
}
if
(
m_source
.
getCharacter
(
)
==
'~'
)
{
res
.
m_raw
+=
m_source
.
getCharacter
(
);
m_source
.
advance
(
readNextLine
);
res
.
m_type
=
TokenType
::
TYLDE_SIGN
;
return
res
;
}
if
(
m_source
.
getCharacter
(
)
==
'!'
)
{
res
.
m_raw
+=
m_source
.
getCharacter
(
);
m_source
.
advance
(
readNextLine
);
res
.
m_type
=
TokenType
::
EXCLAMATION_SIGN
;
return
res
;
}
if
(
m_source
.
getCharacter
(
)
==
'%'
)
{
res
.
m_raw
+=
m_source
.
getCharacter
(
);
m_source
.
advance
(
readNextLine
);
res
.
m_type
=
TokenType
::
PERCENTAGE_SIGN
;
return
res
;
}
if
(
m_source
.
getCharacter
(
)
==
'.'
)
{
res
.
m_raw
+=
m_source
.
getCharacter
(
);
m_source
.
advance
(
readNextLine
);
res
.
m_type
=
TokenType
::
DOT
;
return
res
;
}
if
(
m_source
.
getCharacter
(
)
==
'"'
)
{
res
.
m_raw
+=
m_source
.
getCharacter
(
);
...
...
@@ -185,7 +233,7 @@ q1: if ( m_source.getCharacter ( ) == '\0' ) {
q2:
if
(
m_source
.
getCharacter
(
)
==
'\0'
)
{
res
.
m_value
=
""
;
res
.
m_type
=
TokenType
::
DASH
_SIGN
;
res
.
m_type
=
TokenType
::
MINUS
_SIGN
;
return
res
;
}
if
(
(
m_source
.
getCharacter
(
)
>=
'0'
&&
m_source
.
getCharacter
(
)
<=
'9'
)
)
{
...
...
@@ -209,7 +257,7 @@ q2: if ( m_source.getCharacter ( ) == '\0' ) {
}
res
.
m_value
=
""
;
res
.
m_type
=
TokenType
::
DASH
_SIGN
;
res
.
m_type
=
TokenType
::
MINUS
_SIGN
;
return
res
;
q3:
if
(
m_source
.
getCharacter
(
)
==
'\0'
)
{
...
...
This diff is collapsed.
Click to expand it.
alib2cli/src/lexer/Lexer.h
+
31
−
7
View file @
a5f3f1b0
...
...
@@ -30,8 +30,8 @@ public:
IDENTIFIER,
INTEGER,
STRING,
IN_REDIRECT
,
OUT_REDIRECT
,
LESS_SIGN
,
MORE_SIGN
,
LEFT_PAREN,
RIGHT_PAREN,
LEFT_BRACE,
...
...
@@ -45,9 +45,17 @@ public:
CARET_SIGN,
COLON_SIGN,
SEMICOLON_SIGN,
DASH_SIGN,
MINUS_SIGN,
PLUS_SIGN,
SLASH_SIGN,
STAR_SIGN,
TYLDE_SIGN,
EXCLAMATION_SIGN,
PERCENTAGE_SIGN,
EQUAL_SIGN,
HASH_SIGN,
COMMA,
DOT,
FILE,
TYPE,
ERROR,
...
...
@@ -67,9 +75,9 @@ public:
return "number";
case TokenType::STRING :
return "string";
case TokenType::
IN_REDIRECT
:
case TokenType::
LESS_SIGN
:
return "in_redirect";
case TokenType::
OUT_REDIRECT
:
case TokenType::
MORE_SIGN
:
return "out_redirect";
case TokenType::LEFT_PAREN :
return "left_paren";
...
...
@@ -97,12 +105,28 @@ public:
return "colon_sign";
case TokenType::SEMICOLON_SIGN :
return "semicolon_sign";
case TokenType::DASH_SIGN :
return "dash_sign";
case TokenType::MINUS_SIGN :
return "minus_sign";
case TokenType::PLUS_SIGN :
return "plus_sign";
case TokenType::SLASH_SIGN :
return "slash_sign";
case TokenType::STAR_SIGN :
return "star_sign";
case TokenType::TYLDE_SIGN :
return "tylde_sign";
case TokenType::EXCLAMATION_SIGN :
return "exclemation_sign";
case TokenType::PERCENTAGE_SIGN :
return "percentage_sign";
case TokenType::EQUAL_SIGN :
return "equal_sign";
case TokenType::HASH_SIGN :
return "hash_sign";
case TokenType::COMMA :
return "comma";
case TokenType::DOT :
return "dot";
case TokenType::FILE :
return "file";
case TokenType::TYPE :
...
...
This diff is collapsed.
Click to expand it.
alib2cli/src/parser/Parser.cpp
+
9
−
9
View file @
a5f3f1b0
...
...
@@ -174,8 +174,8 @@ std::shared_ptr < Statement > Parser::common ( ) {
match
(
cli
::
Lexer
::
TokenType
::
DOLAR_SIGN
);
std
::
unique_ptr
<
Arg
>
name
=
arg
(
);
return
std
::
make_shared
<
VariableStatement
>
(
std
::
move
(
name
)
);
}
else
if
(
check
(
cli
::
Lexer
::
TokenType
::
IN_REDIRECT
)
)
{
match
(
cli
::
Lexer
::
TokenType
::
IN_REDIRECT
);
}
else
if
(
check
(
cli
::
Lexer
::
TokenType
::
LESS_SIGN
)
)
{
match
(
cli
::
Lexer
::
TokenType
::
LESS_SIGN
);
return
in_redirect
(
);
}
else
if
(
check
(
cli
::
Lexer
::
TokenType
::
STRING
)
)
{
std
::
string
value
=
matchString
(
);
...
...
@@ -208,10 +208,10 @@ std::shared_ptr < Statement > Parser::common ( ) {
}
std
::
shared_ptr
<
Statement
>
Parser
::
param
(
)
{
if
(
check
(
cli
::
Lexer
::
TokenType
::
DOLAR_SIGN
,
cli
::
Lexer
::
TokenType
::
IN_REDIRECT
,
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
::
INTEGER
,
cli
::
Lexer
::
TokenType
::
HASH_SIGN
,
cli
::
Lexer
::
TokenType
::
LEFT_BRACE
)
)
{
return
common
(
);
}
else
if
(
check
(
cli
::
Lexer
::
TokenType
::
DASH
_SIGN
)
)
{
match
(
cli
::
Lexer
::
TokenType
::
DASH
_SIGN
);
}
else
if
(
check
(
cli
::
Lexer
::
TokenType
::
MINUS
_SIGN
)
)
{
match
(
cli
::
Lexer
::
TokenType
::
MINUS
_SIGN
);
return
std
::
make_shared
<
PreviousResultStatement
>
(
);
}
else
if
(
check
(
cli
::
Lexer
::
TokenType
::
IDENTIFIER
)
)
{
std
::
string
value
=
matchIdentifier
(
);
...
...
@@ -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
::
IN_REDIRECT
,
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
::
INTEGER
,
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
(
)
);
...
...
@@ -241,7 +241,7 @@ std::shared_ptr < Statement > Parser::statement ( ) {
std
::
unique_ptr
<
CategoryOption
>
category
=
category_option
(
);
ext
::
vector
<
std
::
shared_ptr
<
Statement
>
>
params
;
ext
::
vector
<
bool
>
moves
;
while
(
!
check
(
cli
::
Lexer
::
TokenType
::
OUT_REDIRECT
,
cli
::
Lexer
::
TokenType
::
PIPE_SIGN
,
cli
::
Lexer
::
TokenType
::
EOS
,
cli
::
Lexer
::
TokenType
::
EOT
,
cli
::
Lexer
::
TokenType
::
RIGHT_PAREN
,
cli
::
Lexer
::
TokenType
::
SEMICOLON_SIGN
)
)
{
while
(
!
check
(
cli
::
Lexer
::
TokenType
::
MORE_SIGN
,
cli
::
Lexer
::
TokenType
::
PIPE_SIGN
,
cli
::
Lexer
::
TokenType
::
EOS
,
cli
::
Lexer
::
TokenType
::
EOT
,
cli
::
Lexer
::
TokenType
::
RIGHT_PAREN
,
cli
::
Lexer
::
TokenType
::
SEMICOLON_SIGN
)
)
{
moves
.
push_back
(
move_arg
(
)
);
params
.
emplace_back
(
param
(
)
);
}
...
...
@@ -295,8 +295,8 @@ void Parser::out_redirect ( std::shared_ptr < StatementList > & list ) {
}
void
Parser
::
result
(
std
::
shared_ptr
<
StatementList
>
&
list
)
{
if
(
check
(
cli
::
Lexer
::
TokenType
::
OUT_REDIRECT
)
)
{
match
(
cli
::
Lexer
::
TokenType
::
OUT_REDIRECT
);
if
(
check
(
cli
::
Lexer
::
TokenType
::
MORE_SIGN
)
)
{
match
(
cli
::
Lexer
::
TokenType
::
MORE_SIGN
);
out_redirect
(
list
);
}
else
if
(
check
(
cli
::
Lexer
::
TokenType
::
EOS
,
cli
::
Lexer
::
TokenType
::
EOT
,
cli
::
Lexer
::
TokenType
::
SEMICOLON_SIGN
)
)
{
list
->
append
(
std
::
make_unique
<
ResultPrintStatement
>
(
)
);
...
...
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