Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
space-cadets
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Emily Rowlands
space-cadets
Commits
4d8d17c6
Verified
Commit
4d8d17c6
authored
6 years ago
by
Emily Rowlands
Browse files
Options
Downloads
Patches
Plain Diff
Cleaned up
parent
601b0f76
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
wk2/Java/src/jrr1g18/bb/Interpreter.java
+11
-22
11 additions, 22 deletions
wk2/Java/src/jrr1g18/bb/Interpreter.java
with
11 additions
and
22 deletions
wk2/Java/src/jrr1g18/bb/Interpreter.java
+
11
−
22
View file @
4d8d17c6
...
@@ -36,11 +36,6 @@ public class Interpreter {
...
@@ -36,11 +36,6 @@ public class Interpreter {
INCR
,
DECR
,
CLEAR
,
WHILE
,
END
,
INCR
,
DECR
,
CLEAR
,
WHILE
,
END
,
}
}
@SuppressWarnings
(
"unused"
)
private
String
instructionTypeToString
(
InstructionType
it
)
{
return
INSTRUCTION_NAMES
.
get
(
it
);
}
private
InstructionType
stringToInstructionType
(
String
instruction
)
{
private
InstructionType
stringToInstructionType
(
String
instruction
)
{
for
(
Entry
<
InstructionType
,
String
>
entry
:
INSTRUCTION_NAMES
for
(
Entry
<
InstructionType
,
String
>
entry
:
INSTRUCTION_NAMES
.
entrySet
())
{
.
entrySet
())
{
...
@@ -73,23 +68,23 @@ public class Interpreter {
...
@@ -73,23 +68,23 @@ public class Interpreter {
return
m_code
.
get
(
line
);
return
m_code
.
get
(
line
);
}
}
private
String
[]
splitLine
(
String
line
)
{
private
static
String
[]
splitLine
(
String
line
)
{
return
stripWhitespace
(
line
).
split
(
"\\s+"
);
return
stripWhitespace
(
line
).
split
(
"\\s+"
);
}
}
private
String
[]
getSplitLine
(
int
line
)
{
return
splitLine
(
getLine
(
line
));
}
public
static
String
stripWhitespace
(
String
str
)
{
public
static
String
stripWhitespace
(
String
str
)
{
return
str
.
replaceAll
(
"(^\\s+|\\s+$)"
,
""
);
return
str
.
replaceAll
(
"(^\\s+|\\s+$)"
,
""
);
}
}
private
String
[]
getSplitLine
(
int
line
)
{
return
splitLine
(
getLine
(
line
));
}
private
boolean
isVariableNull
(
String
name
)
{
private
boolean
isVariableNull
(
String
name
)
{
return
m_vars
.
get
(
name
)
==
null
;
return
m_vars
.
get
(
name
)
==
null
;
}
}
private
void
codeCheck
()
{
private
void
validateCode
()
{
String
line
;
String
line
;
String
[]
splitLine
;
String
[]
splitLine
;
int
whileDepth
=
0
;
int
whileDepth
=
0
;
...
@@ -127,18 +122,14 @@ public class Interpreter {
...
@@ -127,18 +122,14 @@ public class Interpreter {
switch
(
instruction
)
{
switch
(
instruction
)
{
case
WHILE:
case
WHILE:
whileDepth
++;
whileDepth
++;
splitLine
[
4
]
=
splitLine
[
1
].
replace
(
if
(!
splitLine
[
2
].
equals
(
"not"
)
||
splitLine
.
length
>
5
)
{
splitLine
[
1
].
substring
(
splitLine
[
1
].
length
()
-
1
),
""
);
if
(!
splitLine
[
2
].
equals
(
"not"
)
||
splitLine
[
4
].
equals
(
"do"
)
||
splitLine
.
length
>
5
)
{
System
.
err
.
println
(
"Syntax error on line "
+
(
idx
+
1
));
System
.
err
.
println
(
"Syntax error on line "
+
(
idx
+
1
));
System
.
exit
(
1
);
System
.
exit
(
1
);
}
}
break
;
break
;
case
END:
case
END:
whileDepth
--;
whileDepth
--;
if
(
splitLine
[
0
].
equals
(
"end;"
)
&&
splitLine
.
length
>
1
)
{
if
(
splitLine
.
length
>
1
)
{
System
.
err
.
println
(
"Syntax error on line "
+
(
idx
+
1
));
System
.
err
.
println
(
"Syntax error on line "
+
(
idx
+
1
));
System
.
exit
(
1
);
System
.
exit
(
1
);
}
}
...
@@ -150,11 +141,9 @@ public class Interpreter {
...
@@ -150,11 +141,9 @@ public class Interpreter {
}
}
if
(
whileDepth
>
0
)
{
if
(
whileDepth
>
0
)
{
System
.
err
.
println
(
System
.
err
.
println
(
"Syntax error: unclosed while"
);
"There are more while statements than end statements"
);
}
else
if
(
whileDepth
<
0
)
{
}
else
if
(
whileDepth
<
0
)
{
System
.
err
.
println
(
System
.
err
.
println
(
"Syntax error: overclosed while"
);
"There are more end statements than while statements"
);
}
}
}
}
...
@@ -172,7 +161,7 @@ public class Interpreter {
...
@@ -172,7 +161,7 @@ public class Interpreter {
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
codeCheck
();
validateCode
();
exec
();
exec
();
}
}
...
...
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