From 1099f260d7387ed8f868fb6e9dd50e0ef4078a8d Mon Sep 17 00:00:00 2001 From: Clemens-Dautermann Date: Mon, 17 Aug 2020 01:33:38 +0200 Subject: [PATCH] added check before removing trailing { or ; --- .../.idea.Compiler/.idea/contentModel.xml | 4 +- .../.idea/.idea.Compiler/.idea/workspace.xml | 72 ++++++++----------- Compiler/Parser/Parser.cs | 11 +++ 3 files changed, 42 insertions(+), 45 deletions(-) diff --git a/Compiler/.idea/.idea.Compiler/.idea/contentModel.xml b/Compiler/.idea/.idea.Compiler/.idea/contentModel.xml index 5f284c9..dc3a832 100644 --- a/Compiler/.idea/.idea.Compiler/.idea/contentModel.xml +++ b/Compiler/.idea/.idea.Compiler/.idea/contentModel.xml @@ -1,8 +1,8 @@ - - + + diff --git a/Compiler/.idea/.idea.Compiler/.idea/workspace.xml b/Compiler/.idea/.idea.Compiler/.idea/workspace.xml index 99af283..bb38169 100644 --- a/Compiler/.idea/.idea.Compiler/.idea/workspace.xml +++ b/Compiler/.idea/.idea.Compiler/.idea/workspace.xml @@ -20,25 +20,9 @@ - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + @@ -125,7 +109,7 @@ - + @@ -147,6 +131,7 @@ + @@ -160,11 +145,12 @@ + - @@ -281,10 +267,10 @@ - - + + - + @@ -297,13 +283,13 @@ - + - - - + + + - + \ No newline at end of file diff --git a/Compiler/Parser/Parser.cs b/Compiler/Parser/Parser.cs index 9e180e3..9f912be 100644 --- a/Compiler/Parser/Parser.cs +++ b/Compiler/Parser/Parser.cs @@ -73,6 +73,11 @@ namespace Compiler.Parser n.Children.Add(Parse(ref tokenList, NodeType.StatementNode)); //remove trailing } + if (tokenList[0].TokenType != TokenType.CloseBraceToken) + { + throw new UnexpectedTokenException(TokenType.CloseBraceToken, tokenList[0].TokenType); + } + tokenList.RemoveAt(0); break; case NodeType.StatementNode: @@ -93,6 +98,12 @@ namespace Compiler.Parser //add returned child node to AST n.Children.Add(Parse(ref tokenList, NodeType.ExpressionNode)); //remove trailing ; + + if (tokenList[0].TokenType != TokenType.SemicolonToken) + { + throw new UnexpectedTokenException(TokenType.SemicolonToken, tokenList[0].TokenType); + } + tokenList.RemoveAt(0); }