diff --git a/sources/zweic/Parser.scala b/sources/zweic/Parser.scala index 1ebb1ce..0f18abc 100755 --- a/sources/zweic/Parser.scala +++ b/sources/zweic/Parser.scala @@ -50,38 +50,43 @@ * If the current token corresponds to the token class 'expected' * then skip it and return success. */ - private def check(expected: Token): Boolean = + private def check(expected: Token): Boolean = { if (token == expected) { nextToken; true - } else + } else { false; + } + } override def nextToken: Unit = { - pushedBack match { - case Some(Triple(p, c, t)) => - token = t; - chars = c; - pos = p; - pushedBack = None; - case _ => return super.nextToken; - } + if (debug == true) { + Console.print (" " + token); + } + pushedBack match { + case Some(Triple(p, c, t)) => + token = t; + chars = c; + pos = p; + pushedBack = None; + case _ => return super.nextToken; + } } def peekAhead: Token = pushedBack match { - case Some(Triple(p, c, t)) => - return t; - case _ => - val savedToken = token; - val savedChars = chars; - val savedPos = pos; - nextToken; - val rval = token; - pushedBack = Some(Triple(pos, chars, token)); - token = savedToken; - chars = savedChars; - pos = savedPos; - return rval; + case Some(Triple(p, c, t)) => + return t; + case _ => + val savedToken = token; + val savedChars = chars; + val savedPos = pos; + nextToken; + val rval = token; + pushedBack = Some(Triple(pos, chars, token)); + token = savedToken; + chars = savedChars; + pos = savedPos; + return rval; } /** diff --git a/sources/zweic/Scanner.scala b/sources/zweic/Scanner.scala index 931a28c..b374762 100755 --- a/sources/zweic/Scanner.scala +++ b/sources/zweic/Scanner.scala @@ -14,6 +14,8 @@ * This class implements the scanner of the zwei compiler. */ class Scanner(in: InputStream) { + val debug: boolean = false; + import scala.collection.mutable.HashMap; import Tokens._; @@ -98,6 +100,9 @@ // skip comments and whitespace characters while (Character.isWhitespace (ch) || ch == '/') { + if (debug == true && ch == '\n'){ + Console.println ("") + } if (ch == '/'){ nextCh; if (ch == '/') {