Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
Week 2
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
jrr1g18-space-cadets
Week 2
Commits
f7cc44ba
Commit
f7cc44ba
authored
6 years ago
by
mutantoe
Browse files
Options
Downloads
Patches
Plain Diff
Moved some code in the interpreter
parent
a5b295a4
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
wk2/Java/src/jrr1g18/bb/Interpreter.java
+19
-17
19 additions, 17 deletions
wk2/Java/src/jrr1g18/bb/Interpreter.java
with
19 additions
and
17 deletions
wk2/Java/src/jrr1g18/bb/Interpreter.java
+
19
−
17
View file @
f7cc44ba
...
...
@@ -111,27 +111,29 @@ public class Interpreter {
// Run statement
int
stmt_len
=
stmt_end
-
stmt_begin
;
Token
currentToken
=
tokenHistory
.
get
(
stmt_begin
);
int
setVarTo
;
switch
(
currentToken
.
getType
())
{
case
CLEAR:
case
INCR:
case
DECR:
if
(
stmt_len
==
3
&&
tokenHistory
.
get
(
stmt_begin
+
1
).
getType
()==
TokenType
.
IDENTIFIER
){
ValueToken
token
=
(
ValueToken
)
tokenHistory
.
get
(
stmt_begin
+
1
);
if
(
m_variables
.
containsKey
(
token
.
getValue
()))
{
m_variables
.
replace
(
token
.
getValue
(),
0
);
}
else
{
m_variables
.
put
(
token
.
getValue
(),
0
);
}
}
else
{
throw
new
Exception
(
"Nonsense statement."
);
}
switch
(
currentToken
.
getType
())
{
case
CLEAR:
setVarTo
=
0
;
break
;
case
INCR:
if
(
stmt_len
==
3
&&
tokenHistory
.
get
(
stmt_begin
+
1
).
getType
()==
TokenType
.
IDENTIFIER
){
ValueToken
token
=
(
ValueToken
)
tokenHistory
.
get
(
stmt_begin
+
1
);
setVarTo
=
m_variables
.
get
(
token
.
getValue
())+
1
;
break
;
case
DECR:
setVarTo
=
m_variables
.
get
(
token
.
getValue
())-
1
;
default
:
throw
new
Exception
(
"How did you even get here?"
);
}
if
(
m_variables
.
containsKey
(
token
.
getValue
()))
{
m_variables
.
replace
(
token
.
getValue
(),
m_variables
.
get
(
token
.
getValue
())+
1
);
m_variables
.
replace
(
token
.
getValue
(),
0
);
}
else
{
throw
new
Exception
(
"Undefined variable."
);
m_variables
.
put
(
token
.
getValue
(),
0
);
}
}
else
{
throw
new
Exception
(
"Nonsense statement."
);
...
...
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