diff options
author | AidenRushbrooke <72034940+AidenRushbrooke@users.noreply.github.com> | 2021-11-20 02:24:52 +0000 |
---|---|---|
committer | AidenRushbrooke <72034940+AidenRushbrooke@users.noreply.github.com> | 2021-11-20 02:24:52 +0000 |
commit | 68f651f90ac9bb42e6fcb461f72f82ee74df1fdd (patch) | |
tree | a94d69ae43cdc92395f1dbac3160bb4d45baa570 /src/Compiler/Parser.java | |
parent | 286e177e603d57d445393a0f4899bf7a17a4c31d (diff) | |
download | esotericFORTRAN-68f651f90ac9bb42e6fcb461f72f82ee74df1fdd.tar.gz esotericFORTRAN-68f651f90ac9bb42e6fcb461f72f82ee74df1fdd.zip |
Added initial support for do while loops
Diffstat (limited to 'src/Compiler/Parser.java')
-rw-r--r-- | src/Compiler/Parser.java | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/Compiler/Parser.java b/src/Compiler/Parser.java index 5288c67..8bb8951 100644 --- a/src/Compiler/Parser.java +++ b/src/Compiler/Parser.java @@ -122,6 +122,9 @@ public class Parser { } private Statement doStatement(){ + if(matchAndAdvance(TokenType.WHILE)){ + return whileStatement(); + } Expression variable =expression(); matchOrError(TokenType.EQUALS, "'=' missing"); Expression start = expression(); @@ -137,6 +140,15 @@ public class Parser { } + private Statement whileStatement(){ + matchOrError(TokenType.LEFT_PAREN, " missing '("); + Expression condition = expression(); + matchOrError(TokenType.RIGHT_PAREN, " missing ')"); + Statement.BlockStatement codeBlock = blockStatement(); + matchOrError(TokenType.DO, "Do while statements end with do"); + return new Statement.DoWhileStatement(condition,codeBlock); + } + private Statement expressionStatement(){ Expression expression = assignment(); return new Statement.ExpressionStatement(expression); |