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
f49360ed
Commit
f49360ed
authored
6 years ago
by
mutantoe
Browse files
Options
Downloads
Patches
Plain Diff
Started work on exec()
parent
7c93e23f
No related branches found
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
+30
-4
30 additions, 4 deletions
wk2/Java/src/jrr1g18/bb/Interpreter.java
with
30 additions
and
4 deletions
wk2/Java/src/jrr1g18/bb/Interpreter.java
+
30
−
4
View file @
f49360ed
package
jrr1g18.bb
;
import
java.util.ArrayList
;
import
java.util.Map
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
...
...
@@ -69,5 +70,30 @@ public class Interpreter {
return
token
;
}
public
void
exec
()
{
ArrayList
<
Token
>
tokenHistory
=
new
ArrayList
<
Token
>();
Token
lookahead
;
int
stmt_begin
=
0
;
int
stmt_end
=
0
;
while
(
true
){
// Find next statement
stmt_begin
=
stmt_end
+
1
;
do
{
++
stmt_end
;
lookahead
=
getNextToken
();
tokenHistory
.
add
(
lookahead
);
}
while
(
lookahead
.
getType
()!=
TokenType
.
SEMICOLON
);
// Run statement
for
(
int
stmt_idx
=
stmt_begin
;
stmt_idx
<
stmt_end
;
stmt_idx
++)
{
Token
currentToken
=
tokenHistory
.
get
(
stmt_idx
);
switch
(
currentToken
.
getType
())
{
case
CLEAR:
default
:
throw
new
IllegalStateException
(
"Illegal token type: "
+
Token
.
tokenTypeToString
(
currentToken
.
getType
()));
}
}
}
}
}
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