From a953d2aa2f8c1d4b77b68ec9636e7272bdc5552a Mon Sep 17 00:00:00 2001 From: Anthony Sap <115178622+asapor1@users.noreply.github.com> Date: Fri, 31 Mar 2023 00:49:11 -0400 Subject: [PATCH] Update Parser.java It is done, I just can't get the Do Until to not execute in While loop --- src/compiler/Parser.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/compiler/Parser.java b/src/compiler/Parser.java index 3210752..16ea0a2 100644 --- a/src/compiler/Parser.java +++ b/src/compiler/Parser.java @@ -98,6 +98,7 @@ private void STMT_LIST(final TreeNode parentNode) throws ParseException { list.add(Token.READ); list.add(Token.IF); list.add(Token.WHILE); + list.add(Token.DO); if(list.contains(lexer.currentToken())) { @@ -132,25 +133,27 @@ else if (lexer.currentToken() == Token.IF) { this.CONDITION(thisNode); this.MATCH(thisNode, Token.THEN); this.STMT_LIST(thisNode); + if (lexer.currentToken() == Token.ELSE) { this.MATCH(thisNode, Token.ELSE); this.STMT_LIST(thisNode); } + this.MATCH(thisNode, Token.FI); } - else if (lexer.currentToken() == Token.WHILE){ + else if (lexer.currentToken() == Token.DO) { //Meaning this is do until + this.MATCH(thisNode, Token.DO); //It annoys me I don't know how to implement it not being in a while loop + this.STMT_LIST(thisNode); + this.MATCH(thisNode, Token.UNTIL); + this.CONDITION(thisNode); + } + else{ //Meaning this is a while loop this.MATCH(thisNode, Token.WHILE); this.CONDITION(thisNode); this.MATCH(thisNode, Token.DO); this.STMT_LIST(thisNode); this.MATCH(thisNode, Token.OD); } - else if (lexer.currentToken() == Token.DO) { //Meaning this is do until - this.MATCH(thisNode, Token.DO); - this.STMT_LIST(thisNode); - this.MATCH(thisNode, Token.UNTIL); - this.CONDITION(thisNode); - } } // ::=