Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
arbor
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Analyze
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
arbor-sim
arbor
Commits
517aa5b6
Commit
517aa5b6
authored
8 years ago
by
Vasileios Karakasis
Browse files
Options
Downloads
Patches
Plain Diff
Fixes support of scientific notation in modcc.
Also the corresponding unit test was rewritten in a less repetitive manner.
parent
eb74bd20
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
modcc/lexer.cpp
+4
-0
4 additions, 0 deletions
modcc/lexer.cpp
tests/modcc/test_lexer.cpp
+33
-36
33 additions, 36 deletions
tests/modcc/test_lexer.cpp
with
37 additions
and
36 deletions
modcc/lexer.cpp
+
4
−
0
View file @
517aa5b6
...
...
@@ -257,6 +257,10 @@ std::string Lexer::number() {
uses_scientific_notation
++
;
str
+=
c
;
current_
++
;
// Consume the next char if +/-
if
(
*
current_
==
'+'
||
*
current_
==
'-'
)
{
str
+=
*
current_
++
;
}
}
else
{
break
;
...
...
This diff is collapsed.
Click to expand it.
tests/modcc/test_lexer.cpp
+
33
−
36
View file @
517aa5b6
#include
<cmath>
#include
<iterator>
#include
"test.hpp"
#include
"lexer.hpp"
...
...
@@ -230,40 +231,36 @@ TEST(Lexer, comments) {
// test numbers
TEST
(
Lexer
,
numbers
)
{
char
string
[]
=
"1 .3 23 87.99 12. -3"
;
PRINT_LEX_STRING
Lexer
lexer
(
string
,
string
+
sizeof
(
string
));
auto
t1
=
lexer
.
parse
();
EXPECT_EQ
(
t1
.
type
,
tok
::
number
);
EXPECT_EQ
(
std
::
stod
(
t1
.
spelling
),
1.0
);
auto
t2
=
lexer
.
parse
();
EXPECT_EQ
(
t2
.
type
,
tok
::
number
);
EXPECT_EQ
(
std
::
stod
(
t2
.
spelling
),
0.3
);
auto
t3
=
lexer
.
parse
();
EXPECT_EQ
(
t3
.
type
,
tok
::
number
);
EXPECT_EQ
(
std
::
stod
(
t3
.
spelling
),
23.0
);
auto
t4
=
lexer
.
parse
();
EXPECT_EQ
(
t4
.
type
,
tok
::
number
);
EXPECT_EQ
(
std
::
stod
(
t4
.
spelling
),
87.99
);
auto
t5
=
lexer
.
parse
();
EXPECT_EQ
(
t5
.
type
,
tok
::
number
);
EXPECT_EQ
(
std
::
stod
(
t5
.
spelling
),
12.0
);
// the lexer does not decide where the - sign goes
// the parser uses additional contextual information to
// decide if the minus is a binary or unary expression
auto
t6
=
lexer
.
parse
();
EXPECT_EQ
(
t6
.
type
,
tok
::
minus
);
auto
t7
=
lexer
.
parse
();
EXPECT_EQ
(
t7
.
type
,
tok
::
number
);
EXPECT_EQ
(
std
::
stod
(
t7
.
spelling
),
3.0
);
auto
t8
=
lexer
.
parse
();
EXPECT_EQ
(
t8
.
type
,
tok
::
eof
);
std
::
istringstream
floats_stream
(
"1 23 .3 87.99 12. 1.e3 1.2e+2 23e-3 -3"
);
std
::
vector
<
double
>
floats
;
std
::
copy
(
std
::
istream_iterator
<
double
>
(
floats_stream
),
std
::
istream_iterator
<
double
>
(),
std
::
back_inserter
(
floats
));
Lexer
lexer
(
floats_stream
.
str
());
auto
t
=
lexer
.
parse
();
auto
iter
=
floats
.
cbegin
();
while
(
t
.
type
!=
tok
::
eof
&&
iter
!=
floats
.
cend
())
{
EXPECT_EQ
(
lexerStatus
::
happy
,
lexer
.
status
());
if
(
*
iter
<
0
)
{
// the lexer does not decide where the - sign goes
// the parser uses additional contextual information to
// decide if the minus is a binary or unary expression
EXPECT_EQ
(
tok
::
minus
,
t
.
type
);
t
=
lexer
.
parse
();
EXPECT_EQ
(
tok
::
number
,
t
.
type
);
EXPECT_EQ
(
-
(
*
iter
),
std
::
stod
(
t
.
spelling
));
}
else
{
EXPECT_EQ
(
t
.
type
,
tok
::
number
);
EXPECT_EQ
(
*
iter
,
std
::
stod
(
t
.
spelling
));
}
++
iter
;
t
=
lexer
.
parse
();
}
EXPECT_EQ
(
floats
.
cend
(),
iter
);
EXPECT_EQ
(
tok
::
eof
,
t
.
type
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
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