Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cs444
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Xun Yang
cs444
Commits
6fd50e03
Commit
6fd50e03
authored
5 years ago
by
pycsham
Browse files
Options
Downloads
Patches
Plain Diff
fixing maximum integer range with comments in between
parent
15b4de22
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Scanning.py
+13
-6
13 additions, 6 deletions
Scanning.py
with
13 additions
and
6 deletions
Scanning.py
+
13
−
6
View file @
6fd50e03
...
@@ -77,7 +77,6 @@ wrongJavaKeyWordDict = {
...
@@ -77,7 +77,6 @@ wrongJavaKeyWordDict = {
'
long
'
,
'
long
'
,
'
private
'
,
'
private
'
,
'
strictfp
'
,
'
strictfp
'
,
'
super
'
,
'
switch
'
,
'
switch
'
,
'
synchronized
'
,
'
synchronized
'
,
'
throw
'
,
'
throw
'
,
...
@@ -86,7 +85,6 @@ wrongJavaKeyWordDict = {
...
@@ -86,7 +85,6 @@ wrongJavaKeyWordDict = {
'
try
'
,
'
try
'
,
'
volatile
'
,
'
volatile
'
,
'
_
'
,
'
_
'
,
'
super
'
,
'
Long
'
,
'
Long
'
,
'
Float
'
'
Float
'
}
}
...
@@ -496,10 +494,10 @@ def scan(input):
...
@@ -496,10 +494,10 @@ def scan(input):
if
tokens
[
index
+
1
].
name
==
'
NUM
'
:
if
tokens
[
index
+
1
].
name
==
'
NUM
'
:
return
(
None
,
"
wrong integer literal: starts with 0
"
)
return
(
None
,
"
wrong integer literal: starts with 0
"
)
# Checking integer range (does not cover all edge cases)
# Checking integer range (does not cover all edge cases)
elif
token
.
name
==
'
NUM
'
and
index
>
0
and
tokens
[
index
-
1
].
name
==
'
SUB
'
and
int
(
token
.
lex
)
>
2147483648
:
#
elif token.name == 'NUM' and index > 0 and tokens[index-1].name == 'SUB' and int(token.lex) > 2147483648:
return
(
None
,
"
integer too small
"
)
#
return (None, "integer too small")
elif
token
.
name
==
'
NUM
'
and
int
(
token
.
lex
)
>
2147483647
and
(
index
is
0
or
tokens
[
index
-
1
].
name
is
not
'
SUB
'
):
#
elif token.name == 'NUM' and int(token.lex) > 2147483647 and (index is 0 or tokens[index-1].name is not 'SUB'):
return
(
None
,
"
interger too large
"
)
#
return (None, "interger too large")
# dealing with keywords in Java but not in Joos
# dealing with keywords in Java but not in Joos
...
@@ -511,6 +509,8 @@ def scan(input):
...
@@ -511,6 +509,8 @@ def scan(input):
# TODO: need to figure out what is allowed in compID and refactor this checking for explicit this calls
# TODO: need to figure out what is allowed in compID and refactor this checking for explicit this calls
elif
token
.
name
==
'
ID
'
and
token
.
lex
is
'
this
'
:
elif
token
.
name
==
'
ID
'
and
token
.
lex
is
'
this
'
:
return
(
None
,
"
explicit this call not allowed
"
)
return
(
None
,
"
explicit this call not allowed
"
)
elif
token
.
name
==
'
ID
'
and
token
.
lex
is
'
super
'
:
return
(
None
,
"
explicit super call not allowed
"
)
# Checking wrong keywords in compIDs
# Checking wrong keywords in compIDs
elif
token
.
name
==
'
COMPID
'
:
elif
token
.
name
==
'
COMPID
'
:
...
@@ -539,4 +539,11 @@ def scan(input):
...
@@ -539,4 +539,11 @@ def scan(input):
# remove whitespace, newline characters and comments
# remove whitespace, newline characters and comments
tokens
=
list
(
filter
(
lambda
t
:
t
.
name
not
in
(
"
WHITESPACE
"
,
"
COMMENT
"
,
'
LCOMMENT
'
,
'
RCOMMENT
'
,
'
NEWLINE
'
,
'
NEWLINEC
'
,
'
LCOM2
'
,
'
LCOM3
'
),
tokens
))
tokens
=
list
(
filter
(
lambda
t
:
t
.
name
not
in
(
"
WHITESPACE
"
,
"
COMMENT
"
,
'
LCOMMENT
'
,
'
RCOMMENT
'
,
'
NEWLINE
'
,
'
NEWLINEC
'
,
'
LCOM2
'
,
'
LCOM3
'
),
tokens
))
for
index
,
token
in
enumerate
(
tokens
):
# Checking integer range (does not cover all edge cases)
if
token
.
name
==
'
NUM
'
and
index
>
0
and
tokens
[
index
-
1
].
name
==
'
SUB
'
and
int
(
token
.
lex
)
>
2147483648
:
return
(
None
,
"
integer too small
"
)
elif
token
.
name
==
'
NUM
'
and
int
(
token
.
lex
)
>
2147483647
and
(
index
is
0
or
tokens
[
index
-
1
].
name
is
not
'
SUB
'
):
return
(
None
,
"
interger too large
"
)
return
(
tokens
,
"
success
"
)
return
(
tokens
,
"
success
"
)
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