Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/classroom.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Autograding Tests
'on':
- workflow_dispatch
- repository_dispatch
permissions:
checks: write
actions: read
contents: read
jobs:
run-autograding-tests:
runs-on: ubuntu-latest
if: github.actor != 'github-classroom[bot]'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Scanner Test
id: scanner-test
uses: classroom-resources/autograding-command-grader@v1
with:
test-name: Scanner Test
setup-command: ''
command: gradle test
timeout: 10
- name: Autograding Reporter
uses: classroom-resources/autograding-grading-reporter@v1
env:
SCANNER-TEST_RESULTS: "${{steps.scanner-test.outputs.result}}"
with:
runners: scanner-test
Binary file added .gradle/8.8/checksums/checksums.lock
Binary file not shown.
Binary file added .gradle/8.8/checksums/md5-checksums.bin
Binary file not shown.
Binary file added .gradle/8.8/checksums/sha1-checksums.bin
Binary file not shown.
Empty file.
Binary file added .gradle/8.8/fileChanges/last-build.bin
Binary file not shown.
Binary file added .gradle/8.8/fileHashes/fileHashes.bin
Binary file not shown.
Binary file added .gradle/8.8/fileHashes/fileHashes.lock
Binary file not shown.
Empty file added .gradle/8.8/gc.properties
Empty file.
Binary file added .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
2 changes: 2 additions & 0 deletions .gradle/buildOutputCleanup/cache.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#Mon Nov 18 13:36:26 EST 2024
gradle.version=8.8
Empty file added .gradle/vcs-1/gc.properties
Empty file.
54 changes: 40 additions & 14 deletions src/main/java/com/scanner/project/TokenStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public TokenStream(String fileName) {
input = new BufferedReader(new FileReader(fileName));
} catch (FileNotFoundException e) {
System.out.println("File not found: " + fileName);
// System.exit(1); // Removed to allow ScannerDemo to continue
System.exit(1); // Removed to allow ScannerDemo to continue
// running after the input file is not found.
isEof = true;
}
Expand All @@ -59,6 +59,10 @@ public Token nextToken() { // Main function of the scanner
// skip rest of line - it's a comment.
// TODO TO BE COMPLETED
// look for <cr>, <lf>, <ff>
while(!isEndOfLine(nextChar) && !isEof){
nextChar = readChar();
}
skipWhiteSpace();

} else {
// A slash followed by anything else must be an operator.
Expand All @@ -72,7 +76,9 @@ public Token nextToken() { // Main function of the scanner
// operators as well as 1-character ones.
if (isOperator(nextChar)) {
t.setType("Operator");
t.setValue(t.getValue() + nextChar);
char currentChar = nextChar;
nextChar = readChar();

switch (nextChar) {
// TODO TO BE COMPLETED WHERE NEEDED
case '<':
Expand All @@ -83,15 +89,20 @@ public Token nextToken() { // Main function of the scanner
// ==
case '!':
// !=
nextChar = readChar();
if (nextChar == '='){
t.setValue("" + currentChar + nextChar);
nextChar = readChar();
}else{
t.setValue("" + currentChar);
}
return t;

case '|':
// Look for ||
nextChar = readChar();
if (nextChar == '|') {
t.setValue(t.getValue() + nextChar);
t.setValue("" + currentChar + nextChar);
nextChar = readChar();
return t;
} else {
t.setType("Other");
}
Expand All @@ -101,9 +112,8 @@ public Token nextToken() { // Main function of the scanner
// Look or &&
nextChar = readChar();
if (nextChar == '&') {
t.setValue(t.getValue() + nextChar);
t.setValue("" + currentChar + nextChar);
nextChar = readChar();
return t;
} else {
t.setType("Other");
}
Expand All @@ -120,6 +130,9 @@ public Token nextToken() { // Main function of the scanner
if (isSeparator(nextChar)) {
t.setType("Separator");
// TODO TO BE COMPLETED
t.setType("Separator");
t.setValue("" + nextChar);
nextChar = readChar();
return t;
}

Expand All @@ -137,9 +150,6 @@ public Token nextToken() { // Main function of the scanner
} else if (t.getValue().equals("true") || t.getValue().equals("false")) {
t.setType("Literal");
}
if (isEndOfToken(nextChar)) { // If token is valid, returns.
return t;
}
}

if (isDigit(nextChar)) { // check for integer literals
Expand All @@ -150,9 +160,7 @@ public Token nextToken() { // Main function of the scanner
}
// An Integer-Literal is to be only followed by a space,
// an operator, or a separator.
if (isEndOfToken(nextChar)) {// If token is valid, returns.
return t;
}
return t;
}

t.setType("Other");
Expand Down Expand Up @@ -192,6 +200,12 @@ private char readChar() {

private boolean isKeyword(String s) {
// TODO TO BE COMPLETED
String[] keywords ={"if", "else", "while", "return", "int", "boolean", "void", "true", "false"};
for (String keyword : keywords){
if(keyword.equals(s)){
return true;
}
}
return false;
}

Expand All @@ -216,12 +230,24 @@ private void skipWhiteSpace() {

private boolean isSeparator(char c) {
// TODO TO BE COMPLETED
char[] separators = {';', ',', '(', ')', '{', '}', '[', ']'};
for (char separator : separators){
if (c == separator){
return true;
}
}
return false;
}

private boolean isOperator(char c) {
// Checks for characters that start operators
// TODO TO BE COMPLETED
char[] operators = {'+', '-', '*', '/', '=', '<', '>', '&', '|', '!', '%'};
for (char operator : operators){
if(c == operator){
return true;
}
}
return false;
}

Expand All @@ -231,7 +257,7 @@ private boolean isLetter(char c) {

private boolean isDigit(char c) {
// TODO TO BE COMPLETED
return false;
return c >= '0' && c <= '9';
}

public boolean isEndofFile() {
Expand Down