From 6b7fdd3bb0647e2dc006e6211600be1ea4297e69 Mon Sep 17 00:00:00 2001 From: simonkellet Date: Fri, 23 Sep 2022 15:32:37 +0100 Subject: [PATCH] added multi-line comment support --- .../java/triangle/syntacticAnalyzer/Scanner.java | 14 +++++++++++++- tam | 6 ++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Triangle.Compiler/src/main/java/triangle/syntacticAnalyzer/Scanner.java b/Triangle.Compiler/src/main/java/triangle/syntacticAnalyzer/Scanner.java index ce16357..b43b303 100644 --- a/Triangle.Compiler/src/main/java/triangle/syntacticAnalyzer/Scanner.java +++ b/Triangle.Compiler/src/main/java/triangle/syntacticAnalyzer/Scanner.java @@ -84,6 +84,18 @@ public final class Scanner { } break; + // new type of comment, the multi-line $ comment + case '$':{ + takeIt(); + //check if it is not the comment char or EOT, skipping new lines (no EOL) + while((currentChar != '$') && (currentChar != SourceFile.EOT)) + takeIt(); + //if we reach another $, takeIt and move on, we've reached the end of the multi-line comment + if(currentChar == '$') + takeIt(); + } + break; + // whitespace case ' ': case '\n': @@ -262,7 +274,7 @@ public final class Scanner { currentlyScanningToken = false; // skip any whitespace or comments while (currentChar == '!' || currentChar == ' ' || currentChar == '\n' || currentChar == '\r' - || currentChar == '\t' || currentChar == '#') + || currentChar == '\t' || currentChar == '#' || currentChar == '$') scanSeparator(); currentlyScanningToken = true; diff --git a/tam b/tam index eabc885..ca8b78c 100755 --- a/tam +++ b/tam @@ -15,13 +15,15 @@ if [ -z "$1" ] fi printf "${GRN}[INFO] Compiling file: $1.tri to $1.tam ...${NC}\n" + # Compile to tam -#java -cp build/libs/Triangle-Tools.jar triangle.Compiler programs/$1.tri -o=$1.tam &> /dev/null #Quiet output, not handy! -if java -cp build/libs/Triangle-Tools.jar triangle.Compiler programs/$1.tri -o=$1.tam +if java -cp build/libs/Triangle-Tools.jar triangle.Compiler programs/$1.tri -o=$1.tam &> /dev/null #quiet then printf "${GRN}[INFO] Running file: $1.tam ...${NC}\n" java -cp build/libs/Triangle-Tools.jar triangle.abstractMachine.Interpreter $1.tam else printf "${RED}[ERROR] Could not complie $1.tri ...${NC}" + err=$(java -cp build/libs/Triangle-Tools.jar triangle.Compiler programs/$1.tri -o=$1.tam) + printf "${RED}\n$err\n${NC}" exit 1 fi