From 19ab22324a59cb09bd328d3422ab93f7f7c43167 Mon Sep 17 00:00:00 2001 From: Stepami Date: Fri, 9 Sep 2022 16:40:19 +0300 Subject: [PATCH 01/56] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=B5=D0=B7?= =?UTF-8?q?=D0=B4=20=D0=BD=D0=B0=20.net=206?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Interpreter.Lib/Interpreter.Lib.csproj | 2 +- Interpreter.Tests/Interpreter.Tests.csproj | 2 +- Interpreter/Interpreter.csproj | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Interpreter.Lib/Interpreter.Lib.csproj b/Interpreter.Lib/Interpreter.Lib.csproj index 02de8607..af6168a4 100644 --- a/Interpreter.Lib/Interpreter.Lib.csproj +++ b/Interpreter.Lib/Interpreter.Lib.csproj @@ -1,7 +1,7 @@ - net5.0 + net6.0 diff --git a/Interpreter.Tests/Interpreter.Tests.csproj b/Interpreter.Tests/Interpreter.Tests.csproj index 52edf26f..19f1a28c 100644 --- a/Interpreter.Tests/Interpreter.Tests.csproj +++ b/Interpreter.Tests/Interpreter.Tests.csproj @@ -1,7 +1,7 @@ - net5.0 + net6.0 false diff --git a/Interpreter/Interpreter.csproj b/Interpreter/Interpreter.csproj index baea5a3a..1f9e2e09 100644 --- a/Interpreter/Interpreter.csproj +++ b/Interpreter/Interpreter.csproj @@ -2,7 +2,7 @@ Exe - net5.0 + net6.0 1.0.2 From 4bac666a93d907651872a6d6364986e4e4c9674e Mon Sep 17 00:00:00 2001 From: Stepami Date: Fri, 9 Sep 2022 16:40:36 +0300 Subject: [PATCH 02/56] =?UTF-8?q?=D1=80=D0=B5=D1=84=D0=B0=D0=BA=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=B8=D0=BD=D0=B3=20=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=B8=20=D1=82=D0=B8=D0=BF=D0=B0=20=D1=82=D0=BE=D0=BA=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RBNF/Analysis/Lexical/Lexer.cs | 2 +- .../Lexical/TokenTypes/EndOfProgramType.cs | 16 +------- .../Analysis/Lexical/TokenTypes/ErrorType.cs | 16 +------- .../Analysis/Lexical/TokenTypes/TokenType.cs | 40 +++---------------- .../Lexical/TokenTypes/WhiteSpaceType.cs | 10 +---- 5 files changed, 11 insertions(+), 73 deletions(-) diff --git a/Interpreter.Lib/RBNF/Analysis/Lexical/Lexer.cs b/Interpreter.Lib/RBNF/Analysis/Lexical/Lexer.cs index 4b849f68..0dc3edea 100644 --- a/Interpreter.Lib/RBNF/Analysis/Lexical/Lexer.cs +++ b/Interpreter.Lib/RBNF/Analysis/Lexical/Lexer.cs @@ -44,7 +44,7 @@ public IEnumerator GetEnumerator() ); var token = new Token(type, segment, value); - if (type == LexerUtils.Error) throw new LexerException(token); + if (type.Error()) throw new LexerException(token); yield return token; } diff --git a/Interpreter.Lib/RBNF/Analysis/Lexical/TokenTypes/EndOfProgramType.cs b/Interpreter.Lib/RBNF/Analysis/Lexical/TokenTypes/EndOfProgramType.cs index b7789c03..698497ee 100644 --- a/Interpreter.Lib/RBNF/Analysis/Lexical/TokenTypes/EndOfProgramType.cs +++ b/Interpreter.Lib/RBNF/Analysis/Lexical/TokenTypes/EndOfProgramType.cs @@ -1,19 +1,7 @@ namespace Interpreter.Lib.RBNF.Analysis.Lexical.TokenTypes { - internal record EndOfProgramType : TokenType + internal record EndOfProgramType() : TokenType("EOP", "", int.MaxValue - 1) { - public EndOfProgramType() : base("EOP", "", int.MaxValue - 1) - { - } - - public override bool EndOfProgram() - { - return true; - } - - public override string ToString() - { - return Tag; - } + public override bool EndOfProgram() => true; } } \ No newline at end of file diff --git a/Interpreter.Lib/RBNF/Analysis/Lexical/TokenTypes/ErrorType.cs b/Interpreter.Lib/RBNF/Analysis/Lexical/TokenTypes/ErrorType.cs index 01122113..9145701d 100644 --- a/Interpreter.Lib/RBNF/Analysis/Lexical/TokenTypes/ErrorType.cs +++ b/Interpreter.Lib/RBNF/Analysis/Lexical/TokenTypes/ErrorType.cs @@ -1,19 +1,7 @@ namespace Interpreter.Lib.RBNF.Analysis.Lexical.TokenTypes { - internal record ErrorType : TokenType + internal record ErrorType() : TokenType("ERROR", @"\S+", int.MaxValue) { - public ErrorType() : base("ERROR", @"\S+", int.MaxValue) - { - } - - public override bool Error() - { - return true; - } - - public override string ToString() - { - return Tag; - } + public override bool Error() => true; } } \ No newline at end of file diff --git a/Interpreter.Lib/RBNF/Analysis/Lexical/TokenTypes/TokenType.cs b/Interpreter.Lib/RBNF/Analysis/Lexical/TokenTypes/TokenType.cs index b16e2874..36e6c6b2 100644 --- a/Interpreter.Lib/RBNF/Analysis/Lexical/TokenTypes/TokenType.cs +++ b/Interpreter.Lib/RBNF/Analysis/Lexical/TokenTypes/TokenType.cs @@ -6,44 +6,14 @@ public TokenType() : this(null, null, 0) { } - public virtual bool WhiteSpace() - { - return false; - } + public virtual bool WhiteSpace() => false; - public virtual bool EndOfProgram() - { - return false; - } + public virtual bool EndOfProgram() => false; - public virtual bool Error() - { - return false; - } + public virtual bool Error() => false; - public virtual bool NonTerminal() - { - return false; - } + public string GetNamedRegex() => $"(?<{Tag}>{Pattern})"; - public virtual bool Terminal() - { - return false; - } - - public virtual bool Epsilon() - { - return false; - } - - public string GetNamedRegex() - { - return $"(?<{Tag}>{Pattern})"; - } - - public override string ToString() - { - return Tag; - } + public sealed override string ToString() => Tag; } } \ No newline at end of file diff --git a/Interpreter.Lib/RBNF/Analysis/Lexical/TokenTypes/WhiteSpaceType.cs b/Interpreter.Lib/RBNF/Analysis/Lexical/TokenTypes/WhiteSpaceType.cs index c67f1962..32f41be4 100644 --- a/Interpreter.Lib/RBNF/Analysis/Lexical/TokenTypes/WhiteSpaceType.cs +++ b/Interpreter.Lib/RBNF/Analysis/Lexical/TokenTypes/WhiteSpaceType.cs @@ -3,14 +3,6 @@ namespace Interpreter.Lib.RBNF.Analysis.Lexical.TokenTypes public record WhiteSpaceType(string Tag = null, string Pattern = null, int Priority = 0) : TokenType(Tag, Pattern, Priority) { - public override bool WhiteSpace() - { - return true; - } - - public override string ToString() - { - return Tag; - } + public override bool WhiteSpace() => true; } } \ No newline at end of file From 87e8bff85496870353783b02b543eae495e54b4c Mon Sep 17 00:00:00 2001 From: Stepami Date: Fri, 9 Sep 2022 16:41:47 +0300 Subject: [PATCH 03/56] =?UTF-8?q?=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BF=D0=B0=D0=B9=D0=BF=D0=BB=D0=B0?= =?UTF-8?q?=D0=B9=D0=BD=D0=BE=D0=B2=20=D0=B2=20=D1=81=D0=B2=D1=8F=D0=B7?= =?UTF-8?q?=D0=B8=20=D1=81=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B5=D0=B7=D0=B4?= =?UTF-8?q?=D0=BE=D0=BC=20=D0=BD=D0=B0=20=D0=BD=D0=BE=D0=B2=D1=8B=D0=B9=20?= =?UTF-8?q?.NET?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/develop.yml | 2 +- .github/workflows/release.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/develop.yml b/.github/workflows/develop.yml index ce7dbe7c..3287e8e4 100644 --- a/.github/workflows/develop.yml +++ b/.github/workflows/develop.yml @@ -18,7 +18,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v2 with: - dotnet-version: 5.0.x + dotnet-version: 6.0.x - name: Cache NuGet packages uses: actions/cache@v3 with: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3fbcd6f6..b3580a01 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -42,7 +42,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v2 with: - dotnet-version: 5.0.x + dotnet-version: 6.0.x - name: Publish run: | mkdir output From 147afcf6a6af4bff27ac908cf9c36bcbf065ff2e Mon Sep 17 00:00:00 2001 From: Stepami Date: Fri, 9 Sep 2022 17:00:45 +0300 Subject: [PATCH 04/56] Update Readme.md --- Readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Readme.md b/Readme.md index d0716191..fdd28629 100644 --- a/Readme.md +++ b/Readme.md @@ -158,7 +158,7 @@ let s = v2d as string ### Требования -- .NET 5 SDK +- .NET 6 SDK ### Сборка После клонирования репозитория идём в папку проекта `Interpreter`. @@ -171,7 +171,7 @@ let s = v2d as string ### Запуск ``` -Interpreter 1.0.0 +Interpreter 1.1.2 Copyright (C) 2022 Interpreter USAGE: Simple interpretation call: From 9ee051c3c205c345c59334c28f39853cf8d0abe0 Mon Sep 17 00:00:00 2001 From: Stepami Date: Fri, 9 Sep 2022 17:01:10 +0300 Subject: [PATCH 05/56] update version --- Interpreter/Interpreter.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Interpreter/Interpreter.csproj b/Interpreter/Interpreter.csproj index 1f9e2e09..a12630c8 100644 --- a/Interpreter/Interpreter.csproj +++ b/Interpreter/Interpreter.csproj @@ -3,7 +3,7 @@ Exe net6.0 - 1.0.2 + 1.1.2 From 7d0b232886d1623aacb7f8aeb9adf3cf1d2b3caf Mon Sep 17 00:00:00 2001 From: Stepami Date: Fri, 9 Sep 2022 17:06:19 +0300 Subject: [PATCH 06/56] =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B5=D0=BD=D0=BE?= =?UTF-8?q?=D1=81=20DoubleValueConverter=20=D0=B2=20=D1=82=D0=B5=D0=BB?= =?UTF-8?q?=D0=BE=20=D0=B8=D0=BD=D1=81=D1=82=D1=80=D1=83=D0=BA=D1=86=D0=B8?= =?UTF-8?q?=D0=B8,=20=D0=BF=D0=BE=D1=81=D0=BA=D0=BE=D0=BB=D1=8C=D0=BA?= =?UTF-8?q?=D1=83=20=D0=BE=D0=BD=20=D0=B8=D1=81=D0=BF=D0=BE=D0=BB=D1=8C?= =?UTF-8?q?=D0=B7=D1=83=D0=B5=D1=82=D1=81=D1=8F=20=D1=82=D0=BE=D0=BB=D1=8C?= =?UTF-8?q?=D0=BA=D0=BE=20=D1=82=D0=B0=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Interpreter.Lib/DoubleValueConverter.cs | 24 --------------------- Interpreter.Lib/IR/Instructions/AsString.cs | 17 +++++++++++++++ 2 files changed, 17 insertions(+), 24 deletions(-) delete mode 100644 Interpreter.Lib/DoubleValueConverter.cs diff --git a/Interpreter.Lib/DoubleValueConverter.cs b/Interpreter.Lib/DoubleValueConverter.cs deleted file mode 100644 index 877005fa..00000000 --- a/Interpreter.Lib/DoubleValueConverter.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using Newtonsoft.Json; - -namespace Interpreter.Lib -{ - public class DoubleValueConverter : JsonConverter - { - public override bool CanRead => false; - - public override void WriteJson(JsonWriter writer, double value, JsonSerializer serializer) - { - // ReSharper disable once CompareOfFloatsByEqualityOperator - writer.WriteRawValue(value == Math.Truncate(value) - ? JsonConvert.ToString(Convert.ToInt64(value)) - : JsonConvert.ToString(value)); - } - - public override double ReadJson(JsonReader reader, Type objectType, double existingValue, bool hasExistingValue, - JsonSerializer serializer) - { - throw new NotImplementedException("CanRead is false, so reading is unnecessary"); - } - } -} \ No newline at end of file diff --git a/Interpreter.Lib/IR/Instructions/AsString.cs b/Interpreter.Lib/IR/Instructions/AsString.cs index 9a30be21..0f290169 100644 --- a/Interpreter.Lib/IR/Instructions/AsString.cs +++ b/Interpreter.Lib/IR/Instructions/AsString.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using Interpreter.Lib.VM; using Interpreter.Lib.VM.Values; @@ -35,5 +36,21 @@ public override int Execute(VirtualMachine vm) } protected override string ToStringRepresentation() => $"{Left} = {right.right} as string"; + + private class DoubleValueConverter : JsonConverter + { + public override bool CanRead => false; + + public override void WriteJson(JsonWriter writer, double value, JsonSerializer serializer) => + // ReSharper disable once CompareOfFloatsByEqualityOperator + writer.WriteRawValue(value == Math.Truncate(value) + ? JsonConvert.ToString(Convert.ToInt64(value)) + : JsonConvert.ToString(value)); + + public override double ReadJson(JsonReader reader, Type objectType, + double existingValue, bool hasExistingValue, + JsonSerializer serializer) => + throw new NotImplementedException("CanRead is false, so reading is unnecessary"); + } } } \ No newline at end of file From 295c55661b2b0ab8595230a0b040c4dc3a28a554 Mon Sep 17 00:00:00 2001 From: Stepami Date: Sat, 10 Sep 2022 17:20:58 +0300 Subject: [PATCH 07/56] =?UTF-8?q?=D0=A7=D0=B5=D1=80=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=B8=D0=BA=20=D0=BA=D0=BE=D0=BD=D1=82=D1=80=D0=B0=D0=BA=D1=82?= =?UTF-8?q?=D0=BE=D0=B2=20front-end'=D0=B0=20=D0=B8=D0=BD=D1=82=D0=B5?= =?UTF-8?q?=D1=80=D0=BF=D1=80=D0=B5=D1=82=D0=B0=D1=82=D0=BE=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Interpreter.Lib/Contracts/IAbstractSyntaxTree.cs | 6 ++++++ Interpreter.Lib/Contracts/ILexer.cs | 12 ++++++++++++ Interpreter.Lib/Contracts/IParser.cs | 7 +++++++ 3 files changed, 25 insertions(+) create mode 100644 Interpreter.Lib/Contracts/IAbstractSyntaxTree.cs create mode 100644 Interpreter.Lib/Contracts/ILexer.cs create mode 100644 Interpreter.Lib/Contracts/IParser.cs diff --git a/Interpreter.Lib/Contracts/IAbstractSyntaxTree.cs b/Interpreter.Lib/Contracts/IAbstractSyntaxTree.cs new file mode 100644 index 00000000..235bafb9 --- /dev/null +++ b/Interpreter.Lib/Contracts/IAbstractSyntaxTree.cs @@ -0,0 +1,6 @@ +namespace Interpreter.Lib.Contracts +{ + public interface IAbstractSyntaxTree + { + } +} \ No newline at end of file diff --git a/Interpreter.Lib/Contracts/ILexer.cs b/Interpreter.Lib/Contracts/ILexer.cs new file mode 100644 index 00000000..2280a3f9 --- /dev/null +++ b/Interpreter.Lib/Contracts/ILexer.cs @@ -0,0 +1,12 @@ +using System.Collections.Generic; +using Interpreter.Lib.RBNF.Analysis.Lexical; + +namespace Interpreter.Lib.Contracts +{ + public interface ILexer + { + Structure Structure { get; } + + IEnumerable GetTokens(string text); + } +} \ No newline at end of file diff --git a/Interpreter.Lib/Contracts/IParser.cs b/Interpreter.Lib/Contracts/IParser.cs new file mode 100644 index 00000000..47a69c2a --- /dev/null +++ b/Interpreter.Lib/Contracts/IParser.cs @@ -0,0 +1,7 @@ +namespace Interpreter.Lib.Contracts +{ + public interface IParser + { + IAbstractSyntaxTree TopDownParse(string text); + } +} \ No newline at end of file From 5e3176c072dbe07efe642ac3d42f28219df83136 Mon Sep 17 00:00:00 2001 From: Stepami Date: Sat, 10 Sep 2022 18:09:40 +0300 Subject: [PATCH 08/56] =?UTF-8?q?=D0=BA=D0=B0=D1=80=D0=BA=D0=B0=D1=81=20?= =?UTF-8?q?=D1=81=D1=83=D1=89=D0=BD=D0=BE=D1=81=D1=82=D0=B8=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D0=B2=D0=BD=D1=83=D1=82=D1=80=D0=B5=D0=BD=D0=BD=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D0=B5=D0=B9=20=D0=BF=D0=B0=D1=80=D1=81=D0=B5=D1=80?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Interpreter.Lib/Contracts/ILexer.cs | 2 +- Interpreter.Lib/Contracts/TokensStream.cs | 26 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 Interpreter.Lib/Contracts/TokensStream.cs diff --git a/Interpreter.Lib/Contracts/ILexer.cs b/Interpreter.Lib/Contracts/ILexer.cs index 2280a3f9..6acbd590 100644 --- a/Interpreter.Lib/Contracts/ILexer.cs +++ b/Interpreter.Lib/Contracts/ILexer.cs @@ -7,6 +7,6 @@ public interface ILexer { Structure Structure { get; } - IEnumerable GetTokens(string text); + List GetTokens(string text); } } \ No newline at end of file diff --git a/Interpreter.Lib/Contracts/TokensStream.cs b/Interpreter.Lib/Contracts/TokensStream.cs new file mode 100644 index 00000000..4c8bdb81 --- /dev/null +++ b/Interpreter.Lib/Contracts/TokensStream.cs @@ -0,0 +1,26 @@ +using System.Collections; +using System.Collections.Generic; +using Interpreter.Lib.RBNF.Analysis.Lexical; + +namespace Interpreter.Lib.Contracts; + +public class TokensStream : IEnumerator +{ + private readonly IEnumerator _inner; + + private TokensStream(IEnumerator enumerator) => + _inner = enumerator; + + public bool MoveNext() => _inner.MoveNext(); + + public void Reset() => _inner.Reset(); + + public Token Current => _inner.Current; + + object IEnumerator.Current => Current; + + public void Dispose() => _inner.Dispose(); + + public static implicit operator TokensStream(List tokens) => + new (tokens.GetEnumerator()); +} \ No newline at end of file From a09bc1fefc8da5ec26d9193f48efc6dbea1d0342 Mon Sep 17 00:00:00 2001 From: Stepami Date: Mon, 12 Sep 2022 11:06:46 +0300 Subject: [PATCH 09/56] =?UTF-8?q?=D1=80=D0=B5=D0=BE=D1=80=D0=B3=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20=D0=BF=D0=B0=D0=BF?= =?UTF-8?q?=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Interpreter.Lib/Contracts/IAbstractSyntaxTree.cs | 4 ++++ Interpreter.Lib/Contracts/ILexer.cs | 2 +- Interpreter.Lib/Contracts/TokensStream.cs | 2 +- .../{RBNF/Analysis/Lexical => FrontEnd/Lex}/Coordinates.cs | 2 +- .../{RBNF/Analysis/Lexical => FrontEnd/Lex}/Lexer.cs | 4 +--- .../Analysis/Exceptions => FrontEnd/Lex}/LexerException.cs | 3 +-- Interpreter.Lib/{RBNF/Utils => FrontEnd/Lex}/LexerUtils.cs | 4 ++-- .../{RBNF/Analysis/Lexical => FrontEnd/Lex}/Segment.cs | 2 +- .../{RBNF/Analysis/Lexical => FrontEnd/Lex}/Structure.cs | 5 ++--- .../{RBNF/Analysis/Lexical => FrontEnd/Lex}/Token.cs | 4 ++-- .../Lexical => FrontEnd/Lex}/TokenTypes/EndOfProgramType.cs | 2 +- .../Lexical => FrontEnd/Lex}/TokenTypes/ErrorType.cs | 2 +- .../Lexical => FrontEnd/Lex}/TokenTypes/TokenType.cs | 2 +- .../Lexical => FrontEnd/Lex}/TokenTypes/WhiteSpaceType.cs | 2 +- .../{RBNF/Analysis/Syntactic => FrontEnd/Parse}/Parser.cs | 5 ++--- .../Exceptions => FrontEnd/Parse}/ParserException.cs | 4 ++-- Interpreter.Lib/Interpreter.Lib.csproj | 4 ---- Interpreter.Lib/Semantic/Exceptions/ArrayAccessException.cs | 2 +- Interpreter.Lib/Semantic/Exceptions/CannotDefineType.cs | 2 +- .../Semantic/Exceptions/FunctionWithoutReturnStatement.cs | 2 +- .../Semantic/Exceptions/IncompatibleTypesOfOperands.cs | 2 +- .../Semantic/Exceptions/NotBooleanTestExpression.cs | 2 +- Interpreter.Lib/Semantic/Exceptions/ObjectAccessException.cs | 2 +- Interpreter.Lib/Semantic/Exceptions/OutsideOfLoop.cs | 2 +- Interpreter.Lib/Semantic/Exceptions/ReturnOutsideFunction.cs | 2 +- Interpreter.Lib/Semantic/Exceptions/SymbolIsNotCallable.cs | 2 +- Interpreter.Lib/Semantic/Exceptions/UnsupportedOperation.cs | 2 +- .../Semantic/Exceptions/WrongArrayLiteralDeclaration.cs | 2 +- Interpreter.Lib/Semantic/Exceptions/WrongConditionalTypes.cs | 2 +- .../Semantic/Exceptions/WrongNumberOfArguments.cs | 2 +- Interpreter.Lib/Semantic/Exceptions/WrongReturnType.cs | 2 +- Interpreter.Lib/Semantic/Exceptions/WrongTypeOfArgument.cs | 2 +- Interpreter.Lib/Semantic/Nodes/AbstractSyntaxTreeNode.cs | 2 +- .../Semantic/Nodes/Declarations/LexicalDeclaration.cs | 2 +- .../Semantic/Nodes/Expressions/PrimaryExpressions/Literal.cs | 2 +- Interpreter.Lib/Semantic/Utils/SymbolTableUtils.cs | 2 +- Interpreter.Tests/Unit/ParserTests.cs | 2 +- Interpreter/MappingProfiles/TokenTypeProfile.cs | 2 +- Interpreter/Models/LexerQueryModel.cs | 4 ++-- Interpreter/Services/Executor/Impl/Executor.cs | 3 ++- Interpreter/Services/Providers/ILexerProvider.cs | 2 +- Interpreter/Services/Providers/IParserProvider.cs | 4 ++-- Interpreter/Services/Providers/Impl/LexerProvider.cs | 2 +- Interpreter/Services/Providers/Impl/ParserProvider.cs | 4 ++-- 44 files changed, 55 insertions(+), 59 deletions(-) rename Interpreter.Lib/{RBNF/Analysis/Lexical => FrontEnd/Lex}/Coordinates.cs (96%) rename Interpreter.Lib/{RBNF/Analysis/Lexical => FrontEnd/Lex}/Lexer.cs (92%) rename Interpreter.Lib/{RBNF/Analysis/Exceptions => FrontEnd/Lex}/LexerException.cs (63%) rename Interpreter.Lib/{RBNF/Utils => FrontEnd/Lex}/LexerUtils.cs (66%) rename Interpreter.Lib/{RBNF/Analysis/Lexical => FrontEnd/Lex}/Segment.cs (94%) rename Interpreter.Lib/{RBNF/Analysis/Lexical => FrontEnd/Lex}/Structure.cs (91%) rename Interpreter.Lib/{RBNF/Analysis/Lexical => FrontEnd/Lex}/Token.cs (92%) rename Interpreter.Lib/{RBNF/Analysis/Lexical => FrontEnd/Lex}/TokenTypes/EndOfProgramType.cs (71%) rename Interpreter.Lib/{RBNF/Analysis/Lexical => FrontEnd/Lex}/TokenTypes/ErrorType.cs (69%) rename Interpreter.Lib/{RBNF/Analysis/Lexical => FrontEnd/Lex}/TokenTypes/TokenType.cs (87%) rename Interpreter.Lib/{RBNF/Analysis/Lexical => FrontEnd/Lex}/TokenTypes/WhiteSpaceType.cs (77%) rename Interpreter.Lib/{RBNF/Analysis/Syntactic => FrontEnd/Parse}/Parser.cs (99%) rename Interpreter.Lib/{RBNF/Analysis/Exceptions => FrontEnd/Parse}/ParserException.cs (75%) diff --git a/Interpreter.Lib/Contracts/IAbstractSyntaxTree.cs b/Interpreter.Lib/Contracts/IAbstractSyntaxTree.cs index 235bafb9..f560afb5 100644 --- a/Interpreter.Lib/Contracts/IAbstractSyntaxTree.cs +++ b/Interpreter.Lib/Contracts/IAbstractSyntaxTree.cs @@ -1,6 +1,10 @@ +using System.Collections.Generic; +using Interpreter.Lib.IR.Instructions; + namespace Interpreter.Lib.Contracts { public interface IAbstractSyntaxTree { + List ToInstructions(); } } \ No newline at end of file diff --git a/Interpreter.Lib/Contracts/ILexer.cs b/Interpreter.Lib/Contracts/ILexer.cs index 6acbd590..ef69147d 100644 --- a/Interpreter.Lib/Contracts/ILexer.cs +++ b/Interpreter.Lib/Contracts/ILexer.cs @@ -1,5 +1,5 @@ using System.Collections.Generic; -using Interpreter.Lib.RBNF.Analysis.Lexical; +using Interpreter.Lib.FrontEnd.Lex; namespace Interpreter.Lib.Contracts { diff --git a/Interpreter.Lib/Contracts/TokensStream.cs b/Interpreter.Lib/Contracts/TokensStream.cs index 4c8bdb81..8576f72f 100644 --- a/Interpreter.Lib/Contracts/TokensStream.cs +++ b/Interpreter.Lib/Contracts/TokensStream.cs @@ -1,6 +1,6 @@ using System.Collections; using System.Collections.Generic; -using Interpreter.Lib.RBNF.Analysis.Lexical; +using Interpreter.Lib.FrontEnd.Lex; namespace Interpreter.Lib.Contracts; diff --git a/Interpreter.Lib/RBNF/Analysis/Lexical/Coordinates.cs b/Interpreter.Lib/FrontEnd/Lex/Coordinates.cs similarity index 96% rename from Interpreter.Lib/RBNF/Analysis/Lexical/Coordinates.cs rename to Interpreter.Lib/FrontEnd/Lex/Coordinates.cs index 7f1ffcf5..e767e458 100644 --- a/Interpreter.Lib/RBNF/Analysis/Lexical/Coordinates.cs +++ b/Interpreter.Lib/FrontEnd/Lex/Coordinates.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using Newtonsoft.Json; -namespace Interpreter.Lib.RBNF.Analysis.Lexical +namespace Interpreter.Lib.FrontEnd.Lex { public class Coordinates : IEquatable { diff --git a/Interpreter.Lib/RBNF/Analysis/Lexical/Lexer.cs b/Interpreter.Lib/FrontEnd/Lex/Lexer.cs similarity index 92% rename from Interpreter.Lib/RBNF/Analysis/Lexical/Lexer.cs rename to Interpreter.Lib/FrontEnd/Lex/Lexer.cs index 0dc3edea..69ea1bdf 100644 --- a/Interpreter.Lib/RBNF/Analysis/Lexical/Lexer.cs +++ b/Interpreter.Lib/FrontEnd/Lex/Lexer.cs @@ -2,10 +2,8 @@ using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; -using Interpreter.Lib.RBNF.Analysis.Exceptions; -using Interpreter.Lib.RBNF.Utils; -namespace Interpreter.Lib.RBNF.Analysis.Lexical +namespace Interpreter.Lib.FrontEnd.Lex { public class Lexer : IEnumerable { diff --git a/Interpreter.Lib/RBNF/Analysis/Exceptions/LexerException.cs b/Interpreter.Lib/FrontEnd/Lex/LexerException.cs similarity index 63% rename from Interpreter.Lib/RBNF/Analysis/Exceptions/LexerException.cs rename to Interpreter.Lib/FrontEnd/Lex/LexerException.cs index 0e0862b4..745ac880 100644 --- a/Interpreter.Lib/RBNF/Analysis/Exceptions/LexerException.cs +++ b/Interpreter.Lib/FrontEnd/Lex/LexerException.cs @@ -1,7 +1,6 @@ using System; -using Interpreter.Lib.RBNF.Analysis.Lexical; -namespace Interpreter.Lib.RBNF.Analysis.Exceptions +namespace Interpreter.Lib.FrontEnd.Lex { public class LexerException : Exception { diff --git a/Interpreter.Lib/RBNF/Utils/LexerUtils.cs b/Interpreter.Lib/FrontEnd/Lex/LexerUtils.cs similarity index 66% rename from Interpreter.Lib/RBNF/Utils/LexerUtils.cs rename to Interpreter.Lib/FrontEnd/Lex/LexerUtils.cs index 9c10355e..0915e0fb 100644 --- a/Interpreter.Lib/RBNF/Utils/LexerUtils.cs +++ b/Interpreter.Lib/FrontEnd/Lex/LexerUtils.cs @@ -1,6 +1,6 @@ -using Interpreter.Lib.RBNF.Analysis.Lexical.TokenTypes; +using Interpreter.Lib.FrontEnd.Lex.TokenTypes; -namespace Interpreter.Lib.RBNF.Utils +namespace Interpreter.Lib.FrontEnd.Lex { public static class LexerUtils { diff --git a/Interpreter.Lib/RBNF/Analysis/Lexical/Segment.cs b/Interpreter.Lib/FrontEnd/Lex/Segment.cs similarity index 94% rename from Interpreter.Lib/RBNF/Analysis/Lexical/Segment.cs rename to Interpreter.Lib/FrontEnd/Lex/Segment.cs index 66a5ac23..e717e944 100644 --- a/Interpreter.Lib/RBNF/Analysis/Lexical/Segment.cs +++ b/Interpreter.Lib/FrontEnd/Lex/Segment.cs @@ -1,7 +1,7 @@ using System; using Newtonsoft.Json; -namespace Interpreter.Lib.RBNF.Analysis.Lexical +namespace Interpreter.Lib.FrontEnd.Lex { public class Segment : IEquatable { diff --git a/Interpreter.Lib/RBNF/Analysis/Lexical/Structure.cs b/Interpreter.Lib/FrontEnd/Lex/Structure.cs similarity index 91% rename from Interpreter.Lib/RBNF/Analysis/Lexical/Structure.cs rename to Interpreter.Lib/FrontEnd/Lex/Structure.cs index 87b4af61..256b14de 100644 --- a/Interpreter.Lib/RBNF/Analysis/Lexical/Structure.cs +++ b/Interpreter.Lib/FrontEnd/Lex/Structure.cs @@ -3,10 +3,9 @@ using System.Linq; using System.Text; using System.Text.RegularExpressions; -using Interpreter.Lib.RBNF.Analysis.Lexical.TokenTypes; -using Interpreter.Lib.RBNF.Utils; +using Interpreter.Lib.FrontEnd.Lex.TokenTypes; -namespace Interpreter.Lib.RBNF.Analysis.Lexical +namespace Interpreter.Lib.FrontEnd.Lex { public class Structure : IEnumerable { diff --git a/Interpreter.Lib/RBNF/Analysis/Lexical/Token.cs b/Interpreter.Lib/FrontEnd/Lex/Token.cs similarity index 92% rename from Interpreter.Lib/RBNF/Analysis/Lexical/Token.cs rename to Interpreter.Lib/FrontEnd/Lex/Token.cs index 86764403..5eaa3330 100644 --- a/Interpreter.Lib/RBNF/Analysis/Lexical/Token.cs +++ b/Interpreter.Lib/FrontEnd/Lex/Token.cs @@ -1,8 +1,8 @@ using System; using System.Text.RegularExpressions; -using Interpreter.Lib.RBNF.Analysis.Lexical.TokenTypes; +using Interpreter.Lib.FrontEnd.Lex.TokenTypes; -namespace Interpreter.Lib.RBNF.Analysis.Lexical +namespace Interpreter.Lib.FrontEnd.Lex { public class Token : ICloneable, IEquatable { diff --git a/Interpreter.Lib/RBNF/Analysis/Lexical/TokenTypes/EndOfProgramType.cs b/Interpreter.Lib/FrontEnd/Lex/TokenTypes/EndOfProgramType.cs similarity index 71% rename from Interpreter.Lib/RBNF/Analysis/Lexical/TokenTypes/EndOfProgramType.cs rename to Interpreter.Lib/FrontEnd/Lex/TokenTypes/EndOfProgramType.cs index 698497ee..01b6c789 100644 --- a/Interpreter.Lib/RBNF/Analysis/Lexical/TokenTypes/EndOfProgramType.cs +++ b/Interpreter.Lib/FrontEnd/Lex/TokenTypes/EndOfProgramType.cs @@ -1,4 +1,4 @@ -namespace Interpreter.Lib.RBNF.Analysis.Lexical.TokenTypes +namespace Interpreter.Lib.FrontEnd.Lex.TokenTypes { internal record EndOfProgramType() : TokenType("EOP", "", int.MaxValue - 1) { diff --git a/Interpreter.Lib/RBNF/Analysis/Lexical/TokenTypes/ErrorType.cs b/Interpreter.Lib/FrontEnd/Lex/TokenTypes/ErrorType.cs similarity index 69% rename from Interpreter.Lib/RBNF/Analysis/Lexical/TokenTypes/ErrorType.cs rename to Interpreter.Lib/FrontEnd/Lex/TokenTypes/ErrorType.cs index 9145701d..2c8b46ea 100644 --- a/Interpreter.Lib/RBNF/Analysis/Lexical/TokenTypes/ErrorType.cs +++ b/Interpreter.Lib/FrontEnd/Lex/TokenTypes/ErrorType.cs @@ -1,4 +1,4 @@ -namespace Interpreter.Lib.RBNF.Analysis.Lexical.TokenTypes +namespace Interpreter.Lib.FrontEnd.Lex.TokenTypes { internal record ErrorType() : TokenType("ERROR", @"\S+", int.MaxValue) { diff --git a/Interpreter.Lib/RBNF/Analysis/Lexical/TokenTypes/TokenType.cs b/Interpreter.Lib/FrontEnd/Lex/TokenTypes/TokenType.cs similarity index 87% rename from Interpreter.Lib/RBNF/Analysis/Lexical/TokenTypes/TokenType.cs rename to Interpreter.Lib/FrontEnd/Lex/TokenTypes/TokenType.cs index 36e6c6b2..e31f7e3f 100644 --- a/Interpreter.Lib/RBNF/Analysis/Lexical/TokenTypes/TokenType.cs +++ b/Interpreter.Lib/FrontEnd/Lex/TokenTypes/TokenType.cs @@ -1,4 +1,4 @@ -namespace Interpreter.Lib.RBNF.Analysis.Lexical.TokenTypes +namespace Interpreter.Lib.FrontEnd.Lex.TokenTypes { public record TokenType(string Tag, string Pattern, int Priority) { diff --git a/Interpreter.Lib/RBNF/Analysis/Lexical/TokenTypes/WhiteSpaceType.cs b/Interpreter.Lib/FrontEnd/Lex/TokenTypes/WhiteSpaceType.cs similarity index 77% rename from Interpreter.Lib/RBNF/Analysis/Lexical/TokenTypes/WhiteSpaceType.cs rename to Interpreter.Lib/FrontEnd/Lex/TokenTypes/WhiteSpaceType.cs index 32f41be4..cd542134 100644 --- a/Interpreter.Lib/RBNF/Analysis/Lexical/TokenTypes/WhiteSpaceType.cs +++ b/Interpreter.Lib/FrontEnd/Lex/TokenTypes/WhiteSpaceType.cs @@ -1,4 +1,4 @@ -namespace Interpreter.Lib.RBNF.Analysis.Lexical.TokenTypes +namespace Interpreter.Lib.FrontEnd.Lex.TokenTypes { public record WhiteSpaceType(string Tag = null, string Pattern = null, int Priority = 0) : TokenType(Tag, Pattern, Priority) diff --git a/Interpreter.Lib/RBNF/Analysis/Syntactic/Parser.cs b/Interpreter.Lib/FrontEnd/Parse/Parser.cs similarity index 99% rename from Interpreter.Lib/RBNF/Analysis/Syntactic/Parser.cs rename to Interpreter.Lib/FrontEnd/Parse/Parser.cs index bc68049c..766dadc1 100644 --- a/Interpreter.Lib/RBNF/Analysis/Syntactic/Parser.cs +++ b/Interpreter.Lib/FrontEnd/Parse/Parser.cs @@ -2,8 +2,7 @@ using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Text.RegularExpressions; -using Interpreter.Lib.RBNF.Analysis.Exceptions; -using Interpreter.Lib.RBNF.Analysis.Lexical; +using Interpreter.Lib.FrontEnd.Lex; using Interpreter.Lib.Semantic; using Interpreter.Lib.Semantic.Exceptions; using Interpreter.Lib.Semantic.Nodes; @@ -18,7 +17,7 @@ using Interpreter.Lib.Semantic.Utils; using Expression = Interpreter.Lib.Semantic.Nodes.Expressions.Expression; -namespace Interpreter.Lib.RBNF.Analysis.Syntactic +namespace Interpreter.Lib.FrontEnd.Parse { [SuppressMessage("ReSharper", "PossibleNullReferenceException")] public class Parser diff --git a/Interpreter.Lib/RBNF/Analysis/Exceptions/ParserException.cs b/Interpreter.Lib/FrontEnd/Parse/ParserException.cs similarity index 75% rename from Interpreter.Lib/RBNF/Analysis/Exceptions/ParserException.cs rename to Interpreter.Lib/FrontEnd/Parse/ParserException.cs index 4bd3c94a..257b37e0 100644 --- a/Interpreter.Lib/RBNF/Analysis/Exceptions/ParserException.cs +++ b/Interpreter.Lib/FrontEnd/Parse/ParserException.cs @@ -1,7 +1,7 @@ using System; -using Interpreter.Lib.RBNF.Analysis.Lexical; +using Interpreter.Lib.FrontEnd.Lex; -namespace Interpreter.Lib.RBNF.Analysis.Exceptions +namespace Interpreter.Lib.FrontEnd.Parse { public class ParserException : Exception { diff --git a/Interpreter.Lib/Interpreter.Lib.csproj b/Interpreter.Lib/Interpreter.Lib.csproj index af6168a4..54610ed4 100644 --- a/Interpreter.Lib/Interpreter.Lib.csproj +++ b/Interpreter.Lib/Interpreter.Lib.csproj @@ -4,10 +4,6 @@ net6.0 - - - - diff --git a/Interpreter.Lib/Semantic/Exceptions/ArrayAccessException.cs b/Interpreter.Lib/Semantic/Exceptions/ArrayAccessException.cs index d3a27b40..b7db64de 100644 --- a/Interpreter.Lib/Semantic/Exceptions/ArrayAccessException.cs +++ b/Interpreter.Lib/Semantic/Exceptions/ArrayAccessException.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.RBNF.Analysis.Lexical; +using Interpreter.Lib.FrontEnd.Lex; using Interpreter.Lib.Semantic.Types; namespace Interpreter.Lib.Semantic.Exceptions diff --git a/Interpreter.Lib/Semantic/Exceptions/CannotDefineType.cs b/Interpreter.Lib/Semantic/Exceptions/CannotDefineType.cs index e1f49035..d1906f8c 100644 --- a/Interpreter.Lib/Semantic/Exceptions/CannotDefineType.cs +++ b/Interpreter.Lib/Semantic/Exceptions/CannotDefineType.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.RBNF.Analysis.Lexical; +using Interpreter.Lib.FrontEnd.Lex; namespace Interpreter.Lib.Semantic.Exceptions { diff --git a/Interpreter.Lib/Semantic/Exceptions/FunctionWithoutReturnStatement.cs b/Interpreter.Lib/Semantic/Exceptions/FunctionWithoutReturnStatement.cs index e07ad959..94a94b3a 100644 --- a/Interpreter.Lib/Semantic/Exceptions/FunctionWithoutReturnStatement.cs +++ b/Interpreter.Lib/Semantic/Exceptions/FunctionWithoutReturnStatement.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.RBNF.Analysis.Lexical; +using Interpreter.Lib.FrontEnd.Lex; namespace Interpreter.Lib.Semantic.Exceptions { diff --git a/Interpreter.Lib/Semantic/Exceptions/IncompatibleTypesOfOperands.cs b/Interpreter.Lib/Semantic/Exceptions/IncompatibleTypesOfOperands.cs index f3eec819..e87306c7 100644 --- a/Interpreter.Lib/Semantic/Exceptions/IncompatibleTypesOfOperands.cs +++ b/Interpreter.Lib/Semantic/Exceptions/IncompatibleTypesOfOperands.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.RBNF.Analysis.Lexical; +using Interpreter.Lib.FrontEnd.Lex; using Interpreter.Lib.Semantic.Types; namespace Interpreter.Lib.Semantic.Exceptions diff --git a/Interpreter.Lib/Semantic/Exceptions/NotBooleanTestExpression.cs b/Interpreter.Lib/Semantic/Exceptions/NotBooleanTestExpression.cs index add04790..3ad391d0 100644 --- a/Interpreter.Lib/Semantic/Exceptions/NotBooleanTestExpression.cs +++ b/Interpreter.Lib/Semantic/Exceptions/NotBooleanTestExpression.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.RBNF.Analysis.Lexical; +using Interpreter.Lib.FrontEnd.Lex; using Interpreter.Lib.Semantic.Types; namespace Interpreter.Lib.Semantic.Exceptions diff --git a/Interpreter.Lib/Semantic/Exceptions/ObjectAccessException.cs b/Interpreter.Lib/Semantic/Exceptions/ObjectAccessException.cs index ab41d605..6c3f38e5 100644 --- a/Interpreter.Lib/Semantic/Exceptions/ObjectAccessException.cs +++ b/Interpreter.Lib/Semantic/Exceptions/ObjectAccessException.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.RBNF.Analysis.Lexical; +using Interpreter.Lib.FrontEnd.Lex; using Interpreter.Lib.Semantic.Types; namespace Interpreter.Lib.Semantic.Exceptions diff --git a/Interpreter.Lib/Semantic/Exceptions/OutsideOfLoop.cs b/Interpreter.Lib/Semantic/Exceptions/OutsideOfLoop.cs index 86fcedb7..c878a909 100644 --- a/Interpreter.Lib/Semantic/Exceptions/OutsideOfLoop.cs +++ b/Interpreter.Lib/Semantic/Exceptions/OutsideOfLoop.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.RBNF.Analysis.Lexical; +using Interpreter.Lib.FrontEnd.Lex; namespace Interpreter.Lib.Semantic.Exceptions { diff --git a/Interpreter.Lib/Semantic/Exceptions/ReturnOutsideFunction.cs b/Interpreter.Lib/Semantic/Exceptions/ReturnOutsideFunction.cs index 8bcdbece..b4794135 100644 --- a/Interpreter.Lib/Semantic/Exceptions/ReturnOutsideFunction.cs +++ b/Interpreter.Lib/Semantic/Exceptions/ReturnOutsideFunction.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.RBNF.Analysis.Lexical; +using Interpreter.Lib.FrontEnd.Lex; namespace Interpreter.Lib.Semantic.Exceptions { diff --git a/Interpreter.Lib/Semantic/Exceptions/SymbolIsNotCallable.cs b/Interpreter.Lib/Semantic/Exceptions/SymbolIsNotCallable.cs index 6406b134..cfb3dfdf 100644 --- a/Interpreter.Lib/Semantic/Exceptions/SymbolIsNotCallable.cs +++ b/Interpreter.Lib/Semantic/Exceptions/SymbolIsNotCallable.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.RBNF.Analysis.Lexical; +using Interpreter.Lib.FrontEnd.Lex; namespace Interpreter.Lib.Semantic.Exceptions { diff --git a/Interpreter.Lib/Semantic/Exceptions/UnsupportedOperation.cs b/Interpreter.Lib/Semantic/Exceptions/UnsupportedOperation.cs index 263e12b9..06cafd8c 100644 --- a/Interpreter.Lib/Semantic/Exceptions/UnsupportedOperation.cs +++ b/Interpreter.Lib/Semantic/Exceptions/UnsupportedOperation.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.RBNF.Analysis.Lexical; +using Interpreter.Lib.FrontEnd.Lex; using Interpreter.Lib.Semantic.Types; namespace Interpreter.Lib.Semantic.Exceptions diff --git a/Interpreter.Lib/Semantic/Exceptions/WrongArrayLiteralDeclaration.cs b/Interpreter.Lib/Semantic/Exceptions/WrongArrayLiteralDeclaration.cs index 889647c5..144839d8 100644 --- a/Interpreter.Lib/Semantic/Exceptions/WrongArrayLiteralDeclaration.cs +++ b/Interpreter.Lib/Semantic/Exceptions/WrongArrayLiteralDeclaration.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.RBNF.Analysis.Lexical; +using Interpreter.Lib.FrontEnd.Lex; using Interpreter.Lib.Semantic.Types; namespace Interpreter.Lib.Semantic.Exceptions diff --git a/Interpreter.Lib/Semantic/Exceptions/WrongConditionalTypes.cs b/Interpreter.Lib/Semantic/Exceptions/WrongConditionalTypes.cs index 6ff31488..43bd3171 100644 --- a/Interpreter.Lib/Semantic/Exceptions/WrongConditionalTypes.cs +++ b/Interpreter.Lib/Semantic/Exceptions/WrongConditionalTypes.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.RBNF.Analysis.Lexical; +using Interpreter.Lib.FrontEnd.Lex; using Interpreter.Lib.Semantic.Types; namespace Interpreter.Lib.Semantic.Exceptions diff --git a/Interpreter.Lib/Semantic/Exceptions/WrongNumberOfArguments.cs b/Interpreter.Lib/Semantic/Exceptions/WrongNumberOfArguments.cs index 39b35b50..6a8599ad 100644 --- a/Interpreter.Lib/Semantic/Exceptions/WrongNumberOfArguments.cs +++ b/Interpreter.Lib/Semantic/Exceptions/WrongNumberOfArguments.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.RBNF.Analysis.Lexical; +using Interpreter.Lib.FrontEnd.Lex; namespace Interpreter.Lib.Semantic.Exceptions { diff --git a/Interpreter.Lib/Semantic/Exceptions/WrongReturnType.cs b/Interpreter.Lib/Semantic/Exceptions/WrongReturnType.cs index 2311a5e4..da8a59f8 100644 --- a/Interpreter.Lib/Semantic/Exceptions/WrongReturnType.cs +++ b/Interpreter.Lib/Semantic/Exceptions/WrongReturnType.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.RBNF.Analysis.Lexical; +using Interpreter.Lib.FrontEnd.Lex; using Interpreter.Lib.Semantic.Types; namespace Interpreter.Lib.Semantic.Exceptions diff --git a/Interpreter.Lib/Semantic/Exceptions/WrongTypeOfArgument.cs b/Interpreter.Lib/Semantic/Exceptions/WrongTypeOfArgument.cs index 25c95d45..a1f42cb7 100644 --- a/Interpreter.Lib/Semantic/Exceptions/WrongTypeOfArgument.cs +++ b/Interpreter.Lib/Semantic/Exceptions/WrongTypeOfArgument.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.RBNF.Analysis.Lexical; +using Interpreter.Lib.FrontEnd.Lex; using Interpreter.Lib.Semantic.Types; namespace Interpreter.Lib.Semantic.Exceptions diff --git a/Interpreter.Lib/Semantic/Nodes/AbstractSyntaxTreeNode.cs b/Interpreter.Lib/Semantic/Nodes/AbstractSyntaxTreeNode.cs index e592d4d2..82a53622 100644 --- a/Interpreter.Lib/Semantic/Nodes/AbstractSyntaxTreeNode.cs +++ b/Interpreter.Lib/Semantic/Nodes/AbstractSyntaxTreeNode.cs @@ -1,7 +1,7 @@ using System.Collections; using System.Collections.Generic; +using Interpreter.Lib.FrontEnd.Lex; using Interpreter.Lib.IR.Instructions; -using Interpreter.Lib.RBNF.Analysis.Lexical; using Interpreter.Lib.Semantic.Nodes.Declarations; using Interpreter.Lib.Semantic.Types; diff --git a/Interpreter.Lib/Semantic/Nodes/Declarations/LexicalDeclaration.cs b/Interpreter.Lib/Semantic/Nodes/Declarations/LexicalDeclaration.cs index b2e1e4ab..61022c33 100644 --- a/Interpreter.Lib/Semantic/Nodes/Declarations/LexicalDeclaration.cs +++ b/Interpreter.Lib/Semantic/Nodes/Declarations/LexicalDeclaration.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using System.Linq; +using Interpreter.Lib.FrontEnd.Lex; using Interpreter.Lib.IR.Instructions; -using Interpreter.Lib.RBNF.Analysis.Lexical; using Interpreter.Lib.Semantic.Nodes.Expressions; using Interpreter.Lib.Semantic.Nodes.Expressions.PrimaryExpressions; using Interpreter.Lib.Semantic.Types; diff --git a/Interpreter.Lib/Semantic/Nodes/Expressions/PrimaryExpressions/Literal.cs b/Interpreter.Lib/Semantic/Nodes/Expressions/PrimaryExpressions/Literal.cs index 28af43a4..aa2a2b7d 100644 --- a/Interpreter.Lib/Semantic/Nodes/Expressions/PrimaryExpressions/Literal.cs +++ b/Interpreter.Lib/Semantic/Nodes/Expressions/PrimaryExpressions/Literal.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.RBNF.Analysis.Lexical; +using Interpreter.Lib.FrontEnd.Lex; using Interpreter.Lib.VM.Values; using Type = Interpreter.Lib.Semantic.Types.Type; diff --git a/Interpreter.Lib/Semantic/Utils/SymbolTableUtils.cs b/Interpreter.Lib/Semantic/Utils/SymbolTableUtils.cs index 8e80e37f..70046172 100644 --- a/Interpreter.Lib/Semantic/Utils/SymbolTableUtils.cs +++ b/Interpreter.Lib/Semantic/Utils/SymbolTableUtils.cs @@ -1,5 +1,5 @@ using System.Collections.Generic; -using Interpreter.Lib.RBNF.Analysis.Lexical; +using Interpreter.Lib.FrontEnd.Lex; using Interpreter.Lib.Semantic.Nodes; using Interpreter.Lib.Semantic.Nodes.Declarations; using Interpreter.Lib.Semantic.Nodes.Statements; diff --git a/Interpreter.Tests/Unit/ParserTests.cs b/Interpreter.Tests/Unit/ParserTests.cs index 00908e5b..7f982f5b 100644 --- a/Interpreter.Tests/Unit/ParserTests.cs +++ b/Interpreter.Tests/Unit/ParserTests.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.RBNF.Analysis.Syntactic; +using Interpreter.Lib.FrontEnd.Parse; using Interpreter.Models; using Interpreter.Services.Providers; using Interpreter.Tests.TestData; diff --git a/Interpreter/MappingProfiles/TokenTypeProfile.cs b/Interpreter/MappingProfiles/TokenTypeProfile.cs index ee75f8ba..590bfc5c 100644 --- a/Interpreter/MappingProfiles/TokenTypeProfile.cs +++ b/Interpreter/MappingProfiles/TokenTypeProfile.cs @@ -1,5 +1,5 @@ using AutoMapper; -using Interpreter.Lib.RBNF.Analysis.Lexical.TokenTypes; +using Interpreter.Lib.FrontEnd.Lex.TokenTypes; using Interpreter.Models; namespace Interpreter.MappingProfiles diff --git a/Interpreter/Models/LexerQueryModel.cs b/Interpreter/Models/LexerQueryModel.cs index 8976cc47..6e29bef1 100644 --- a/Interpreter/Models/LexerQueryModel.cs +++ b/Interpreter/Models/LexerQueryModel.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using AutoMapper; -using Interpreter.Lib.RBNF.Analysis.Lexical; -using Interpreter.Lib.RBNF.Analysis.Lexical.TokenTypes; +using Interpreter.Lib.FrontEnd.Lex; +using Interpreter.Lib.FrontEnd.Lex.TokenTypes; using Newtonsoft.Json; namespace Interpreter.Models diff --git a/Interpreter/Services/Executor/Impl/Executor.cs b/Interpreter/Services/Executor/Impl/Executor.cs index 9ef946aa..82233352 100644 --- a/Interpreter/Services/Executor/Impl/Executor.cs +++ b/Interpreter/Services/Executor/Impl/Executor.cs @@ -1,10 +1,11 @@ using System; using System.IO; using System.Linq; +using Interpreter.Lib.FrontEnd.Lex; +using Interpreter.Lib.FrontEnd.Parse; using Interpreter.Lib.IR; using Interpreter.Lib.IR.Instructions; using Interpreter.Lib.IR.Optimizers; -using Interpreter.Lib.RBNF.Analysis.Exceptions; using Interpreter.Lib.Semantic.Analysis; using Interpreter.Lib.Semantic.Exceptions; using Interpreter.Lib.VM; diff --git a/Interpreter/Services/Providers/ILexerProvider.cs b/Interpreter/Services/Providers/ILexerProvider.cs index 187e9821..e9384822 100644 --- a/Interpreter/Services/Providers/ILexerProvider.cs +++ b/Interpreter/Services/Providers/ILexerProvider.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.RBNF.Analysis.Lexical; +using Interpreter.Lib.FrontEnd.Lex; using Interpreter.Models; namespace Interpreter.Services.Providers diff --git a/Interpreter/Services/Providers/IParserProvider.cs b/Interpreter/Services/Providers/IParserProvider.cs index f0726014..ae18472d 100644 --- a/Interpreter/Services/Providers/IParserProvider.cs +++ b/Interpreter/Services/Providers/IParserProvider.cs @@ -1,5 +1,5 @@ -using Interpreter.Lib.RBNF.Analysis.Lexical; -using Interpreter.Lib.RBNF.Analysis.Syntactic; +using Interpreter.Lib.FrontEnd.Lex; +using Interpreter.Lib.FrontEnd.Parse; namespace Interpreter.Services.Providers { diff --git a/Interpreter/Services/Providers/Impl/LexerProvider.cs b/Interpreter/Services/Providers/Impl/LexerProvider.cs index 7b0b456b..a55395eb 100644 --- a/Interpreter/Services/Providers/Impl/LexerProvider.cs +++ b/Interpreter/Services/Providers/Impl/LexerProvider.cs @@ -1,5 +1,5 @@ using AutoMapper; -using Interpreter.Lib.RBNF.Analysis.Lexical; +using Interpreter.Lib.FrontEnd.Lex; using Interpreter.Models; namespace Interpreter.Services.Providers.Impl diff --git a/Interpreter/Services/Providers/Impl/ParserProvider.cs b/Interpreter/Services/Providers/Impl/ParserProvider.cs index 4a70036d..4e19f7c7 100644 --- a/Interpreter/Services/Providers/Impl/ParserProvider.cs +++ b/Interpreter/Services/Providers/Impl/ParserProvider.cs @@ -1,5 +1,5 @@ -using Interpreter.Lib.RBNF.Analysis.Lexical; -using Interpreter.Lib.RBNF.Analysis.Syntactic; +using Interpreter.Lib.FrontEnd.Lex; +using Interpreter.Lib.FrontEnd.Parse; namespace Interpreter.Services.Providers.Impl { From 52282440b03581e97d1800cc123e9e8053462d2b Mon Sep 17 00:00:00 2001 From: Stepami Date: Mon, 12 Sep 2022 11:09:44 +0300 Subject: [PATCH 10/56] =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B5=D0=B8=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=BF=D0=B0?= =?UTF-8?q?=D0=BF=D0=BE=D0=BA=20=D0=BF=D0=BE=20=D0=BF=D1=80=D0=B8=D0=BD?= =?UTF-8?q?=D1=86=D0=B8=D0=BF=D1=83=20feature=20directory?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Interpreter.Lib/Contracts/ILexer.cs | 2 +- Interpreter.Lib/Contracts/TokensStream.cs | 2 +- Interpreter.Lib/FrontEnd/{Lex => GetTokens}/Coordinates.cs | 2 +- Interpreter.Lib/FrontEnd/{Lex => GetTokens}/Lexer.cs | 2 +- Interpreter.Lib/FrontEnd/{Lex => GetTokens}/LexerException.cs | 2 +- Interpreter.Lib/FrontEnd/{Lex => GetTokens}/LexerUtils.cs | 4 ++-- Interpreter.Lib/FrontEnd/{Lex => GetTokens}/Segment.cs | 2 +- Interpreter.Lib/FrontEnd/{Lex => GetTokens}/Structure.cs | 4 ++-- Interpreter.Lib/FrontEnd/{Lex => GetTokens}/Token.cs | 4 ++-- .../{Lex => GetTokens}/TokenTypes/EndOfProgramType.cs | 2 +- .../FrontEnd/{Lex => GetTokens}/TokenTypes/ErrorType.cs | 2 +- .../FrontEnd/{Lex => GetTokens}/TokenTypes/TokenType.cs | 2 +- .../FrontEnd/{Lex => GetTokens}/TokenTypes/WhiteSpaceType.cs | 2 +- Interpreter.Lib/FrontEnd/{Parse => TopDownParse}/Parser.cs | 4 ++-- .../FrontEnd/{Parse => TopDownParse}/ParserException.cs | 4 ++-- Interpreter.Lib/Semantic/Exceptions/ArrayAccessException.cs | 2 +- Interpreter.Lib/Semantic/Exceptions/CannotDefineType.cs | 2 +- .../Semantic/Exceptions/FunctionWithoutReturnStatement.cs | 2 +- .../Semantic/Exceptions/IncompatibleTypesOfOperands.cs | 2 +- .../Semantic/Exceptions/NotBooleanTestExpression.cs | 2 +- Interpreter.Lib/Semantic/Exceptions/ObjectAccessException.cs | 2 +- Interpreter.Lib/Semantic/Exceptions/OutsideOfLoop.cs | 2 +- Interpreter.Lib/Semantic/Exceptions/ReturnOutsideFunction.cs | 2 +- Interpreter.Lib/Semantic/Exceptions/SymbolIsNotCallable.cs | 2 +- Interpreter.Lib/Semantic/Exceptions/UnsupportedOperation.cs | 2 +- .../Semantic/Exceptions/WrongArrayLiteralDeclaration.cs | 2 +- Interpreter.Lib/Semantic/Exceptions/WrongConditionalTypes.cs | 2 +- Interpreter.Lib/Semantic/Exceptions/WrongNumberOfArguments.cs | 2 +- Interpreter.Lib/Semantic/Exceptions/WrongReturnType.cs | 2 +- Interpreter.Lib/Semantic/Exceptions/WrongTypeOfArgument.cs | 2 +- Interpreter.Lib/Semantic/Nodes/AbstractSyntaxTreeNode.cs | 2 +- .../Semantic/Nodes/Declarations/LexicalDeclaration.cs | 2 +- .../Semantic/Nodes/Expressions/PrimaryExpressions/Literal.cs | 2 +- Interpreter.Lib/Semantic/Utils/SymbolTableUtils.cs | 2 +- Interpreter.Tests/Unit/ParserTests.cs | 2 +- Interpreter/MappingProfiles/TokenTypeProfile.cs | 2 +- Interpreter/Models/LexerQueryModel.cs | 4 ++-- Interpreter/Services/Executor/Impl/Executor.cs | 4 ++-- Interpreter/Services/Providers/ILexerProvider.cs | 2 +- Interpreter/Services/Providers/IParserProvider.cs | 4 ++-- Interpreter/Services/Providers/Impl/LexerProvider.cs | 2 +- Interpreter/Services/Providers/Impl/ParserProvider.cs | 4 ++-- 42 files changed, 51 insertions(+), 51 deletions(-) rename Interpreter.Lib/FrontEnd/{Lex => GetTokens}/Coordinates.cs (96%) rename Interpreter.Lib/FrontEnd/{Lex => GetTokens}/Lexer.cs (97%) rename Interpreter.Lib/FrontEnd/{Lex => GetTokens}/LexerException.cs (79%) rename Interpreter.Lib/FrontEnd/{Lex => GetTokens}/LexerUtils.cs (65%) rename Interpreter.Lib/FrontEnd/{Lex => GetTokens}/Segment.cs (95%) rename Interpreter.Lib/FrontEnd/{Lex => GetTokens}/Structure.cs (93%) rename Interpreter.Lib/FrontEnd/{Lex => GetTokens}/Token.cs (92%) rename Interpreter.Lib/FrontEnd/{Lex => GetTokens}/TokenTypes/EndOfProgramType.cs (72%) rename Interpreter.Lib/FrontEnd/{Lex => GetTokens}/TokenTypes/ErrorType.cs (70%) rename Interpreter.Lib/FrontEnd/{Lex => GetTokens}/TokenTypes/TokenType.cs (87%) rename Interpreter.Lib/FrontEnd/{Lex => GetTokens}/TokenTypes/WhiteSpaceType.cs (78%) rename Interpreter.Lib/FrontEnd/{Parse => TopDownParse}/Parser.cs (99%) rename Interpreter.Lib/FrontEnd/{Parse => TopDownParse}/ParserException.cs (76%) diff --git a/Interpreter.Lib/Contracts/ILexer.cs b/Interpreter.Lib/Contracts/ILexer.cs index ef69147d..6e51b18b 100644 --- a/Interpreter.Lib/Contracts/ILexer.cs +++ b/Interpreter.Lib/Contracts/ILexer.cs @@ -1,5 +1,5 @@ using System.Collections.Generic; -using Interpreter.Lib.FrontEnd.Lex; +using Interpreter.Lib.FrontEnd.GetTokens; namespace Interpreter.Lib.Contracts { diff --git a/Interpreter.Lib/Contracts/TokensStream.cs b/Interpreter.Lib/Contracts/TokensStream.cs index 8576f72f..a82a3d3b 100644 --- a/Interpreter.Lib/Contracts/TokensStream.cs +++ b/Interpreter.Lib/Contracts/TokensStream.cs @@ -1,6 +1,6 @@ using System.Collections; using System.Collections.Generic; -using Interpreter.Lib.FrontEnd.Lex; +using Interpreter.Lib.FrontEnd.GetTokens; namespace Interpreter.Lib.Contracts; diff --git a/Interpreter.Lib/FrontEnd/Lex/Coordinates.cs b/Interpreter.Lib/FrontEnd/GetTokens/Coordinates.cs similarity index 96% rename from Interpreter.Lib/FrontEnd/Lex/Coordinates.cs rename to Interpreter.Lib/FrontEnd/GetTokens/Coordinates.cs index e767e458..6092c934 100644 --- a/Interpreter.Lib/FrontEnd/Lex/Coordinates.cs +++ b/Interpreter.Lib/FrontEnd/GetTokens/Coordinates.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using Newtonsoft.Json; -namespace Interpreter.Lib.FrontEnd.Lex +namespace Interpreter.Lib.FrontEnd.GetTokens { public class Coordinates : IEquatable { diff --git a/Interpreter.Lib/FrontEnd/Lex/Lexer.cs b/Interpreter.Lib/FrontEnd/GetTokens/Lexer.cs similarity index 97% rename from Interpreter.Lib/FrontEnd/Lex/Lexer.cs rename to Interpreter.Lib/FrontEnd/GetTokens/Lexer.cs index 69ea1bdf..cbb2db19 100644 --- a/Interpreter.Lib/FrontEnd/Lex/Lexer.cs +++ b/Interpreter.Lib/FrontEnd/GetTokens/Lexer.cs @@ -3,7 +3,7 @@ using System.Linq; using System.Text.RegularExpressions; -namespace Interpreter.Lib.FrontEnd.Lex +namespace Interpreter.Lib.FrontEnd.GetTokens { public class Lexer : IEnumerable { diff --git a/Interpreter.Lib/FrontEnd/Lex/LexerException.cs b/Interpreter.Lib/FrontEnd/GetTokens/LexerException.cs similarity index 79% rename from Interpreter.Lib/FrontEnd/Lex/LexerException.cs rename to Interpreter.Lib/FrontEnd/GetTokens/LexerException.cs index 745ac880..480e1b6a 100644 --- a/Interpreter.Lib/FrontEnd/Lex/LexerException.cs +++ b/Interpreter.Lib/FrontEnd/GetTokens/LexerException.cs @@ -1,6 +1,6 @@ using System; -namespace Interpreter.Lib.FrontEnd.Lex +namespace Interpreter.Lib.FrontEnd.GetTokens { public class LexerException : Exception { diff --git a/Interpreter.Lib/FrontEnd/Lex/LexerUtils.cs b/Interpreter.Lib/FrontEnd/GetTokens/LexerUtils.cs similarity index 65% rename from Interpreter.Lib/FrontEnd/Lex/LexerUtils.cs rename to Interpreter.Lib/FrontEnd/GetTokens/LexerUtils.cs index 0915e0fb..c91125e9 100644 --- a/Interpreter.Lib/FrontEnd/Lex/LexerUtils.cs +++ b/Interpreter.Lib/FrontEnd/GetTokens/LexerUtils.cs @@ -1,6 +1,6 @@ -using Interpreter.Lib.FrontEnd.Lex.TokenTypes; +using Interpreter.Lib.FrontEnd.GetTokens.TokenTypes; -namespace Interpreter.Lib.FrontEnd.Lex +namespace Interpreter.Lib.FrontEnd.GetTokens { public static class LexerUtils { diff --git a/Interpreter.Lib/FrontEnd/Lex/Segment.cs b/Interpreter.Lib/FrontEnd/GetTokens/Segment.cs similarity index 95% rename from Interpreter.Lib/FrontEnd/Lex/Segment.cs rename to Interpreter.Lib/FrontEnd/GetTokens/Segment.cs index e717e944..9099a9e4 100644 --- a/Interpreter.Lib/FrontEnd/Lex/Segment.cs +++ b/Interpreter.Lib/FrontEnd/GetTokens/Segment.cs @@ -1,7 +1,7 @@ using System; using Newtonsoft.Json; -namespace Interpreter.Lib.FrontEnd.Lex +namespace Interpreter.Lib.FrontEnd.GetTokens { public class Segment : IEquatable { diff --git a/Interpreter.Lib/FrontEnd/Lex/Structure.cs b/Interpreter.Lib/FrontEnd/GetTokens/Structure.cs similarity index 93% rename from Interpreter.Lib/FrontEnd/Lex/Structure.cs rename to Interpreter.Lib/FrontEnd/GetTokens/Structure.cs index 256b14de..671adcc9 100644 --- a/Interpreter.Lib/FrontEnd/Lex/Structure.cs +++ b/Interpreter.Lib/FrontEnd/GetTokens/Structure.cs @@ -3,9 +3,9 @@ using System.Linq; using System.Text; using System.Text.RegularExpressions; -using Interpreter.Lib.FrontEnd.Lex.TokenTypes; +using Interpreter.Lib.FrontEnd.GetTokens.TokenTypes; -namespace Interpreter.Lib.FrontEnd.Lex +namespace Interpreter.Lib.FrontEnd.GetTokens { public class Structure : IEnumerable { diff --git a/Interpreter.Lib/FrontEnd/Lex/Token.cs b/Interpreter.Lib/FrontEnd/GetTokens/Token.cs similarity index 92% rename from Interpreter.Lib/FrontEnd/Lex/Token.cs rename to Interpreter.Lib/FrontEnd/GetTokens/Token.cs index 5eaa3330..98bcadf1 100644 --- a/Interpreter.Lib/FrontEnd/Lex/Token.cs +++ b/Interpreter.Lib/FrontEnd/GetTokens/Token.cs @@ -1,8 +1,8 @@ using System; using System.Text.RegularExpressions; -using Interpreter.Lib.FrontEnd.Lex.TokenTypes; +using Interpreter.Lib.FrontEnd.GetTokens.TokenTypes; -namespace Interpreter.Lib.FrontEnd.Lex +namespace Interpreter.Lib.FrontEnd.GetTokens { public class Token : ICloneable, IEquatable { diff --git a/Interpreter.Lib/FrontEnd/Lex/TokenTypes/EndOfProgramType.cs b/Interpreter.Lib/FrontEnd/GetTokens/TokenTypes/EndOfProgramType.cs similarity index 72% rename from Interpreter.Lib/FrontEnd/Lex/TokenTypes/EndOfProgramType.cs rename to Interpreter.Lib/FrontEnd/GetTokens/TokenTypes/EndOfProgramType.cs index 01b6c789..89230c2a 100644 --- a/Interpreter.Lib/FrontEnd/Lex/TokenTypes/EndOfProgramType.cs +++ b/Interpreter.Lib/FrontEnd/GetTokens/TokenTypes/EndOfProgramType.cs @@ -1,4 +1,4 @@ -namespace Interpreter.Lib.FrontEnd.Lex.TokenTypes +namespace Interpreter.Lib.FrontEnd.GetTokens.TokenTypes { internal record EndOfProgramType() : TokenType("EOP", "", int.MaxValue - 1) { diff --git a/Interpreter.Lib/FrontEnd/Lex/TokenTypes/ErrorType.cs b/Interpreter.Lib/FrontEnd/GetTokens/TokenTypes/ErrorType.cs similarity index 70% rename from Interpreter.Lib/FrontEnd/Lex/TokenTypes/ErrorType.cs rename to Interpreter.Lib/FrontEnd/GetTokens/TokenTypes/ErrorType.cs index 2c8b46ea..345e14b2 100644 --- a/Interpreter.Lib/FrontEnd/Lex/TokenTypes/ErrorType.cs +++ b/Interpreter.Lib/FrontEnd/GetTokens/TokenTypes/ErrorType.cs @@ -1,4 +1,4 @@ -namespace Interpreter.Lib.FrontEnd.Lex.TokenTypes +namespace Interpreter.Lib.FrontEnd.GetTokens.TokenTypes { internal record ErrorType() : TokenType("ERROR", @"\S+", int.MaxValue) { diff --git a/Interpreter.Lib/FrontEnd/Lex/TokenTypes/TokenType.cs b/Interpreter.Lib/FrontEnd/GetTokens/TokenTypes/TokenType.cs similarity index 87% rename from Interpreter.Lib/FrontEnd/Lex/TokenTypes/TokenType.cs rename to Interpreter.Lib/FrontEnd/GetTokens/TokenTypes/TokenType.cs index e31f7e3f..10eaa67d 100644 --- a/Interpreter.Lib/FrontEnd/Lex/TokenTypes/TokenType.cs +++ b/Interpreter.Lib/FrontEnd/GetTokens/TokenTypes/TokenType.cs @@ -1,4 +1,4 @@ -namespace Interpreter.Lib.FrontEnd.Lex.TokenTypes +namespace Interpreter.Lib.FrontEnd.GetTokens.TokenTypes { public record TokenType(string Tag, string Pattern, int Priority) { diff --git a/Interpreter.Lib/FrontEnd/Lex/TokenTypes/WhiteSpaceType.cs b/Interpreter.Lib/FrontEnd/GetTokens/TokenTypes/WhiteSpaceType.cs similarity index 78% rename from Interpreter.Lib/FrontEnd/Lex/TokenTypes/WhiteSpaceType.cs rename to Interpreter.Lib/FrontEnd/GetTokens/TokenTypes/WhiteSpaceType.cs index cd542134..e7b804bd 100644 --- a/Interpreter.Lib/FrontEnd/Lex/TokenTypes/WhiteSpaceType.cs +++ b/Interpreter.Lib/FrontEnd/GetTokens/TokenTypes/WhiteSpaceType.cs @@ -1,4 +1,4 @@ -namespace Interpreter.Lib.FrontEnd.Lex.TokenTypes +namespace Interpreter.Lib.FrontEnd.GetTokens.TokenTypes { public record WhiteSpaceType(string Tag = null, string Pattern = null, int Priority = 0) : TokenType(Tag, Pattern, Priority) diff --git a/Interpreter.Lib/FrontEnd/Parse/Parser.cs b/Interpreter.Lib/FrontEnd/TopDownParse/Parser.cs similarity index 99% rename from Interpreter.Lib/FrontEnd/Parse/Parser.cs rename to Interpreter.Lib/FrontEnd/TopDownParse/Parser.cs index 766dadc1..9e8db151 100644 --- a/Interpreter.Lib/FrontEnd/Parse/Parser.cs +++ b/Interpreter.Lib/FrontEnd/TopDownParse/Parser.cs @@ -2,7 +2,7 @@ using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Text.RegularExpressions; -using Interpreter.Lib.FrontEnd.Lex; +using Interpreter.Lib.FrontEnd.GetTokens; using Interpreter.Lib.Semantic; using Interpreter.Lib.Semantic.Exceptions; using Interpreter.Lib.Semantic.Nodes; @@ -17,7 +17,7 @@ using Interpreter.Lib.Semantic.Utils; using Expression = Interpreter.Lib.Semantic.Nodes.Expressions.Expression; -namespace Interpreter.Lib.FrontEnd.Parse +namespace Interpreter.Lib.FrontEnd.TopDownParse { [SuppressMessage("ReSharper", "PossibleNullReferenceException")] public class Parser diff --git a/Interpreter.Lib/FrontEnd/Parse/ParserException.cs b/Interpreter.Lib/FrontEnd/TopDownParse/ParserException.cs similarity index 76% rename from Interpreter.Lib/FrontEnd/Parse/ParserException.cs rename to Interpreter.Lib/FrontEnd/TopDownParse/ParserException.cs index 257b37e0..cabcf08f 100644 --- a/Interpreter.Lib/FrontEnd/Parse/ParserException.cs +++ b/Interpreter.Lib/FrontEnd/TopDownParse/ParserException.cs @@ -1,7 +1,7 @@ using System; -using Interpreter.Lib.FrontEnd.Lex; +using Interpreter.Lib.FrontEnd.GetTokens; -namespace Interpreter.Lib.FrontEnd.Parse +namespace Interpreter.Lib.FrontEnd.TopDownParse { public class ParserException : Exception { diff --git a/Interpreter.Lib/Semantic/Exceptions/ArrayAccessException.cs b/Interpreter.Lib/Semantic/Exceptions/ArrayAccessException.cs index b7db64de..eb587ec8 100644 --- a/Interpreter.Lib/Semantic/Exceptions/ArrayAccessException.cs +++ b/Interpreter.Lib/Semantic/Exceptions/ArrayAccessException.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.FrontEnd.Lex; +using Interpreter.Lib.FrontEnd.GetTokens; using Interpreter.Lib.Semantic.Types; namespace Interpreter.Lib.Semantic.Exceptions diff --git a/Interpreter.Lib/Semantic/Exceptions/CannotDefineType.cs b/Interpreter.Lib/Semantic/Exceptions/CannotDefineType.cs index d1906f8c..07eca43e 100644 --- a/Interpreter.Lib/Semantic/Exceptions/CannotDefineType.cs +++ b/Interpreter.Lib/Semantic/Exceptions/CannotDefineType.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.FrontEnd.Lex; +using Interpreter.Lib.FrontEnd.GetTokens; namespace Interpreter.Lib.Semantic.Exceptions { diff --git a/Interpreter.Lib/Semantic/Exceptions/FunctionWithoutReturnStatement.cs b/Interpreter.Lib/Semantic/Exceptions/FunctionWithoutReturnStatement.cs index 94a94b3a..b1c4d548 100644 --- a/Interpreter.Lib/Semantic/Exceptions/FunctionWithoutReturnStatement.cs +++ b/Interpreter.Lib/Semantic/Exceptions/FunctionWithoutReturnStatement.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.FrontEnd.Lex; +using Interpreter.Lib.FrontEnd.GetTokens; namespace Interpreter.Lib.Semantic.Exceptions { diff --git a/Interpreter.Lib/Semantic/Exceptions/IncompatibleTypesOfOperands.cs b/Interpreter.Lib/Semantic/Exceptions/IncompatibleTypesOfOperands.cs index e87306c7..99e693d3 100644 --- a/Interpreter.Lib/Semantic/Exceptions/IncompatibleTypesOfOperands.cs +++ b/Interpreter.Lib/Semantic/Exceptions/IncompatibleTypesOfOperands.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.FrontEnd.Lex; +using Interpreter.Lib.FrontEnd.GetTokens; using Interpreter.Lib.Semantic.Types; namespace Interpreter.Lib.Semantic.Exceptions diff --git a/Interpreter.Lib/Semantic/Exceptions/NotBooleanTestExpression.cs b/Interpreter.Lib/Semantic/Exceptions/NotBooleanTestExpression.cs index 3ad391d0..2712ba22 100644 --- a/Interpreter.Lib/Semantic/Exceptions/NotBooleanTestExpression.cs +++ b/Interpreter.Lib/Semantic/Exceptions/NotBooleanTestExpression.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.FrontEnd.Lex; +using Interpreter.Lib.FrontEnd.GetTokens; using Interpreter.Lib.Semantic.Types; namespace Interpreter.Lib.Semantic.Exceptions diff --git a/Interpreter.Lib/Semantic/Exceptions/ObjectAccessException.cs b/Interpreter.Lib/Semantic/Exceptions/ObjectAccessException.cs index 6c3f38e5..5b473cfc 100644 --- a/Interpreter.Lib/Semantic/Exceptions/ObjectAccessException.cs +++ b/Interpreter.Lib/Semantic/Exceptions/ObjectAccessException.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.FrontEnd.Lex; +using Interpreter.Lib.FrontEnd.GetTokens; using Interpreter.Lib.Semantic.Types; namespace Interpreter.Lib.Semantic.Exceptions diff --git a/Interpreter.Lib/Semantic/Exceptions/OutsideOfLoop.cs b/Interpreter.Lib/Semantic/Exceptions/OutsideOfLoop.cs index c878a909..cbd33576 100644 --- a/Interpreter.Lib/Semantic/Exceptions/OutsideOfLoop.cs +++ b/Interpreter.Lib/Semantic/Exceptions/OutsideOfLoop.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.FrontEnd.Lex; +using Interpreter.Lib.FrontEnd.GetTokens; namespace Interpreter.Lib.Semantic.Exceptions { diff --git a/Interpreter.Lib/Semantic/Exceptions/ReturnOutsideFunction.cs b/Interpreter.Lib/Semantic/Exceptions/ReturnOutsideFunction.cs index b4794135..0c89e774 100644 --- a/Interpreter.Lib/Semantic/Exceptions/ReturnOutsideFunction.cs +++ b/Interpreter.Lib/Semantic/Exceptions/ReturnOutsideFunction.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.FrontEnd.Lex; +using Interpreter.Lib.FrontEnd.GetTokens; namespace Interpreter.Lib.Semantic.Exceptions { diff --git a/Interpreter.Lib/Semantic/Exceptions/SymbolIsNotCallable.cs b/Interpreter.Lib/Semantic/Exceptions/SymbolIsNotCallable.cs index cfb3dfdf..3ba15808 100644 --- a/Interpreter.Lib/Semantic/Exceptions/SymbolIsNotCallable.cs +++ b/Interpreter.Lib/Semantic/Exceptions/SymbolIsNotCallable.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.FrontEnd.Lex; +using Interpreter.Lib.FrontEnd.GetTokens; namespace Interpreter.Lib.Semantic.Exceptions { diff --git a/Interpreter.Lib/Semantic/Exceptions/UnsupportedOperation.cs b/Interpreter.Lib/Semantic/Exceptions/UnsupportedOperation.cs index 06cafd8c..629878b4 100644 --- a/Interpreter.Lib/Semantic/Exceptions/UnsupportedOperation.cs +++ b/Interpreter.Lib/Semantic/Exceptions/UnsupportedOperation.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.FrontEnd.Lex; +using Interpreter.Lib.FrontEnd.GetTokens; using Interpreter.Lib.Semantic.Types; namespace Interpreter.Lib.Semantic.Exceptions diff --git a/Interpreter.Lib/Semantic/Exceptions/WrongArrayLiteralDeclaration.cs b/Interpreter.Lib/Semantic/Exceptions/WrongArrayLiteralDeclaration.cs index 144839d8..07190e73 100644 --- a/Interpreter.Lib/Semantic/Exceptions/WrongArrayLiteralDeclaration.cs +++ b/Interpreter.Lib/Semantic/Exceptions/WrongArrayLiteralDeclaration.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.FrontEnd.Lex; +using Interpreter.Lib.FrontEnd.GetTokens; using Interpreter.Lib.Semantic.Types; namespace Interpreter.Lib.Semantic.Exceptions diff --git a/Interpreter.Lib/Semantic/Exceptions/WrongConditionalTypes.cs b/Interpreter.Lib/Semantic/Exceptions/WrongConditionalTypes.cs index 43bd3171..8f3699fe 100644 --- a/Interpreter.Lib/Semantic/Exceptions/WrongConditionalTypes.cs +++ b/Interpreter.Lib/Semantic/Exceptions/WrongConditionalTypes.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.FrontEnd.Lex; +using Interpreter.Lib.FrontEnd.GetTokens; using Interpreter.Lib.Semantic.Types; namespace Interpreter.Lib.Semantic.Exceptions diff --git a/Interpreter.Lib/Semantic/Exceptions/WrongNumberOfArguments.cs b/Interpreter.Lib/Semantic/Exceptions/WrongNumberOfArguments.cs index 6a8599ad..eae17a07 100644 --- a/Interpreter.Lib/Semantic/Exceptions/WrongNumberOfArguments.cs +++ b/Interpreter.Lib/Semantic/Exceptions/WrongNumberOfArguments.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.FrontEnd.Lex; +using Interpreter.Lib.FrontEnd.GetTokens; namespace Interpreter.Lib.Semantic.Exceptions { diff --git a/Interpreter.Lib/Semantic/Exceptions/WrongReturnType.cs b/Interpreter.Lib/Semantic/Exceptions/WrongReturnType.cs index da8a59f8..53c576e5 100644 --- a/Interpreter.Lib/Semantic/Exceptions/WrongReturnType.cs +++ b/Interpreter.Lib/Semantic/Exceptions/WrongReturnType.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.FrontEnd.Lex; +using Interpreter.Lib.FrontEnd.GetTokens; using Interpreter.Lib.Semantic.Types; namespace Interpreter.Lib.Semantic.Exceptions diff --git a/Interpreter.Lib/Semantic/Exceptions/WrongTypeOfArgument.cs b/Interpreter.Lib/Semantic/Exceptions/WrongTypeOfArgument.cs index a1f42cb7..7cd7233e 100644 --- a/Interpreter.Lib/Semantic/Exceptions/WrongTypeOfArgument.cs +++ b/Interpreter.Lib/Semantic/Exceptions/WrongTypeOfArgument.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.FrontEnd.Lex; +using Interpreter.Lib.FrontEnd.GetTokens; using Interpreter.Lib.Semantic.Types; namespace Interpreter.Lib.Semantic.Exceptions diff --git a/Interpreter.Lib/Semantic/Nodes/AbstractSyntaxTreeNode.cs b/Interpreter.Lib/Semantic/Nodes/AbstractSyntaxTreeNode.cs index 82a53622..ddb879fc 100644 --- a/Interpreter.Lib/Semantic/Nodes/AbstractSyntaxTreeNode.cs +++ b/Interpreter.Lib/Semantic/Nodes/AbstractSyntaxTreeNode.cs @@ -1,6 +1,6 @@ using System.Collections; using System.Collections.Generic; -using Interpreter.Lib.FrontEnd.Lex; +using Interpreter.Lib.FrontEnd.GetTokens; using Interpreter.Lib.IR.Instructions; using Interpreter.Lib.Semantic.Nodes.Declarations; using Interpreter.Lib.Semantic.Types; diff --git a/Interpreter.Lib/Semantic/Nodes/Declarations/LexicalDeclaration.cs b/Interpreter.Lib/Semantic/Nodes/Declarations/LexicalDeclaration.cs index 61022c33..d981767c 100644 --- a/Interpreter.Lib/Semantic/Nodes/Declarations/LexicalDeclaration.cs +++ b/Interpreter.Lib/Semantic/Nodes/Declarations/LexicalDeclaration.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; using System.Linq; -using Interpreter.Lib.FrontEnd.Lex; +using Interpreter.Lib.FrontEnd.GetTokens; using Interpreter.Lib.IR.Instructions; using Interpreter.Lib.Semantic.Nodes.Expressions; using Interpreter.Lib.Semantic.Nodes.Expressions.PrimaryExpressions; diff --git a/Interpreter.Lib/Semantic/Nodes/Expressions/PrimaryExpressions/Literal.cs b/Interpreter.Lib/Semantic/Nodes/Expressions/PrimaryExpressions/Literal.cs index aa2a2b7d..979c81bf 100644 --- a/Interpreter.Lib/Semantic/Nodes/Expressions/PrimaryExpressions/Literal.cs +++ b/Interpreter.Lib/Semantic/Nodes/Expressions/PrimaryExpressions/Literal.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.FrontEnd.Lex; +using Interpreter.Lib.FrontEnd.GetTokens; using Interpreter.Lib.VM.Values; using Type = Interpreter.Lib.Semantic.Types.Type; diff --git a/Interpreter.Lib/Semantic/Utils/SymbolTableUtils.cs b/Interpreter.Lib/Semantic/Utils/SymbolTableUtils.cs index 70046172..7c040272 100644 --- a/Interpreter.Lib/Semantic/Utils/SymbolTableUtils.cs +++ b/Interpreter.Lib/Semantic/Utils/SymbolTableUtils.cs @@ -1,5 +1,5 @@ using System.Collections.Generic; -using Interpreter.Lib.FrontEnd.Lex; +using Interpreter.Lib.FrontEnd.GetTokens; using Interpreter.Lib.Semantic.Nodes; using Interpreter.Lib.Semantic.Nodes.Declarations; using Interpreter.Lib.Semantic.Nodes.Statements; diff --git a/Interpreter.Tests/Unit/ParserTests.cs b/Interpreter.Tests/Unit/ParserTests.cs index 7f982f5b..9799b7a7 100644 --- a/Interpreter.Tests/Unit/ParserTests.cs +++ b/Interpreter.Tests/Unit/ParserTests.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.FrontEnd.Parse; +using Interpreter.Lib.FrontEnd.TopDownParse; using Interpreter.Models; using Interpreter.Services.Providers; using Interpreter.Tests.TestData; diff --git a/Interpreter/MappingProfiles/TokenTypeProfile.cs b/Interpreter/MappingProfiles/TokenTypeProfile.cs index 590bfc5c..51b0c1a0 100644 --- a/Interpreter/MappingProfiles/TokenTypeProfile.cs +++ b/Interpreter/MappingProfiles/TokenTypeProfile.cs @@ -1,5 +1,5 @@ using AutoMapper; -using Interpreter.Lib.FrontEnd.Lex.TokenTypes; +using Interpreter.Lib.FrontEnd.GetTokens.TokenTypes; using Interpreter.Models; namespace Interpreter.MappingProfiles diff --git a/Interpreter/Models/LexerQueryModel.cs b/Interpreter/Models/LexerQueryModel.cs index 6e29bef1..eea615aa 100644 --- a/Interpreter/Models/LexerQueryModel.cs +++ b/Interpreter/Models/LexerQueryModel.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using AutoMapper; -using Interpreter.Lib.FrontEnd.Lex; -using Interpreter.Lib.FrontEnd.Lex.TokenTypes; +using Interpreter.Lib.FrontEnd.GetTokens; +using Interpreter.Lib.FrontEnd.GetTokens.TokenTypes; using Newtonsoft.Json; namespace Interpreter.Models diff --git a/Interpreter/Services/Executor/Impl/Executor.cs b/Interpreter/Services/Executor/Impl/Executor.cs index 82233352..1518c321 100644 --- a/Interpreter/Services/Executor/Impl/Executor.cs +++ b/Interpreter/Services/Executor/Impl/Executor.cs @@ -1,8 +1,8 @@ using System; using System.IO; using System.Linq; -using Interpreter.Lib.FrontEnd.Lex; -using Interpreter.Lib.FrontEnd.Parse; +using Interpreter.Lib.FrontEnd.GetTokens; +using Interpreter.Lib.FrontEnd.TopDownParse; using Interpreter.Lib.IR; using Interpreter.Lib.IR.Instructions; using Interpreter.Lib.IR.Optimizers; diff --git a/Interpreter/Services/Providers/ILexerProvider.cs b/Interpreter/Services/Providers/ILexerProvider.cs index e9384822..72f17b01 100644 --- a/Interpreter/Services/Providers/ILexerProvider.cs +++ b/Interpreter/Services/Providers/ILexerProvider.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.FrontEnd.Lex; +using Interpreter.Lib.FrontEnd.GetTokens; using Interpreter.Models; namespace Interpreter.Services.Providers diff --git a/Interpreter/Services/Providers/IParserProvider.cs b/Interpreter/Services/Providers/IParserProvider.cs index ae18472d..7e4ecfd5 100644 --- a/Interpreter/Services/Providers/IParserProvider.cs +++ b/Interpreter/Services/Providers/IParserProvider.cs @@ -1,5 +1,5 @@ -using Interpreter.Lib.FrontEnd.Lex; -using Interpreter.Lib.FrontEnd.Parse; +using Interpreter.Lib.FrontEnd.GetTokens; +using Interpreter.Lib.FrontEnd.TopDownParse; namespace Interpreter.Services.Providers { diff --git a/Interpreter/Services/Providers/Impl/LexerProvider.cs b/Interpreter/Services/Providers/Impl/LexerProvider.cs index a55395eb..f0e1dc5f 100644 --- a/Interpreter/Services/Providers/Impl/LexerProvider.cs +++ b/Interpreter/Services/Providers/Impl/LexerProvider.cs @@ -1,5 +1,5 @@ using AutoMapper; -using Interpreter.Lib.FrontEnd.Lex; +using Interpreter.Lib.FrontEnd.GetTokens; using Interpreter.Models; namespace Interpreter.Services.Providers.Impl diff --git a/Interpreter/Services/Providers/Impl/ParserProvider.cs b/Interpreter/Services/Providers/Impl/ParserProvider.cs index 4e19f7c7..85421f4d 100644 --- a/Interpreter/Services/Providers/Impl/ParserProvider.cs +++ b/Interpreter/Services/Providers/Impl/ParserProvider.cs @@ -1,5 +1,5 @@ -using Interpreter.Lib.FrontEnd.Lex; -using Interpreter.Lib.FrontEnd.Parse; +using Interpreter.Lib.FrontEnd.GetTokens; +using Interpreter.Lib.FrontEnd.TopDownParse; namespace Interpreter.Services.Providers.Impl { From 8d3c28fe23ea516ba1a24f79744a42b5b0bb5789 Mon Sep 17 00:00:00 2001 From: Stepami Date: Mon, 12 Sep 2022 11:40:00 +0300 Subject: [PATCH 11/56] =?UTF-8?q?=D0=92=20=D1=80=D0=B0=D0=BC=D0=BA=D0=B0?= =?UTF-8?q?=D1=85=20=D0=BF=D1=80=D0=BE=D0=B5=D0=BA=D1=82=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=B8=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BD=D1=82=D0=B5=D0=BA=D1=81=D1=82=20FrontEnd,=20=D0=B3=D0=B4?= =?UTF-8?q?=D0=B5=20=D0=BD=D0=B0=D1=85=D0=BE=D0=B4=D1=8F=D1=82=D1=81=D1=8F?= =?UTF-8?q?=20=D1=81=D1=83=D1=89=D0=BD=D0=BE=D1=81=D1=82=D0=B8,=20=D0=BE?= =?UTF-8?q?=D1=82=D0=B2=D0=B5=D1=87=D0=B0=D1=8E=D1=89=D0=B8=D0=B5=20=D0=B7?= =?UTF-8?q?=D0=B0=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=20AST?= =?UTF-8?q?,=20=D0=B2=D0=BA=D0=BB=D1=8E=D1=87=D0=B0=D1=8F=20=D1=81=D0=B0?= =?UTF-8?q?=D0=BC=D0=BE=20AST?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Interpreter.Lib/Contracts/IParser.cs | 7 --- .../FrontEnd/GetTokens/Coordinates.cs | 49 ---------------- .../GetTokens}/ILexer.cs | 4 +- .../FrontEnd/GetTokens/{ => Impl}/Lexer.cs | 27 +++++---- .../GetTokens/{ => Impl}/Structure.cs | 4 +- .../FrontEnd/GetTokens/Impl/Token.cs | 56 +++++++++++++++++++ .../{ => Impl}/TokenTypes/EndOfProgramType.cs | 2 +- .../{ => Impl}/TokenTypes/ErrorType.cs | 2 +- .../{ => Impl}/TokenTypes/TokenType.cs | 2 +- .../{ => Impl}/TokenTypes/WhiteSpaceType.cs | 2 +- .../FrontEnd/GetTokens/LexerException.cs | 1 + .../FrontEnd/GetTokens/LexerUtils.cs | 2 +- Interpreter.Lib/FrontEnd/GetTokens/Segment.cs | 33 ----------- Interpreter.Lib/FrontEnd/GetTokens/Token.cs | 48 ---------------- .../FrontEnd/TopDownParse/IParser.cs | 9 +++ .../TopDownParse/{ => Impl}/Parser.cs | 43 +++++++------- .../TopDownParse/Impl}/TokensStream.cs | 4 +- .../FrontEnd/TopDownParse/ParserException.cs | 2 +- .../Exceptions/ArrayAccessException.cs | 2 +- .../Semantic/Exceptions/CannotDefineType.cs | 2 +- .../FunctionWithoutReturnStatement.cs | 2 +- .../Exceptions/IncompatibleTypesOfOperands.cs | 2 +- .../Exceptions/NotBooleanTestExpression.cs | 2 +- .../Exceptions/ObjectAccessException.cs | 2 +- .../Semantic/Exceptions/OutsideOfLoop.cs | 2 +- .../Exceptions/ReturnOutsideFunction.cs | 2 +- .../Exceptions/SymbolIsNotCallable.cs | 2 +- .../Exceptions/UnsupportedOperation.cs | 2 +- .../WrongArrayLiteralDeclaration.cs | 2 +- .../Exceptions/WrongConditionalTypes.cs | 2 +- .../Exceptions/WrongNumberOfArguments.cs | 2 +- .../Semantic/Exceptions/WrongReturnType.cs | 2 +- .../Exceptions/WrongTypeOfArgument.cs | 2 +- .../Semantic/Nodes/AbstractSyntaxTreeNode.cs | 2 +- .../Nodes/Declarations/LexicalDeclaration.cs | 2 +- .../Expressions/PrimaryExpressions/Literal.cs | 2 +- .../Semantic/Utils/SymbolTableUtils.cs | 2 +- Interpreter.Tests/Unit/ParserTests.cs | 4 +- .../MappingProfiles/TokenTypeProfile.cs | 2 +- Interpreter/Models/LexerQueryModel.cs | 8 +-- .../Services/Executor/Impl/Executor.cs | 6 +- .../Services/Providers/ILexerProvider.cs | 2 +- .../Services/Providers/IParserProvider.cs | 4 +- .../Services/Providers/Impl/LexerProvider.cs | 7 +-- .../Services/Providers/Impl/ParserProvider.cs | 4 +- 45 files changed, 156 insertions(+), 216 deletions(-) delete mode 100644 Interpreter.Lib/Contracts/IParser.cs delete mode 100644 Interpreter.Lib/FrontEnd/GetTokens/Coordinates.cs rename Interpreter.Lib/{Contracts => FrontEnd/GetTokens}/ILexer.cs (63%) rename Interpreter.Lib/FrontEnd/GetTokens/{ => Impl}/Lexer.cs (64%) rename Interpreter.Lib/FrontEnd/GetTokens/{ => Impl}/Structure.cs (93%) create mode 100644 Interpreter.Lib/FrontEnd/GetTokens/Impl/Token.cs rename Interpreter.Lib/FrontEnd/GetTokens/{ => Impl}/TokenTypes/EndOfProgramType.cs (70%) rename Interpreter.Lib/FrontEnd/GetTokens/{ => Impl}/TokenTypes/ErrorType.cs (69%) rename Interpreter.Lib/FrontEnd/GetTokens/{ => Impl}/TokenTypes/TokenType.cs (87%) rename Interpreter.Lib/FrontEnd/GetTokens/{ => Impl}/TokenTypes/WhiteSpaceType.cs (76%) delete mode 100644 Interpreter.Lib/FrontEnd/GetTokens/Segment.cs delete mode 100644 Interpreter.Lib/FrontEnd/GetTokens/Token.cs create mode 100644 Interpreter.Lib/FrontEnd/TopDownParse/IParser.cs rename Interpreter.Lib/FrontEnd/TopDownParse/{ => Impl}/Parser.cs (96%) rename Interpreter.Lib/{Contracts => FrontEnd/TopDownParse/Impl}/TokensStream.cs (85%) diff --git a/Interpreter.Lib/Contracts/IParser.cs b/Interpreter.Lib/Contracts/IParser.cs deleted file mode 100644 index 47a69c2a..00000000 --- a/Interpreter.Lib/Contracts/IParser.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Interpreter.Lib.Contracts -{ - public interface IParser - { - IAbstractSyntaxTree TopDownParse(string text); - } -} \ No newline at end of file diff --git a/Interpreter.Lib/FrontEnd/GetTokens/Coordinates.cs b/Interpreter.Lib/FrontEnd/GetTokens/Coordinates.cs deleted file mode 100644 index 6092c934..00000000 --- a/Interpreter.Lib/FrontEnd/GetTokens/Coordinates.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System; -using System.Collections.Generic; -using Newtonsoft.Json; - -namespace Interpreter.Lib.FrontEnd.GetTokens -{ - public class Coordinates : IEquatable - { - [JsonProperty] private readonly int _line, _column; - - public Coordinates(int line, int column) - { - (_line, _column) = (line, column); - } - - public Coordinates(int absolutePos, List system) - { - for (var i = 0; i < system.Count; i++) - if (absolutePos <= system[i]) - { - var offset = i == 0 ? -1 : system[i - 1]; - _line = i + 1; - _column = absolutePos - offset; - break; - } - - if (_line == 0) - { - _column = 1; - _line = system.Count + 1; - } - } - - public override string ToString() - { - return $"({_line}, {_column})"; - } - - public override bool Equals(object obj) => Equals(obj as Coordinates); - - public override int GetHashCode() => HashCode.Combine(_line, _column); - - public bool Equals(Coordinates obj) - { - if (ReferenceEquals(null, obj)) return false; - return _line == obj._line && _column == obj._column; - } - } -} \ No newline at end of file diff --git a/Interpreter.Lib/Contracts/ILexer.cs b/Interpreter.Lib/FrontEnd/GetTokens/ILexer.cs similarity index 63% rename from Interpreter.Lib/Contracts/ILexer.cs rename to Interpreter.Lib/FrontEnd/GetTokens/ILexer.cs index 6e51b18b..8dc9095e 100644 --- a/Interpreter.Lib/Contracts/ILexer.cs +++ b/Interpreter.Lib/FrontEnd/GetTokens/ILexer.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; -using Interpreter.Lib.FrontEnd.GetTokens; +using Interpreter.Lib.FrontEnd.GetTokens.Impl; -namespace Interpreter.Lib.Contracts +namespace Interpreter.Lib.FrontEnd.GetTokens { public interface ILexer { diff --git a/Interpreter.Lib/FrontEnd/GetTokens/Lexer.cs b/Interpreter.Lib/FrontEnd/GetTokens/Impl/Lexer.cs similarity index 64% rename from Interpreter.Lib/FrontEnd/GetTokens/Lexer.cs rename to Interpreter.Lib/FrontEnd/GetTokens/Impl/Lexer.cs index cbb2db19..c0484a90 100644 --- a/Interpreter.Lib/FrontEnd/GetTokens/Lexer.cs +++ b/Interpreter.Lib/FrontEnd/GetTokens/Impl/Lexer.cs @@ -3,30 +3,35 @@ using System.Linq; using System.Text.RegularExpressions; -namespace Interpreter.Lib.FrontEnd.GetTokens +namespace Interpreter.Lib.FrontEnd.GetTokens.Impl { - public class Lexer : IEnumerable + public class Lexer : ILexer, IEnumerable { private readonly List _lines = new(); - private readonly string _source; + private string _text = ""; public Structure Structure { get; } - public Lexer(Structure structure, string source) - { + public Lexer(Structure structure) => Structure = structure; - _source = source; + + public List GetTokens(string text) + { + _text = text; var lineMatches = - new Regex(@"(?\n)").Matches(source[^1] == '\n' - ? source - : new string(source.Append('\n').ToArray())); - foreach (Match match in lineMatches) _lines.Add(match.Groups["NEWLINE"].Index); + new Regex(@"(?\n)").Matches(text[^1] == '\n' + ? text + : new string(text.Append('\n').ToArray())); + foreach (Match match in lineMatches) + _lines.Add(match.Groups["NEWLINE"].Index); + + return this.Where(t => !t.Type.WhiteSpace()).ToList(); } public IEnumerator GetEnumerator() { - var matches = Structure.Regex.Matches(_source); + var matches = Structure.Regex.Matches(_text); foreach (Match match in matches) { foreach (var type in Structure) diff --git a/Interpreter.Lib/FrontEnd/GetTokens/Structure.cs b/Interpreter.Lib/FrontEnd/GetTokens/Impl/Structure.cs similarity index 93% rename from Interpreter.Lib/FrontEnd/GetTokens/Structure.cs rename to Interpreter.Lib/FrontEnd/GetTokens/Impl/Structure.cs index 671adcc9..c66b6fe2 100644 --- a/Interpreter.Lib/FrontEnd/GetTokens/Structure.cs +++ b/Interpreter.Lib/FrontEnd/GetTokens/Impl/Structure.cs @@ -3,9 +3,9 @@ using System.Linq; using System.Text; using System.Text.RegularExpressions; -using Interpreter.Lib.FrontEnd.GetTokens.TokenTypes; +using Interpreter.Lib.FrontEnd.GetTokens.Impl.TokenTypes; -namespace Interpreter.Lib.FrontEnd.GetTokens +namespace Interpreter.Lib.FrontEnd.GetTokens.Impl { public class Structure : IEnumerable { diff --git a/Interpreter.Lib/FrontEnd/GetTokens/Impl/Token.cs b/Interpreter.Lib/FrontEnd/GetTokens/Impl/Token.cs new file mode 100644 index 00000000..53ffc3b7 --- /dev/null +++ b/Interpreter.Lib/FrontEnd/GetTokens/Impl/Token.cs @@ -0,0 +1,56 @@ +using System.Collections.Generic; +using System.Text.RegularExpressions; +using Interpreter.Lib.FrontEnd.GetTokens.Impl.TokenTypes; + +namespace Interpreter.Lib.FrontEnd.GetTokens.Impl +{ + public record Token(TokenType Type) + { + public Segment Segment { get; } + + public string Value { get; } + + public Token(TokenType type, Segment segment, string value) : this(type) + { + (Segment, Value) = (segment, value); + } + + public override string ToString() + { + var displayValue = Value; + if (displayValue != null) displayValue = Regex.Replace(Value, "\"", "\\\""); + if (Type.WhiteSpace()) displayValue = ""; + return $"{Type} {Segment}: {displayValue}"; + } + } + + public record Segment(Coordinates Start, Coordinates End) + { + public override string ToString() => $"{Start}-{End}"; + + public static Segment operator +(Segment left, Segment right) => + new(left.Start, right.End); + } + + public record Coordinates(int Line, int Column) + { + public Coordinates(int absolutePos, IReadOnlyList system) : + this(0, 0) + { + for (var i = 0; i < system.Count; i++) + if (absolutePos <= system[i]) + { + var offset = i == 0 ? -1 : system[i - 1]; + (Line, Column) = (i + 1, absolutePos - offset); + break; + } + + if (Line == 0) + { + (Line, Column) = (system.Count + 1, 1); + } + } + + public override string ToString() => $"({Line}, {Column})"; + } +} \ No newline at end of file diff --git a/Interpreter.Lib/FrontEnd/GetTokens/TokenTypes/EndOfProgramType.cs b/Interpreter.Lib/FrontEnd/GetTokens/Impl/TokenTypes/EndOfProgramType.cs similarity index 70% rename from Interpreter.Lib/FrontEnd/GetTokens/TokenTypes/EndOfProgramType.cs rename to Interpreter.Lib/FrontEnd/GetTokens/Impl/TokenTypes/EndOfProgramType.cs index 89230c2a..8d1f1f21 100644 --- a/Interpreter.Lib/FrontEnd/GetTokens/TokenTypes/EndOfProgramType.cs +++ b/Interpreter.Lib/FrontEnd/GetTokens/Impl/TokenTypes/EndOfProgramType.cs @@ -1,4 +1,4 @@ -namespace Interpreter.Lib.FrontEnd.GetTokens.TokenTypes +namespace Interpreter.Lib.FrontEnd.GetTokens.Impl.TokenTypes { internal record EndOfProgramType() : TokenType("EOP", "", int.MaxValue - 1) { diff --git a/Interpreter.Lib/FrontEnd/GetTokens/TokenTypes/ErrorType.cs b/Interpreter.Lib/FrontEnd/GetTokens/Impl/TokenTypes/ErrorType.cs similarity index 69% rename from Interpreter.Lib/FrontEnd/GetTokens/TokenTypes/ErrorType.cs rename to Interpreter.Lib/FrontEnd/GetTokens/Impl/TokenTypes/ErrorType.cs index 345e14b2..b07f5957 100644 --- a/Interpreter.Lib/FrontEnd/GetTokens/TokenTypes/ErrorType.cs +++ b/Interpreter.Lib/FrontEnd/GetTokens/Impl/TokenTypes/ErrorType.cs @@ -1,4 +1,4 @@ -namespace Interpreter.Lib.FrontEnd.GetTokens.TokenTypes +namespace Interpreter.Lib.FrontEnd.GetTokens.Impl.TokenTypes { internal record ErrorType() : TokenType("ERROR", @"\S+", int.MaxValue) { diff --git a/Interpreter.Lib/FrontEnd/GetTokens/TokenTypes/TokenType.cs b/Interpreter.Lib/FrontEnd/GetTokens/Impl/TokenTypes/TokenType.cs similarity index 87% rename from Interpreter.Lib/FrontEnd/GetTokens/TokenTypes/TokenType.cs rename to Interpreter.Lib/FrontEnd/GetTokens/Impl/TokenTypes/TokenType.cs index 10eaa67d..e10ce5c7 100644 --- a/Interpreter.Lib/FrontEnd/GetTokens/TokenTypes/TokenType.cs +++ b/Interpreter.Lib/FrontEnd/GetTokens/Impl/TokenTypes/TokenType.cs @@ -1,4 +1,4 @@ -namespace Interpreter.Lib.FrontEnd.GetTokens.TokenTypes +namespace Interpreter.Lib.FrontEnd.GetTokens.Impl.TokenTypes { public record TokenType(string Tag, string Pattern, int Priority) { diff --git a/Interpreter.Lib/FrontEnd/GetTokens/TokenTypes/WhiteSpaceType.cs b/Interpreter.Lib/FrontEnd/GetTokens/Impl/TokenTypes/WhiteSpaceType.cs similarity index 76% rename from Interpreter.Lib/FrontEnd/GetTokens/TokenTypes/WhiteSpaceType.cs rename to Interpreter.Lib/FrontEnd/GetTokens/Impl/TokenTypes/WhiteSpaceType.cs index e7b804bd..5e7742bb 100644 --- a/Interpreter.Lib/FrontEnd/GetTokens/TokenTypes/WhiteSpaceType.cs +++ b/Interpreter.Lib/FrontEnd/GetTokens/Impl/TokenTypes/WhiteSpaceType.cs @@ -1,4 +1,4 @@ -namespace Interpreter.Lib.FrontEnd.GetTokens.TokenTypes +namespace Interpreter.Lib.FrontEnd.GetTokens.Impl.TokenTypes { public record WhiteSpaceType(string Tag = null, string Pattern = null, int Priority = 0) : TokenType(Tag, Pattern, Priority) diff --git a/Interpreter.Lib/FrontEnd/GetTokens/LexerException.cs b/Interpreter.Lib/FrontEnd/GetTokens/LexerException.cs index 480e1b6a..ced5f3d7 100644 --- a/Interpreter.Lib/FrontEnd/GetTokens/LexerException.cs +++ b/Interpreter.Lib/FrontEnd/GetTokens/LexerException.cs @@ -1,4 +1,5 @@ using System; +using Interpreter.Lib.FrontEnd.GetTokens.Impl; namespace Interpreter.Lib.FrontEnd.GetTokens { diff --git a/Interpreter.Lib/FrontEnd/GetTokens/LexerUtils.cs b/Interpreter.Lib/FrontEnd/GetTokens/LexerUtils.cs index c91125e9..6bec3b10 100644 --- a/Interpreter.Lib/FrontEnd/GetTokens/LexerUtils.cs +++ b/Interpreter.Lib/FrontEnd/GetTokens/LexerUtils.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.FrontEnd.GetTokens.TokenTypes; +using Interpreter.Lib.FrontEnd.GetTokens.Impl.TokenTypes; namespace Interpreter.Lib.FrontEnd.GetTokens { diff --git a/Interpreter.Lib/FrontEnd/GetTokens/Segment.cs b/Interpreter.Lib/FrontEnd/GetTokens/Segment.cs deleted file mode 100644 index 9099a9e4..00000000 --- a/Interpreter.Lib/FrontEnd/GetTokens/Segment.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System; -using Newtonsoft.Json; - -namespace Interpreter.Lib.FrontEnd.GetTokens -{ - public class Segment : IEquatable - { - [JsonProperty] private readonly Coordinates _start, _end; - - public Segment(Coordinates start, Coordinates end) - { - (_start, _end) = (start, end); - } - - public override string ToString() - { - return $"{_start}-{_end}"; - } - - public override bool Equals(object obj) => Equals(obj as Segment); - - public override int GetHashCode() => HashCode.Combine(_start, _end); - - public bool Equals(Segment obj) - { - if (ReferenceEquals(null, obj)) return false; - return Equals(_start, obj._start) && Equals(_end, obj._end); - } - - public static Segment operator +(Segment left, Segment right) => - new(left._start, right._end); - } -} \ No newline at end of file diff --git a/Interpreter.Lib/FrontEnd/GetTokens/Token.cs b/Interpreter.Lib/FrontEnd/GetTokens/Token.cs deleted file mode 100644 index 98bcadf1..00000000 --- a/Interpreter.Lib/FrontEnd/GetTokens/Token.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System; -using System.Text.RegularExpressions; -using Interpreter.Lib.FrontEnd.GetTokens.TokenTypes; - -namespace Interpreter.Lib.FrontEnd.GetTokens -{ - public class Token : ICloneable, IEquatable - { - public Segment Segment { get; } - - public Token(TokenType type) - { - Type = type; - } - - public Token(TokenType type, Segment segment, string value) : this(type) - { - (Segment, Value) = (segment, value); - } - - public TokenType Type { get; } - - public string Value { get; } - - public override string ToString() - { - var displayValue = Value; - if (displayValue != null) displayValue = Regex.Replace(Value, "\"", "\\\""); - if (Type.WhiteSpace()) displayValue = ""; - return $"{Type} {Segment}: {displayValue}"; - } - - public object Clone() - { - return new Token(Type, Segment, Value); - } - - public override bool Equals(object obj) => Equals(obj as Token); - - public override int GetHashCode() => HashCode.Combine(Type, Segment, Value); - - public bool Equals(Token obj) - { - if (ReferenceEquals(null, obj)) return false; - return Type == obj.Type && Equals(Segment, obj.Segment) && Value == obj.Value; - } - } -} \ No newline at end of file diff --git a/Interpreter.Lib/FrontEnd/TopDownParse/IParser.cs b/Interpreter.Lib/FrontEnd/TopDownParse/IParser.cs new file mode 100644 index 00000000..803f2ad5 --- /dev/null +++ b/Interpreter.Lib/FrontEnd/TopDownParse/IParser.cs @@ -0,0 +1,9 @@ +using Interpreter.Lib.Semantic; + +namespace Interpreter.Lib.FrontEnd.TopDownParse +{ + public interface IParser + { + AbstractSyntaxTree TopDownParse(string text); + } +} \ No newline at end of file diff --git a/Interpreter.Lib/FrontEnd/TopDownParse/Parser.cs b/Interpreter.Lib/FrontEnd/TopDownParse/Impl/Parser.cs similarity index 96% rename from Interpreter.Lib/FrontEnd/TopDownParse/Parser.cs rename to Interpreter.Lib/FrontEnd/TopDownParse/Impl/Parser.cs index 9e8db151..409a1fcf 100644 --- a/Interpreter.Lib/FrontEnd/TopDownParse/Parser.cs +++ b/Interpreter.Lib/FrontEnd/TopDownParse/Impl/Parser.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Text.RegularExpressions; using Interpreter.Lib.FrontEnd.GetTokens; +using Interpreter.Lib.FrontEnd.GetTokens.Impl; using Interpreter.Lib.Semantic; using Interpreter.Lib.Semantic.Exceptions; using Interpreter.Lib.Semantic.Nodes; @@ -17,20 +18,16 @@ using Interpreter.Lib.Semantic.Utils; using Expression = Interpreter.Lib.Semantic.Nodes.Expressions.Expression; -namespace Interpreter.Lib.FrontEnd.TopDownParse +namespace Interpreter.Lib.FrontEnd.TopDownParse.Impl { [SuppressMessage("ReSharper", "PossibleNullReferenceException")] - public class Parser + public class Parser : IParser { - private readonly IEnumerator _tokens; - private readonly Structure _structure; + private TokensStream _tokens; + private readonly ILexer _lexer; - public Parser(Lexer lexer) - { - _tokens = lexer.Where(t => !t.Type.WhiteSpace()).GetEnumerator(); - _tokens.MoveNext(); - _structure = lexer.Structure; - } + public Parser(ILexer lexer) => + _lexer = lexer; private Token Expect(string expectedTag, string expectedValue = null) { @@ -49,20 +46,28 @@ private Token Expect(string expectedTag, string expectedValue = null) return current; } - private bool CurrentIs(string tag) => _tokens.Current.Type == _structure.FindByTag(tag); + private bool CurrentIs(string tag) => + _tokens.Current.Type == _lexer.Structure.FindByTag(tag); - private bool CurrentIsLiteral() => CurrentIs("NullLiteral") || - CurrentIs("IntegerLiteral") || - CurrentIs("FloatLiteral") || - CurrentIs("StringLiteral") || - CurrentIs("BooleanLiteral"); + private bool CurrentIsLiteral() => + CurrentIs("NullLiteral") || + CurrentIs("IntegerLiteral") || + CurrentIs("FloatLiteral") || + CurrentIs("StringLiteral") || + CurrentIs("BooleanLiteral"); - private bool CurrentIsKeyword(string keyword) => CurrentIs("Keyword") && _tokens.Current.Value == keyword; + private bool CurrentIsKeyword(string keyword) => + CurrentIs("Keyword") && + _tokens.Current.Value == keyword; - private bool CurrentIsOperator(string @operator) => CurrentIs("Operator") && _tokens.Current.Value == @operator; + private bool CurrentIsOperator(string @operator) => + CurrentIs("Operator") && + _tokens.Current.Value == @operator; - public AbstractSyntaxTree TopDownParse() + public AbstractSyntaxTree TopDownParse(string text) { + _tokens = _lexer.GetTokens(text); + var root = Script(SymbolTableUtils.GetStandardLibrary()); Expect("EOP"); return new AbstractSyntaxTree(root); diff --git a/Interpreter.Lib/Contracts/TokensStream.cs b/Interpreter.Lib/FrontEnd/TopDownParse/Impl/TokensStream.cs similarity index 85% rename from Interpreter.Lib/Contracts/TokensStream.cs rename to Interpreter.Lib/FrontEnd/TopDownParse/Impl/TokensStream.cs index a82a3d3b..a61660a9 100644 --- a/Interpreter.Lib/Contracts/TokensStream.cs +++ b/Interpreter.Lib/FrontEnd/TopDownParse/Impl/TokensStream.cs @@ -1,8 +1,8 @@ using System.Collections; using System.Collections.Generic; -using Interpreter.Lib.FrontEnd.GetTokens; +using Interpreter.Lib.FrontEnd.GetTokens.Impl; -namespace Interpreter.Lib.Contracts; +namespace Interpreter.Lib.FrontEnd.TopDownParse.Impl; public class TokensStream : IEnumerator { diff --git a/Interpreter.Lib/FrontEnd/TopDownParse/ParserException.cs b/Interpreter.Lib/FrontEnd/TopDownParse/ParserException.cs index cabcf08f..67f88fee 100644 --- a/Interpreter.Lib/FrontEnd/TopDownParse/ParserException.cs +++ b/Interpreter.Lib/FrontEnd/TopDownParse/ParserException.cs @@ -1,5 +1,5 @@ using System; -using Interpreter.Lib.FrontEnd.GetTokens; +using Interpreter.Lib.FrontEnd.GetTokens.Impl; namespace Interpreter.Lib.FrontEnd.TopDownParse { diff --git a/Interpreter.Lib/Semantic/Exceptions/ArrayAccessException.cs b/Interpreter.Lib/Semantic/Exceptions/ArrayAccessException.cs index eb587ec8..6924f2d3 100644 --- a/Interpreter.Lib/Semantic/Exceptions/ArrayAccessException.cs +++ b/Interpreter.Lib/Semantic/Exceptions/ArrayAccessException.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.FrontEnd.GetTokens; +using Interpreter.Lib.FrontEnd.GetTokens.Impl; using Interpreter.Lib.Semantic.Types; namespace Interpreter.Lib.Semantic.Exceptions diff --git a/Interpreter.Lib/Semantic/Exceptions/CannotDefineType.cs b/Interpreter.Lib/Semantic/Exceptions/CannotDefineType.cs index 07eca43e..72d93949 100644 --- a/Interpreter.Lib/Semantic/Exceptions/CannotDefineType.cs +++ b/Interpreter.Lib/Semantic/Exceptions/CannotDefineType.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.FrontEnd.GetTokens; +using Interpreter.Lib.FrontEnd.GetTokens.Impl; namespace Interpreter.Lib.Semantic.Exceptions { diff --git a/Interpreter.Lib/Semantic/Exceptions/FunctionWithoutReturnStatement.cs b/Interpreter.Lib/Semantic/Exceptions/FunctionWithoutReturnStatement.cs index b1c4d548..286c1219 100644 --- a/Interpreter.Lib/Semantic/Exceptions/FunctionWithoutReturnStatement.cs +++ b/Interpreter.Lib/Semantic/Exceptions/FunctionWithoutReturnStatement.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.FrontEnd.GetTokens; +using Interpreter.Lib.FrontEnd.GetTokens.Impl; namespace Interpreter.Lib.Semantic.Exceptions { diff --git a/Interpreter.Lib/Semantic/Exceptions/IncompatibleTypesOfOperands.cs b/Interpreter.Lib/Semantic/Exceptions/IncompatibleTypesOfOperands.cs index 99e693d3..606bfd04 100644 --- a/Interpreter.Lib/Semantic/Exceptions/IncompatibleTypesOfOperands.cs +++ b/Interpreter.Lib/Semantic/Exceptions/IncompatibleTypesOfOperands.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.FrontEnd.GetTokens; +using Interpreter.Lib.FrontEnd.GetTokens.Impl; using Interpreter.Lib.Semantic.Types; namespace Interpreter.Lib.Semantic.Exceptions diff --git a/Interpreter.Lib/Semantic/Exceptions/NotBooleanTestExpression.cs b/Interpreter.Lib/Semantic/Exceptions/NotBooleanTestExpression.cs index 2712ba22..175bc74e 100644 --- a/Interpreter.Lib/Semantic/Exceptions/NotBooleanTestExpression.cs +++ b/Interpreter.Lib/Semantic/Exceptions/NotBooleanTestExpression.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.FrontEnd.GetTokens; +using Interpreter.Lib.FrontEnd.GetTokens.Impl; using Interpreter.Lib.Semantic.Types; namespace Interpreter.Lib.Semantic.Exceptions diff --git a/Interpreter.Lib/Semantic/Exceptions/ObjectAccessException.cs b/Interpreter.Lib/Semantic/Exceptions/ObjectAccessException.cs index 5b473cfc..81e55973 100644 --- a/Interpreter.Lib/Semantic/Exceptions/ObjectAccessException.cs +++ b/Interpreter.Lib/Semantic/Exceptions/ObjectAccessException.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.FrontEnd.GetTokens; +using Interpreter.Lib.FrontEnd.GetTokens.Impl; using Interpreter.Lib.Semantic.Types; namespace Interpreter.Lib.Semantic.Exceptions diff --git a/Interpreter.Lib/Semantic/Exceptions/OutsideOfLoop.cs b/Interpreter.Lib/Semantic/Exceptions/OutsideOfLoop.cs index cbd33576..5eb1cdcd 100644 --- a/Interpreter.Lib/Semantic/Exceptions/OutsideOfLoop.cs +++ b/Interpreter.Lib/Semantic/Exceptions/OutsideOfLoop.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.FrontEnd.GetTokens; +using Interpreter.Lib.FrontEnd.GetTokens.Impl; namespace Interpreter.Lib.Semantic.Exceptions { diff --git a/Interpreter.Lib/Semantic/Exceptions/ReturnOutsideFunction.cs b/Interpreter.Lib/Semantic/Exceptions/ReturnOutsideFunction.cs index 0c89e774..e6d9ef00 100644 --- a/Interpreter.Lib/Semantic/Exceptions/ReturnOutsideFunction.cs +++ b/Interpreter.Lib/Semantic/Exceptions/ReturnOutsideFunction.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.FrontEnd.GetTokens; +using Interpreter.Lib.FrontEnd.GetTokens.Impl; namespace Interpreter.Lib.Semantic.Exceptions { diff --git a/Interpreter.Lib/Semantic/Exceptions/SymbolIsNotCallable.cs b/Interpreter.Lib/Semantic/Exceptions/SymbolIsNotCallable.cs index 3ba15808..4c805c74 100644 --- a/Interpreter.Lib/Semantic/Exceptions/SymbolIsNotCallable.cs +++ b/Interpreter.Lib/Semantic/Exceptions/SymbolIsNotCallable.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.FrontEnd.GetTokens; +using Interpreter.Lib.FrontEnd.GetTokens.Impl; namespace Interpreter.Lib.Semantic.Exceptions { diff --git a/Interpreter.Lib/Semantic/Exceptions/UnsupportedOperation.cs b/Interpreter.Lib/Semantic/Exceptions/UnsupportedOperation.cs index 629878b4..06b959d7 100644 --- a/Interpreter.Lib/Semantic/Exceptions/UnsupportedOperation.cs +++ b/Interpreter.Lib/Semantic/Exceptions/UnsupportedOperation.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.FrontEnd.GetTokens; +using Interpreter.Lib.FrontEnd.GetTokens.Impl; using Interpreter.Lib.Semantic.Types; namespace Interpreter.Lib.Semantic.Exceptions diff --git a/Interpreter.Lib/Semantic/Exceptions/WrongArrayLiteralDeclaration.cs b/Interpreter.Lib/Semantic/Exceptions/WrongArrayLiteralDeclaration.cs index 07190e73..019a2fbf 100644 --- a/Interpreter.Lib/Semantic/Exceptions/WrongArrayLiteralDeclaration.cs +++ b/Interpreter.Lib/Semantic/Exceptions/WrongArrayLiteralDeclaration.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.FrontEnd.GetTokens; +using Interpreter.Lib.FrontEnd.GetTokens.Impl; using Interpreter.Lib.Semantic.Types; namespace Interpreter.Lib.Semantic.Exceptions diff --git a/Interpreter.Lib/Semantic/Exceptions/WrongConditionalTypes.cs b/Interpreter.Lib/Semantic/Exceptions/WrongConditionalTypes.cs index 8f3699fe..a8c198b2 100644 --- a/Interpreter.Lib/Semantic/Exceptions/WrongConditionalTypes.cs +++ b/Interpreter.Lib/Semantic/Exceptions/WrongConditionalTypes.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.FrontEnd.GetTokens; +using Interpreter.Lib.FrontEnd.GetTokens.Impl; using Interpreter.Lib.Semantic.Types; namespace Interpreter.Lib.Semantic.Exceptions diff --git a/Interpreter.Lib/Semantic/Exceptions/WrongNumberOfArguments.cs b/Interpreter.Lib/Semantic/Exceptions/WrongNumberOfArguments.cs index eae17a07..4e3212a2 100644 --- a/Interpreter.Lib/Semantic/Exceptions/WrongNumberOfArguments.cs +++ b/Interpreter.Lib/Semantic/Exceptions/WrongNumberOfArguments.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.FrontEnd.GetTokens; +using Interpreter.Lib.FrontEnd.GetTokens.Impl; namespace Interpreter.Lib.Semantic.Exceptions { diff --git a/Interpreter.Lib/Semantic/Exceptions/WrongReturnType.cs b/Interpreter.Lib/Semantic/Exceptions/WrongReturnType.cs index 53c576e5..c69ef468 100644 --- a/Interpreter.Lib/Semantic/Exceptions/WrongReturnType.cs +++ b/Interpreter.Lib/Semantic/Exceptions/WrongReturnType.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.FrontEnd.GetTokens; +using Interpreter.Lib.FrontEnd.GetTokens.Impl; using Interpreter.Lib.Semantic.Types; namespace Interpreter.Lib.Semantic.Exceptions diff --git a/Interpreter.Lib/Semantic/Exceptions/WrongTypeOfArgument.cs b/Interpreter.Lib/Semantic/Exceptions/WrongTypeOfArgument.cs index 7cd7233e..f2179284 100644 --- a/Interpreter.Lib/Semantic/Exceptions/WrongTypeOfArgument.cs +++ b/Interpreter.Lib/Semantic/Exceptions/WrongTypeOfArgument.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.FrontEnd.GetTokens; +using Interpreter.Lib.FrontEnd.GetTokens.Impl; using Interpreter.Lib.Semantic.Types; namespace Interpreter.Lib.Semantic.Exceptions diff --git a/Interpreter.Lib/Semantic/Nodes/AbstractSyntaxTreeNode.cs b/Interpreter.Lib/Semantic/Nodes/AbstractSyntaxTreeNode.cs index ddb879fc..3f81b12f 100644 --- a/Interpreter.Lib/Semantic/Nodes/AbstractSyntaxTreeNode.cs +++ b/Interpreter.Lib/Semantic/Nodes/AbstractSyntaxTreeNode.cs @@ -1,6 +1,6 @@ using System.Collections; using System.Collections.Generic; -using Interpreter.Lib.FrontEnd.GetTokens; +using Interpreter.Lib.FrontEnd.GetTokens.Impl; using Interpreter.Lib.IR.Instructions; using Interpreter.Lib.Semantic.Nodes.Declarations; using Interpreter.Lib.Semantic.Types; diff --git a/Interpreter.Lib/Semantic/Nodes/Declarations/LexicalDeclaration.cs b/Interpreter.Lib/Semantic/Nodes/Declarations/LexicalDeclaration.cs index d981767c..f5df8056 100644 --- a/Interpreter.Lib/Semantic/Nodes/Declarations/LexicalDeclaration.cs +++ b/Interpreter.Lib/Semantic/Nodes/Declarations/LexicalDeclaration.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; using System.Linq; -using Interpreter.Lib.FrontEnd.GetTokens; +using Interpreter.Lib.FrontEnd.GetTokens.Impl; using Interpreter.Lib.IR.Instructions; using Interpreter.Lib.Semantic.Nodes.Expressions; using Interpreter.Lib.Semantic.Nodes.Expressions.PrimaryExpressions; diff --git a/Interpreter.Lib/Semantic/Nodes/Expressions/PrimaryExpressions/Literal.cs b/Interpreter.Lib/Semantic/Nodes/Expressions/PrimaryExpressions/Literal.cs index 979c81bf..ed4acb00 100644 --- a/Interpreter.Lib/Semantic/Nodes/Expressions/PrimaryExpressions/Literal.cs +++ b/Interpreter.Lib/Semantic/Nodes/Expressions/PrimaryExpressions/Literal.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.FrontEnd.GetTokens; +using Interpreter.Lib.FrontEnd.GetTokens.Impl; using Interpreter.Lib.VM.Values; using Type = Interpreter.Lib.Semantic.Types.Type; diff --git a/Interpreter.Lib/Semantic/Utils/SymbolTableUtils.cs b/Interpreter.Lib/Semantic/Utils/SymbolTableUtils.cs index 7c040272..63f1f77b 100644 --- a/Interpreter.Lib/Semantic/Utils/SymbolTableUtils.cs +++ b/Interpreter.Lib/Semantic/Utils/SymbolTableUtils.cs @@ -1,5 +1,5 @@ using System.Collections.Generic; -using Interpreter.Lib.FrontEnd.GetTokens; +using Interpreter.Lib.FrontEnd.GetTokens.Impl; using Interpreter.Lib.Semantic.Nodes; using Interpreter.Lib.Semantic.Nodes.Declarations; using Interpreter.Lib.Semantic.Nodes.Statements; diff --git a/Interpreter.Tests/Unit/ParserTests.cs b/Interpreter.Tests/Unit/ParserTests.cs index 9799b7a7..9dc1815a 100644 --- a/Interpreter.Tests/Unit/ParserTests.cs +++ b/Interpreter.Tests/Unit/ParserTests.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.FrontEnd.TopDownParse; +using Interpreter.Lib.FrontEnd.TopDownParse.Impl; using Interpreter.Models; using Interpreter.Services.Providers; using Interpreter.Tests.TestData; @@ -37,7 +37,7 @@ public void ParserDoesNotThrowTest(string text) var ex = Record.Exception(() => { // ReSharper disable once UnusedVariable - var ast = parser.TopDownParse(); + var ast = parser.TopDownParse(text); }); Assert.Null(ex); } diff --git a/Interpreter/MappingProfiles/TokenTypeProfile.cs b/Interpreter/MappingProfiles/TokenTypeProfile.cs index 51b0c1a0..d96961e2 100644 --- a/Interpreter/MappingProfiles/TokenTypeProfile.cs +++ b/Interpreter/MappingProfiles/TokenTypeProfile.cs @@ -1,5 +1,5 @@ using AutoMapper; -using Interpreter.Lib.FrontEnd.GetTokens.TokenTypes; +using Interpreter.Lib.FrontEnd.GetTokens.Impl.TokenTypes; using Interpreter.Models; namespace Interpreter.MappingProfiles diff --git a/Interpreter/Models/LexerQueryModel.cs b/Interpreter/Models/LexerQueryModel.cs index eea615aa..01f03f8d 100644 --- a/Interpreter/Models/LexerQueryModel.cs +++ b/Interpreter/Models/LexerQueryModel.cs @@ -1,14 +1,14 @@ using System.Collections.Generic; using AutoMapper; -using Interpreter.Lib.FrontEnd.GetTokens; -using Interpreter.Lib.FrontEnd.GetTokens.TokenTypes; +using Interpreter.Lib.FrontEnd.GetTokens.Impl; +using Interpreter.Lib.FrontEnd.GetTokens.Impl.TokenTypes; using Newtonsoft.Json; namespace Interpreter.Models { public class LexerQueryModel { - [JsonProperty] private List TokenTypes { get; set; } + private List TokenTypes { get; set; } public LexerQueryModel() { @@ -19,7 +19,7 @@ public LexerQueryModel() public string Text { get; set; } - public Structure GetDomain(IMapper mapper) => + public Structure GetStructure(IMapper mapper) => new(mapper.Map>(TokenTypes)); } } \ No newline at end of file diff --git a/Interpreter/Services/Executor/Impl/Executor.cs b/Interpreter/Services/Executor/Impl/Executor.cs index 1518c321..3216ba2d 100644 --- a/Interpreter/Services/Executor/Impl/Executor.cs +++ b/Interpreter/Services/Executor/Impl/Executor.cs @@ -31,13 +31,15 @@ public void Execute() { try { + var lexerQuery = _commandLineSettings.CreateLexerQuery(); + var lexer = _lexerProvider - .CreateLexer(_commandLineSettings.CreateLexerQuery()); + .CreateLexer(lexerQuery); var parser = _parserProvider .CreateParser(lexer); - using var ast = parser.TopDownParse(); + using var ast = parser.TopDownParse(lexerQuery.Text); ast.Check(new SemanticAnalyzer(node => node.SemanticCheck())); diff --git a/Interpreter/Services/Providers/ILexerProvider.cs b/Interpreter/Services/Providers/ILexerProvider.cs index 72f17b01..9691cd1d 100644 --- a/Interpreter/Services/Providers/ILexerProvider.cs +++ b/Interpreter/Services/Providers/ILexerProvider.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.FrontEnd.GetTokens; +using Interpreter.Lib.FrontEnd.GetTokens.Impl; using Interpreter.Models; namespace Interpreter.Services.Providers diff --git a/Interpreter/Services/Providers/IParserProvider.cs b/Interpreter/Services/Providers/IParserProvider.cs index 7e4ecfd5..3bea742e 100644 --- a/Interpreter/Services/Providers/IParserProvider.cs +++ b/Interpreter/Services/Providers/IParserProvider.cs @@ -1,5 +1,5 @@ -using Interpreter.Lib.FrontEnd.GetTokens; -using Interpreter.Lib.FrontEnd.TopDownParse; +using Interpreter.Lib.FrontEnd.GetTokens.Impl; +using Interpreter.Lib.FrontEnd.TopDownParse.Impl; namespace Interpreter.Services.Providers { diff --git a/Interpreter/Services/Providers/Impl/LexerProvider.cs b/Interpreter/Services/Providers/Impl/LexerProvider.cs index f0e1dc5f..a4f76e62 100644 --- a/Interpreter/Services/Providers/Impl/LexerProvider.cs +++ b/Interpreter/Services/Providers/Impl/LexerProvider.cs @@ -1,5 +1,5 @@ using AutoMapper; -using Interpreter.Lib.FrontEnd.GetTokens; +using Interpreter.Lib.FrontEnd.GetTokens.Impl; using Interpreter.Models; namespace Interpreter.Services.Providers.Impl @@ -15,9 +15,8 @@ public LexerProvider(IMapper mapper) public Lexer CreateLexer(LexerQueryModel lexerQuery) { - var domain = lexerQuery.GetDomain(_mapper); - var source = lexerQuery.Text; - return new Lexer(domain, source); + var domain = lexerQuery.GetStructure(_mapper); + return new Lexer(domain); } } } \ No newline at end of file diff --git a/Interpreter/Services/Providers/Impl/ParserProvider.cs b/Interpreter/Services/Providers/Impl/ParserProvider.cs index 85421f4d..9391d8bc 100644 --- a/Interpreter/Services/Providers/Impl/ParserProvider.cs +++ b/Interpreter/Services/Providers/Impl/ParserProvider.cs @@ -1,5 +1,5 @@ -using Interpreter.Lib.FrontEnd.GetTokens; -using Interpreter.Lib.FrontEnd.TopDownParse; +using Interpreter.Lib.FrontEnd.GetTokens.Impl; +using Interpreter.Lib.FrontEnd.TopDownParse.Impl; namespace Interpreter.Services.Providers.Impl { From 3a35d786ff6842eb2d069e347b9ece5e846f9600 Mon Sep 17 00:00:00 2001 From: Stepami Date: Mon, 12 Sep 2022 11:46:34 +0300 Subject: [PATCH 12/56] bugfix --- Interpreter.Lib/FrontEnd/TopDownParse/Impl/TokensStream.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Interpreter.Lib/FrontEnd/TopDownParse/Impl/TokensStream.cs b/Interpreter.Lib/FrontEnd/TopDownParse/Impl/TokensStream.cs index a61660a9..6acf5862 100644 --- a/Interpreter.Lib/FrontEnd/TopDownParse/Impl/TokensStream.cs +++ b/Interpreter.Lib/FrontEnd/TopDownParse/Impl/TokensStream.cs @@ -8,8 +8,11 @@ public class TokensStream : IEnumerator { private readonly IEnumerator _inner; - private TokensStream(IEnumerator enumerator) => + private TokensStream(IEnumerator enumerator) + { _inner = enumerator; + _inner.MoveNext(); + } public bool MoveNext() => _inner.MoveNext(); From f723a804b6012e2fecd5fd83cb5f0e79a3f7f1b3 Mon Sep 17 00:00:00 2001 From: Stepami Date: Mon, 12 Sep 2022 11:52:59 +0300 Subject: [PATCH 13/56] =?UTF-8?q?=D0=BD=D0=B5=D0=B1=D0=BE=D0=BB=D1=8C?= =?UTF-8?q?=D1=88=D0=BE=D0=B5=20=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=82=D1=82?= =?UTF-8?q?=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Interpreter.Lib/FrontEnd/GetTokens/Impl/Token.cs | 5 ++--- Interpreter.Lib/FrontEnd/GetTokens/LexerException.cs | 3 ++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Interpreter.Lib/FrontEnd/GetTokens/Impl/Token.cs b/Interpreter.Lib/FrontEnd/GetTokens/Impl/Token.cs index 53ffc3b7..88879c85 100644 --- a/Interpreter.Lib/FrontEnd/GetTokens/Impl/Token.cs +++ b/Interpreter.Lib/FrontEnd/GetTokens/Impl/Token.cs @@ -10,10 +10,9 @@ public record Token(TokenType Type) public string Value { get; } - public Token(TokenType type, Segment segment, string value) : this(type) - { + public Token(TokenType type, Segment segment, string value) : + this(type) => (Segment, Value) = (segment, value); - } public override string ToString() { diff --git a/Interpreter.Lib/FrontEnd/GetTokens/LexerException.cs b/Interpreter.Lib/FrontEnd/GetTokens/LexerException.cs index ced5f3d7..030393b7 100644 --- a/Interpreter.Lib/FrontEnd/GetTokens/LexerException.cs +++ b/Interpreter.Lib/FrontEnd/GetTokens/LexerException.cs @@ -5,7 +5,8 @@ namespace Interpreter.Lib.FrontEnd.GetTokens { public class LexerException : Exception { - public LexerException(Token token) : base($"Unknown token {token}") + public LexerException(Token token) : + base($"Unknown token {token}") { } } From 78b9a81b717122ffbd703fa3ab72801117f0c26e Mon Sep 17 00:00:00 2001 From: Stepami Date: Mon, 12 Sep 2022 11:54:57 +0300 Subject: [PATCH 14/56] bugfix --- Interpreter.Lib/FrontEnd/GetTokens/Impl/Lexer.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Interpreter.Lib/FrontEnd/GetTokens/Impl/Lexer.cs b/Interpreter.Lib/FrontEnd/GetTokens/Impl/Lexer.cs index c0484a90..65541c5a 100644 --- a/Interpreter.Lib/FrontEnd/GetTokens/Impl/Lexer.cs +++ b/Interpreter.Lib/FrontEnd/GetTokens/Impl/Lexer.cs @@ -19,6 +19,7 @@ public List GetTokens(string text) { _text = text; + _lines.Clear(); var lineMatches = new Regex(@"(?\n)").Matches(text[^1] == '\n' ? text From 4e8a3757b6e38a94a44dcf7df97383a8806eb941 Mon Sep 17 00:00:00 2001 From: Stepami Date: Mon, 12 Sep 2022 12:38:53 +0300 Subject: [PATCH 15/56] =?UTF-8?q?=D0=BD=D0=B5=D0=B1=D0=BE=D0=BB=D1=8C?= =?UTF-8?q?=D1=88=D0=B8=D0=B5=20=D0=B8=D0=BD=D1=84=D1=80=D0=B0=D1=81=D1=82?= =?UTF-8?q?=D1=80=D1=83=D0=BA=D1=82=D1=83=D1=80=D0=BD=D1=8B=D0=B5=20=D0=B8?= =?UTF-8?q?=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F:=20=D0=BF?= =?UTF-8?q?=D0=BE=D1=81=D0=BA=D0=BE=D0=BB=D1=8C=D0=BA=D1=83=20=D1=82=D0=B5?= =?UTF-8?q?=D0=BF=D0=B5=D1=80=D1=8C=20=D1=81=D1=83=D1=89=D0=BD=D0=BE=D1=81?= =?UTF-8?q?=D1=82=D0=B8=20=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D0=BF=D1=80=D0=B5?= =?UTF-8?q?=D1=82=D0=B0=D1=82=D0=BE=D1=80=D0=B0=20=D0=BD=D0=B5=20=D0=BA?= =?UTF-8?q?=D0=BE=D0=BD=D1=81=D1=82=D1=80=D1=83=D0=B8=D1=80=D1=83=D1=8E?= =?UTF-8?q?=D1=82=D1=81=D1=8F=20=D0=BD=D0=B0=20=D0=BE=D1=81=D0=BD=D0=BE?= =?UTF-8?q?=D0=B2=D0=B5=20=D0=B8=D1=81=D1=85=D0=BE=D0=B4=D0=BD=D0=BE=D0=B3?= =?UTF-8?q?=D0=BE=20=D1=82=D0=B5=D0=BA=D1=81=D1=82=D0=B0,=20=D1=81=20?= =?UTF-8?q?=D0=BA=D0=BE=D1=82=D0=BE=D1=80=D1=8B=D0=BC=20=D0=BF=D1=80=D0=B8?= =?UTF-8?q?=D0=B4=D1=91=D1=82=D1=81=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=D1=82=D1=8C,=20=D1=82=D0=BE=20=D0=BF=D0=BE=D0=BD=D1=8F?= =?UTF-8?q?=D1=82=D0=B8=D0=B5=20=D0=B7=D0=B0=D0=BF=D1=80=D0=BE=D1=81=D0=B0?= =?UTF-8?q?=20=D0=BD=D0=B0=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D1=81=D1=83=D1=89=D0=BD=D0=BE=D1=81=D1=82=D0=B8=20?= =?UTF-8?q?=D0=B1=D0=BE=D0=BB=D1=8C=D1=88=D0=B5=20=D0=BD=D0=B5=20=D0=BD?= =?UTF-8?q?=D1=83=D0=B6=D0=BD=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Interpreter.Tests/Unit/ParserTests.cs | 11 ++++---- Interpreter/CommandLineSettings.cs | 9 +++---- .../MappingProfiles/StructureProfile.cs | 20 +++++++++++++++ Interpreter/Models/LexerQueryModel.cs | 25 ------------------- Interpreter/Models/StructureModel.cs | 17 +++++++++++++ Interpreter/Program.cs | 2 +- .../Services/Executor/Impl/Executor.cs | 6 ++--- .../Services/Providers/ILexerProvider.cs | 2 +- .../Services/Providers/Impl/LexerProvider.cs | 4 +-- Interpreter/TokenTypes.cs | 2 +- 10 files changed, 53 insertions(+), 45 deletions(-) create mode 100644 Interpreter/MappingProfiles/StructureProfile.cs delete mode 100644 Interpreter/Models/LexerQueryModel.cs create mode 100644 Interpreter/Models/StructureModel.cs diff --git a/Interpreter.Tests/Unit/ParserTests.cs b/Interpreter.Tests/Unit/ParserTests.cs index 9dc1815a..a408ddf0 100644 --- a/Interpreter.Tests/Unit/ParserTests.cs +++ b/Interpreter.Tests/Unit/ParserTests.cs @@ -9,21 +9,20 @@ namespace Interpreter.Tests.Unit public class ParserTests { private readonly TestContainer _container; - private readonly LexerQueryModel _query; + private readonly StructureModel _structureModel; public ParserTests() { _container = new TestContainer(); - _query = new LexerQueryModel(); + _structureModel = new StructureModel(); } - private Parser GetParser(string text) + private Parser GetParser() { - _query.Text = text; var lexerCreator = _container.Get(); var parserCreator = _container.Get(); - var lexer = lexerCreator.CreateLexer(_query); + var lexer = lexerCreator.CreateLexer(_structureModel); var parser = parserCreator.CreateParser(lexer); return parser; } @@ -32,7 +31,7 @@ private Parser GetParser(string text) [ClassData(typeof(ParserSuccessTestData))] public void ParserDoesNotThrowTest(string text) { - var parser = GetParser(text); + var parser = GetParser(); var ex = Record.Exception(() => { diff --git a/Interpreter/CommandLineSettings.cs b/Interpreter/CommandLineSettings.cs index 8a1e0879..fccf4791 100644 --- a/Interpreter/CommandLineSettings.cs +++ b/Interpreter/CommandLineSettings.cs @@ -32,10 +32,9 @@ public static IEnumerable Examples public string GetInputFileName() => InputFilePath.Split(".js")[0]; - public LexerQueryModel CreateLexerQuery() => - new() - { - Text = File.ReadAllText(InputFilePath) - }; + public StructureModel StructureModel { get; } = new(); + + public string GetText() => + File.ReadAllText(InputFilePath); } } \ No newline at end of file diff --git a/Interpreter/MappingProfiles/StructureProfile.cs b/Interpreter/MappingProfiles/StructureProfile.cs new file mode 100644 index 00000000..97d32ec2 --- /dev/null +++ b/Interpreter/MappingProfiles/StructureProfile.cs @@ -0,0 +1,20 @@ +using System.Collections.Generic; +using AutoMapper; +using Interpreter.Lib.FrontEnd.GetTokens.Impl; +using Interpreter.Lib.FrontEnd.GetTokens.Impl.TokenTypes; +using Interpreter.Models; + +namespace Interpreter.MappingProfiles +{ + public class StructureProfile : Profile + { + public StructureProfile() + { + CreateMap() + .ConstructUsing((src, context) => + new Structure(context.Mapper + .Map, List> + (src.TokenTypes))); + } + } +} \ No newline at end of file diff --git a/Interpreter/Models/LexerQueryModel.cs b/Interpreter/Models/LexerQueryModel.cs deleted file mode 100644 index 01f03f8d..00000000 --- a/Interpreter/Models/LexerQueryModel.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System.Collections.Generic; -using AutoMapper; -using Interpreter.Lib.FrontEnd.GetTokens.Impl; -using Interpreter.Lib.FrontEnd.GetTokens.Impl.TokenTypes; -using Newtonsoft.Json; - -namespace Interpreter.Models -{ - public class LexerQueryModel - { - private List TokenTypes { get; set; } - - public LexerQueryModel() - { - TokenTypes = JsonConvert.DeserializeObject>( - Interpreter.TokenTypes.Json - ); - } - - public string Text { get; set; } - - public Structure GetStructure(IMapper mapper) => - new(mapper.Map>(TokenTypes)); - } -} \ No newline at end of file diff --git a/Interpreter/Models/StructureModel.cs b/Interpreter/Models/StructureModel.cs new file mode 100644 index 00000000..f472129e --- /dev/null +++ b/Interpreter/Models/StructureModel.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Interpreter.Models +{ + public class StructureModel + { + public List TokenTypes { get; } + + public StructureModel() + { + TokenTypes = JsonConvert.DeserializeObject>( + Interpreter.TokenTypes.Json + ); + } + } +} \ No newline at end of file diff --git a/Interpreter/Program.cs b/Interpreter/Program.cs index ee749040..ec4334e3 100644 --- a/Interpreter/Program.cs +++ b/Interpreter/Program.cs @@ -34,7 +34,7 @@ private static void ConfigureServices(CommandLineSettings settings) ServiceCollection.AddTransient(); ServiceCollection.AddTransient(); - ServiceCollection.AddAutoMapper(typeof(TokenTypeProfile)); + ServiceCollection.AddAutoMapper(typeof(TokenTypeProfile), typeof(StructureProfile)); ServiceCollection.AddSingleton(); diff --git a/Interpreter/Services/Executor/Impl/Executor.cs b/Interpreter/Services/Executor/Impl/Executor.cs index 3216ba2d..c7ea165f 100644 --- a/Interpreter/Services/Executor/Impl/Executor.cs +++ b/Interpreter/Services/Executor/Impl/Executor.cs @@ -31,15 +31,13 @@ public void Execute() { try { - var lexerQuery = _commandLineSettings.CreateLexerQuery(); - var lexer = _lexerProvider - .CreateLexer(lexerQuery); + .CreateLexer(_commandLineSettings.StructureModel); var parser = _parserProvider .CreateParser(lexer); - using var ast = parser.TopDownParse(lexerQuery.Text); + using var ast = parser.TopDownParse(_commandLineSettings.GetText()); ast.Check(new SemanticAnalyzer(node => node.SemanticCheck())); diff --git a/Interpreter/Services/Providers/ILexerProvider.cs b/Interpreter/Services/Providers/ILexerProvider.cs index 9691cd1d..584bcc58 100644 --- a/Interpreter/Services/Providers/ILexerProvider.cs +++ b/Interpreter/Services/Providers/ILexerProvider.cs @@ -5,6 +5,6 @@ namespace Interpreter.Services.Providers { public interface ILexerProvider { - Lexer CreateLexer(LexerQueryModel lexerQuery); + Lexer CreateLexer(StructureModel structureModel); } } \ No newline at end of file diff --git a/Interpreter/Services/Providers/Impl/LexerProvider.cs b/Interpreter/Services/Providers/Impl/LexerProvider.cs index a4f76e62..93179989 100644 --- a/Interpreter/Services/Providers/Impl/LexerProvider.cs +++ b/Interpreter/Services/Providers/Impl/LexerProvider.cs @@ -13,9 +13,9 @@ public LexerProvider(IMapper mapper) _mapper = mapper; } - public Lexer CreateLexer(LexerQueryModel lexerQuery) + public Lexer CreateLexer(StructureModel structureModel) { - var domain = lexerQuery.GetStructure(_mapper); + var domain = _mapper.Map(structureModel); return new Lexer(domain); } } diff --git a/Interpreter/TokenTypes.cs b/Interpreter/TokenTypes.cs index 707e37cf..ec2636f0 100644 --- a/Interpreter/TokenTypes.cs +++ b/Interpreter/TokenTypes.cs @@ -2,7 +2,7 @@ namespace Interpreter { public static class TokenTypes { - public static readonly string Json = @"[ + public const string Json = @"[ { ""tag"": ""Comment"", ""pattern"": ""[\/]{2}.*"", From 3513f2257bf3e32e10000fc715c10d6cf7f74a63 Mon Sep 17 00:00:00 2001 From: Stepami Date: Mon, 12 Sep 2022 14:41:49 +0300 Subject: [PATCH 16/56] suppressing possible NRE using language feature --- .../FrontEnd/TopDownParse/Impl/Parser.cs | 14 ++++++-------- Interpreter/Program.cs | 4 +--- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/Interpreter.Lib/FrontEnd/TopDownParse/Impl/Parser.cs b/Interpreter.Lib/FrontEnd/TopDownParse/Impl/Parser.cs index 409a1fcf..ad6e8485 100644 --- a/Interpreter.Lib/FrontEnd/TopDownParse/Impl/Parser.cs +++ b/Interpreter.Lib/FrontEnd/TopDownParse/Impl/Parser.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Text.RegularExpressions; using Interpreter.Lib.FrontEnd.GetTokens; @@ -20,7 +19,6 @@ namespace Interpreter.Lib.FrontEnd.TopDownParse.Impl { - [SuppressMessage("ReSharper", "PossibleNullReferenceException")] public class Parser : IParser { private TokensStream _tokens; @@ -34,8 +32,8 @@ private Token Expect(string expectedTag, string expectedValue = null) var current = _tokens.Current; if (!CurrentIs(expectedTag)) - throw new ParserException(_tokens.Current.Segment, expectedTag, _tokens.Current); - if (_tokens.Current.Value != (expectedValue ?? _tokens.Current.Value)) + throw new ParserException(_tokens.Current!.Segment, expectedTag, _tokens.Current); + if (_tokens.Current!.Value != (expectedValue ?? _tokens.Current.Value)) throw new ParserException(_tokens.Current.Segment, expectedValue, _tokens.Current); if (CurrentIs(expectedTag) && _tokens.Current.Value == (expectedValue ?? _tokens.Current.Value)) @@ -47,7 +45,7 @@ private Token Expect(string expectedTag, string expectedValue = null) } private bool CurrentIs(string tag) => - _tokens.Current.Type == _lexer.Structure.FindByTag(tag); + _tokens.Current!.Type == _lexer.Structure.FindByTag(tag); private bool CurrentIsLiteral() => CurrentIs("NullLiteral") || @@ -58,11 +56,11 @@ private bool CurrentIsLiteral() => private bool CurrentIsKeyword(string keyword) => CurrentIs("Keyword") && - _tokens.Current.Value == keyword; + _tokens.Current!.Value == keyword; private bool CurrentIsOperator(string @operator) => CurrentIs("Operator") && - _tokens.Current.Value == @operator; + _tokens.Current!.Value == @operator; public AbstractSyntaxTree TopDownParse(string text) { @@ -730,7 +728,7 @@ private Expression PrimaryExpression(SymbolTable table) private Literal Literal() { - var segment = _tokens.Current.Segment; + var segment = _tokens.Current!.Segment; if (CurrentIs("StringLiteral")) { var str = Expect("StringLiteral"); diff --git a/Interpreter/Program.cs b/Interpreter/Program.cs index ec4334e3..a4803655 100644 --- a/Interpreter/Program.cs +++ b/Interpreter/Program.cs @@ -1,5 +1,4 @@ using System; -using System.Diagnostics.CodeAnalysis; using CommandLine; using Microsoft.Extensions.DependencyInjection; using Interpreter.MappingProfiles; @@ -16,14 +15,13 @@ public static class Program private static IServiceCollection ServiceCollection { get; } = new ServiceCollection(); private static IServiceProvider ServiceProvider { get; set; } - [SuppressMessage("ReSharper", "PossibleNullReferenceException")] private static void Main(string[] args) => Parser.Default.ParseArguments(args) .WithParsed(options => { ConfigureServices(options); ServiceProvider - .GetService() + .GetService()! .Execute(); }) .WithNotParsed(errors => errors.Output()); From 862d7e6dc9f652e4bd85d0d70dc2996885abf4b9 Mon Sep 17 00:00:00 2001 From: Stepami Date: Mon, 12 Sep 2022 14:56:15 +0300 Subject: [PATCH 17/56] =?UTF-8?q?=D0=9F=D0=BE=D0=B4=D1=81=D1=82=D1=80?= =?UTF-8?q?=D0=BE=D0=B8=D0=BB=20=D0=B8=D0=BD=D1=84=D1=80=D0=B0=D1=81=D1=82?= =?UTF-8?q?=D1=80=D1=83=D0=BA=D1=82=D1=83=D1=80=D1=83=20=D0=BF=D0=BE=D0=B4?= =?UTF-8?q?=20=D0=B8=D1=81=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BD=D0=BE=D0=B2=D1=8B=D1=85=20=D0=B4?= =?UTF-8?q?=D0=BE=D0=BC=D0=B5=D0=BD=D0=BD=D1=8B=D1=85=20=D0=BA=D0=BE=D0=BD?= =?UTF-8?q?=D1=82=D1=80=D0=B0=D0=BA=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Interpreter.Tests/TestContainer.cs | 32 ----------------- Interpreter.Tests/Unit/ParserTests.cs | 34 +++++++++---------- .../Services/Executor/Impl/Executor.cs | 2 +- .../Services/Providers/ILexerProvider.cs | 5 ++- .../Services/Providers/IParserProvider.cs | 6 ++-- .../Services/Providers/Impl/LexerProvider.cs | 10 ++++-- .../Services/Providers/Impl/ParserProvider.cs | 5 +-- 7 files changed, 33 insertions(+), 61 deletions(-) delete mode 100644 Interpreter.Tests/TestContainer.cs diff --git a/Interpreter.Tests/TestContainer.cs b/Interpreter.Tests/TestContainer.cs deleted file mode 100644 index c8bc508b..00000000 --- a/Interpreter.Tests/TestContainer.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; -using Interpreter.MappingProfiles; -using Interpreter.Services.Providers; -using Interpreter.Services.Providers.Impl; -using Microsoft.Extensions.DependencyInjection; - -namespace Interpreter.Tests -{ - internal class TestContainer - { - private IServiceCollection ServiceCollection { get; } = new ServiceCollection(); - - private IServiceProvider ServiceProvider { get; set; } - - public TestContainer() - { - ConfigureServices(); - } - - private void ConfigureServices() - { - ServiceCollection.AddTransient(); - ServiceCollection.AddTransient(); - - ServiceCollection.AddAutoMapper(typeof(TokenTypeProfile)); - - ServiceProvider = ServiceCollection.BuildServiceProvider(); - } - - public T Get() => ServiceProvider.GetService(); - } -} \ No newline at end of file diff --git a/Interpreter.Tests/Unit/ParserTests.cs b/Interpreter.Tests/Unit/ParserTests.cs index a408ddf0..4da8cf9b 100644 --- a/Interpreter.Tests/Unit/ParserTests.cs +++ b/Interpreter.Tests/Unit/ParserTests.cs @@ -1,6 +1,10 @@ +using System.Collections.Generic; +using AutoMapper; +using Interpreter.Lib.FrontEnd.GetTokens.Impl; +using Interpreter.Lib.FrontEnd.TopDownParse; using Interpreter.Lib.FrontEnd.TopDownParse.Impl; +using Interpreter.MappingProfiles; using Interpreter.Models; -using Interpreter.Services.Providers; using Interpreter.Tests.TestData; using Xunit; @@ -8,35 +12,31 @@ namespace Interpreter.Tests.Unit { public class ParserTests { - private readonly TestContainer _container; - private readonly StructureModel _structureModel; + private readonly IParser _parser; public ParserTests() { - _container = new TestContainer(); - _structureModel = new StructureModel(); - } - - private Parser GetParser() - { - var lexerCreator = _container.Get(); - var parserCreator = _container.Get(); + IMapper mapper = new Mapper(new MapperConfiguration( + x => x.AddProfiles(new List + { + new TokenTypeProfile(), + new StructureProfile() + }) + )); - var lexer = lexerCreator.CreateLexer(_structureModel); - var parser = parserCreator.CreateParser(lexer); - return parser; + _parser = new Parser(new Lexer( + mapper.Map(new()) + )); } [Theory] [ClassData(typeof(ParserSuccessTestData))] public void ParserDoesNotThrowTest(string text) { - var parser = GetParser(); - var ex = Record.Exception(() => { // ReSharper disable once UnusedVariable - var ast = parser.TopDownParse(text); + var ast = _parser.TopDownParse(text); }); Assert.Null(ex); } diff --git a/Interpreter/Services/Executor/Impl/Executor.cs b/Interpreter/Services/Executor/Impl/Executor.cs index c7ea165f..089f3dc9 100644 --- a/Interpreter/Services/Executor/Impl/Executor.cs +++ b/Interpreter/Services/Executor/Impl/Executor.cs @@ -32,7 +32,7 @@ public void Execute() try { var lexer = _lexerProvider - .CreateLexer(_commandLineSettings.StructureModel); + .CreateLexer(); var parser = _parserProvider .CreateParser(lexer); diff --git a/Interpreter/Services/Providers/ILexerProvider.cs b/Interpreter/Services/Providers/ILexerProvider.cs index 584bcc58..4011e48a 100644 --- a/Interpreter/Services/Providers/ILexerProvider.cs +++ b/Interpreter/Services/Providers/ILexerProvider.cs @@ -1,10 +1,9 @@ -using Interpreter.Lib.FrontEnd.GetTokens.Impl; -using Interpreter.Models; +using Interpreter.Lib.FrontEnd.GetTokens; namespace Interpreter.Services.Providers { public interface ILexerProvider { - Lexer CreateLexer(StructureModel structureModel); + ILexer CreateLexer(); } } \ No newline at end of file diff --git a/Interpreter/Services/Providers/IParserProvider.cs b/Interpreter/Services/Providers/IParserProvider.cs index 3bea742e..789a1244 100644 --- a/Interpreter/Services/Providers/IParserProvider.cs +++ b/Interpreter/Services/Providers/IParserProvider.cs @@ -1,10 +1,10 @@ -using Interpreter.Lib.FrontEnd.GetTokens.Impl; -using Interpreter.Lib.FrontEnd.TopDownParse.Impl; +using Interpreter.Lib.FrontEnd.GetTokens; +using Interpreter.Lib.FrontEnd.TopDownParse; namespace Interpreter.Services.Providers { public interface IParserProvider { - Parser CreateParser(Lexer lexer); + IParser CreateParser(ILexer lexer); } } \ No newline at end of file diff --git a/Interpreter/Services/Providers/Impl/LexerProvider.cs b/Interpreter/Services/Providers/Impl/LexerProvider.cs index 93179989..35f302e2 100644 --- a/Interpreter/Services/Providers/Impl/LexerProvider.cs +++ b/Interpreter/Services/Providers/Impl/LexerProvider.cs @@ -1,21 +1,25 @@ using AutoMapper; +using Interpreter.Lib.FrontEnd.GetTokens; using Interpreter.Lib.FrontEnd.GetTokens.Impl; using Interpreter.Models; +using Microsoft.Extensions.Options; namespace Interpreter.Services.Providers.Impl { public class LexerProvider : ILexerProvider { private readonly IMapper _mapper; + private readonly StructureModel _structureModel; - public LexerProvider(IMapper mapper) + public LexerProvider(IMapper mapper, IOptions options) { _mapper = mapper; + _structureModel = options.Value.StructureModel; } - public Lexer CreateLexer(StructureModel structureModel) + public ILexer CreateLexer() { - var domain = _mapper.Map(structureModel); + var domain = _mapper.Map(_structureModel); return new Lexer(domain); } } diff --git a/Interpreter/Services/Providers/Impl/ParserProvider.cs b/Interpreter/Services/Providers/Impl/ParserProvider.cs index 9391d8bc..6e98bd59 100644 --- a/Interpreter/Services/Providers/Impl/ParserProvider.cs +++ b/Interpreter/Services/Providers/Impl/ParserProvider.cs @@ -1,10 +1,11 @@ -using Interpreter.Lib.FrontEnd.GetTokens.Impl; +using Interpreter.Lib.FrontEnd.GetTokens; +using Interpreter.Lib.FrontEnd.TopDownParse; using Interpreter.Lib.FrontEnd.TopDownParse.Impl; namespace Interpreter.Services.Providers.Impl { public class ParserProvider : IParserProvider { - public Parser CreateParser(Lexer lexer) => new (lexer); + public IParser CreateParser(ILexer lexer) => new Parser(lexer); } } \ No newline at end of file From cdb061cccc928ce427e5549e528ba17d904605fe Mon Sep 17 00:00:00 2001 From: Stepami Date: Mon, 12 Sep 2022 16:52:51 +0300 Subject: [PATCH 18/56] =?UTF-8?q?=D0=B4=D0=BE=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=BA=D0=B0=20=D0=BA=D0=BE=D0=BD=D1=82=D1=80=D0=B0=D0=BA?= =?UTF-8?q?=D1=82=D0=BE=D0=B2=20=D0=B4=D0=BE=D0=BC=D0=B5=D0=BD=D0=BD=D0=BE?= =?UTF-8?q?=D0=B9=20=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Contracts/IAbstractSyntaxTree.cs | 2 +- .../FrontEnd/TopDownParse/IParser.cs | 4 +-- .../FrontEnd/TopDownParse/Impl/Parser.cs | 3 ++- .../Semantic/AbstractSyntaxTree.cs | 13 +++++---- Interpreter.Lib/Semantic/SymbolTable.cs | 27 +------------------ .../Services/Executor/Impl/Executor.cs | 12 +++------ 6 files changed, 15 insertions(+), 46 deletions(-) diff --git a/Interpreter.Lib/Contracts/IAbstractSyntaxTree.cs b/Interpreter.Lib/Contracts/IAbstractSyntaxTree.cs index f560afb5..2d7913cf 100644 --- a/Interpreter.Lib/Contracts/IAbstractSyntaxTree.cs +++ b/Interpreter.Lib/Contracts/IAbstractSyntaxTree.cs @@ -5,6 +5,6 @@ namespace Interpreter.Lib.Contracts { public interface IAbstractSyntaxTree { - List ToInstructions(); + List GetInstructions(); } } \ No newline at end of file diff --git a/Interpreter.Lib/FrontEnd/TopDownParse/IParser.cs b/Interpreter.Lib/FrontEnd/TopDownParse/IParser.cs index 803f2ad5..5cdbb154 100644 --- a/Interpreter.Lib/FrontEnd/TopDownParse/IParser.cs +++ b/Interpreter.Lib/FrontEnd/TopDownParse/IParser.cs @@ -1,9 +1,9 @@ -using Interpreter.Lib.Semantic; +using Interpreter.Lib.Contracts; namespace Interpreter.Lib.FrontEnd.TopDownParse { public interface IParser { - AbstractSyntaxTree TopDownParse(string text); + IAbstractSyntaxTree TopDownParse(string text); } } \ No newline at end of file diff --git a/Interpreter.Lib/FrontEnd/TopDownParse/Impl/Parser.cs b/Interpreter.Lib/FrontEnd/TopDownParse/Impl/Parser.cs index ad6e8485..b11282ab 100644 --- a/Interpreter.Lib/FrontEnd/TopDownParse/Impl/Parser.cs +++ b/Interpreter.Lib/FrontEnd/TopDownParse/Impl/Parser.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; +using Interpreter.Lib.Contracts; using Interpreter.Lib.FrontEnd.GetTokens; using Interpreter.Lib.FrontEnd.GetTokens.Impl; using Interpreter.Lib.Semantic; @@ -62,7 +63,7 @@ private bool CurrentIsOperator(string @operator) => CurrentIs("Operator") && _tokens.Current!.Value == @operator; - public AbstractSyntaxTree TopDownParse(string text) + public IAbstractSyntaxTree TopDownParse(string text) { _tokens = _lexer.GetTokens(text); diff --git a/Interpreter.Lib/Semantic/AbstractSyntaxTree.cs b/Interpreter.Lib/Semantic/AbstractSyntaxTree.cs index be0e1c28..c1494031 100644 --- a/Interpreter.Lib/Semantic/AbstractSyntaxTree.cs +++ b/Interpreter.Lib/Semantic/AbstractSyntaxTree.cs @@ -1,14 +1,13 @@ -using System; using System.Collections.Generic; using System.Linq; using System.Text; +using Interpreter.Lib.Contracts; using Interpreter.Lib.IR.Instructions; -using Interpreter.Lib.Semantic.Analysis; using Interpreter.Lib.Semantic.Nodes; namespace Interpreter.Lib.Semantic { - public class AbstractSyntaxTree : IDisposable + public class AbstractSyntaxTree : IAbstractSyntaxTree { private readonly AbstractSyntaxTreeNode _root; @@ -17,14 +16,16 @@ public AbstractSyntaxTree(AbstractSyntaxTreeNode root) _root = root; } - public void Check(SemanticAnalyzer analyzer) => - GetAllNodes().ToList().ForEach(analyzer.CheckCallback); + private void Check() => + GetAllNodes().ToList().ForEach(node => node.SemanticCheck()); private IEnumerable GetAllNodes() => _root.GetAllNodes(); public List GetInstructions() { + Check(); + var start = 0; var result = new List(); foreach (var node in _root) @@ -63,7 +64,5 @@ public override string ToString() }); return tree.Append("}\n").ToString(); } - - public void Dispose() => _root.SymbolTable.Dispose(); } } \ No newline at end of file diff --git a/Interpreter.Lib/Semantic/SymbolTable.cs b/Interpreter.Lib/Semantic/SymbolTable.cs index a8265bbb..cac4dbb1 100644 --- a/Interpreter.Lib/Semantic/SymbolTable.cs +++ b/Interpreter.Lib/Semantic/SymbolTable.cs @@ -1,23 +1,19 @@ -using System; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using Interpreter.Lib.Semantic.Symbols; using Type = Interpreter.Lib.Semantic.Types.Type; namespace Interpreter.Lib.Semantic { - public class SymbolTable : IDisposable + public class SymbolTable { private readonly Dictionary _symbols = new(); private readonly Dictionary _types = new(); private SymbolTable _openScope; - private readonly List _subScopes = new(); public void AddOpenScope(SymbolTable table) { _openScope = table; - table._subScopes.Add(this); } public void AddSymbol(Symbol symbol) => _symbols[symbol.Id] = symbol; @@ -46,26 +42,5 @@ public T FindSymbol(string id) where T : Symbol public bool ContainsSymbol(string id) => _symbols.ContainsKey(id); public void Clear() => _symbols.Clear(); - - private void DeepClean() - { - Clear(); - foreach (var child in _subScopes) - { - child.DeepClean(); - } - } - - [SuppressMessage("ReSharper", "CA1816")] - public void Dispose() - { - var table = _openScope; - while (table._openScope != null) - { - table = table._openScope; - } - - table.DeepClean(); - } } } \ No newline at end of file diff --git a/Interpreter/Services/Executor/Impl/Executor.cs b/Interpreter/Services/Executor/Impl/Executor.cs index 089f3dc9..dbb90264 100644 --- a/Interpreter/Services/Executor/Impl/Executor.cs +++ b/Interpreter/Services/Executor/Impl/Executor.cs @@ -6,7 +6,6 @@ using Interpreter.Lib.IR; using Interpreter.Lib.IR.Instructions; using Interpreter.Lib.IR.Optimizers; -using Interpreter.Lib.Semantic.Analysis; using Interpreter.Lib.Semantic.Exceptions; using Interpreter.Lib.VM; using Interpreter.Services.Providers; @@ -31,15 +30,10 @@ public void Execute() { try { - var lexer = _lexerProvider - .CreateLexer(); + var lexer = _lexerProvider.CreateLexer(); + var parser = _parserProvider.CreateParser(lexer); - var parser = _parserProvider - .CreateParser(lexer); - - using var ast = parser.TopDownParse(_commandLineSettings.GetText()); - - ast.Check(new SemanticAnalyzer(node => node.SemanticCheck())); + var ast = parser.TopDownParse(_commandLineSettings.GetText()); var instructions = ast.GetInstructions(); From 53d19fcb3a0924a90fef50eba1976716a505fb2c Mon Sep 17 00:00:00 2001 From: Stepami Date: Mon, 12 Sep 2022 16:53:25 +0300 Subject: [PATCH 19/56] =?UTF-8?q?=D1=83=D0=B4=D0=B0=D0=BB=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BD=D0=B5=D0=B8=D1=81=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D1=83?= =?UTF-8?q?=D0=B5=D0=BC=D1=8B=D0=B9=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Semantic/Analysis/SemanticAnalyzer.cs | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 Interpreter.Lib/Semantic/Analysis/SemanticAnalyzer.cs diff --git a/Interpreter.Lib/Semantic/Analysis/SemanticAnalyzer.cs b/Interpreter.Lib/Semantic/Analysis/SemanticAnalyzer.cs deleted file mode 100644 index 3f4d14ca..00000000 --- a/Interpreter.Lib/Semantic/Analysis/SemanticAnalyzer.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using Interpreter.Lib.Semantic.Nodes; - -namespace Interpreter.Lib.Semantic.Analysis -{ - public class SemanticAnalyzer - { - public Action CheckCallback { get; } - - public SemanticAnalyzer(Action checkCallback) - { - CheckCallback = checkCallback; - } - } -} \ No newline at end of file From b43aa04655afc0bf6ed2f2891a1aaef4ff7d0933 Mon Sep 17 00:00:00 2001 From: Stepami Date: Mon, 12 Sep 2022 18:15:13 +0300 Subject: [PATCH 20/56] =?UTF-8?q?=D0=92=D1=8B=D0=BF=D0=B8=D0=BB=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=B2=D1=81=D1=91,=20=D1=87=D1=82=D0=BE=20=D1=81?= =?UTF-8?q?=D0=B2=D1=8F=D0=B7=D0=B0=D0=BD=D0=BE=20=D1=81=20=D0=BE=D0=BF?= =?UTF-8?q?=D1=82=D0=B8=D0=BC=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Interpreter.Lib/IR/BasicBlock.cs | 65 ------------------- Interpreter.Lib/IR/BasicBlockBuilder.cs | 49 -------------- Interpreter.Lib/IR/ControlFlowGraph.cs | 63 ------------------ Interpreter.Lib/IR/Optimizers/IOptimizer.cs | 16 ----- .../IR/Optimizers/IdentityExpression.cs | 30 --------- .../IR/Optimizers/ZeroExpression.cs | 29 --------- Interpreter.Lib/VM/VirtualMachine.cs | 30 ++------- Interpreter.Tests/Unit/OptimizerTests.cs | 43 ------------ .../Services/Executor/Impl/Executor.cs | 20 +----- 9 files changed, 7 insertions(+), 338 deletions(-) delete mode 100644 Interpreter.Lib/IR/BasicBlock.cs delete mode 100644 Interpreter.Lib/IR/BasicBlockBuilder.cs delete mode 100644 Interpreter.Lib/IR/ControlFlowGraph.cs delete mode 100644 Interpreter.Lib/IR/Optimizers/IOptimizer.cs delete mode 100644 Interpreter.Lib/IR/Optimizers/IdentityExpression.cs delete mode 100644 Interpreter.Lib/IR/Optimizers/ZeroExpression.cs delete mode 100644 Interpreter.Tests/Unit/OptimizerTests.cs diff --git a/Interpreter.Lib/IR/BasicBlock.cs b/Interpreter.Lib/IR/BasicBlock.cs deleted file mode 100644 index be7f482b..00000000 --- a/Interpreter.Lib/IR/BasicBlock.cs +++ /dev/null @@ -1,65 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Interpreter.Lib.IR.Instructions; - -namespace Interpreter.Lib.IR -{ - public class BasicBlock : IEnumerable, IEquatable, IComparable - { - private readonly List _instructions; - - public BasicBlock(IEnumerable instructions) - { - _instructions = new List(instructions); - _instructions.Sort(); - } - - public int In() => _instructions.First().Number; - - public List Out() - { - var last = _instructions.Last(); - if (last is Return ret) - { - return ret.ToList(); - } - if (last.Branch() && (last is IfNotGoto)) - { - return new() - { - last.Jump(), - last.Number + 1 - }; - } - - return new() {last.Jump()}; - } - - public bool Equals(BasicBlock other) - { - if (other == null) - return false; - return this.Count() == other.Count() && this.Zip(other).All(pair => pair.First.Equals(pair.Second)); - } - - public IEnumerator GetEnumerator() => new List(_instructions).GetEnumerator(); - - IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - - public int CompareTo(BasicBlock other) => In().CompareTo(other.In()); - - public override bool Equals(object obj) => Equals(obj as BasicBlock); - - public override int GetHashCode() => In(); - - public override string ToString() - { - var result = new StringBuilder($@"{GetHashCode()} [shape=box, label="""); - result.AppendJoin("\\n", _instructions); - return result.Append(@"""]").ToString(); - } - } -} \ No newline at end of file diff --git a/Interpreter.Lib/IR/BasicBlockBuilder.cs b/Interpreter.Lib/IR/BasicBlockBuilder.cs deleted file mode 100644 index bb9c1bd0..00000000 --- a/Interpreter.Lib/IR/BasicBlockBuilder.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using Interpreter.Lib.IR.Instructions; - -namespace Interpreter.Lib.IR -{ - public class BasicBlockBuilder - { - private readonly List _instructions; - - public BasicBlockBuilder(List instructions) - { - _instructions = instructions; - } - - public List GetBasicBlocks() - { - _instructions[0].Leader = true; - - _instructions - .Where(i => i.Branch()) - .Select(i => new - { - Jump = i.Jump(), - Next = i.Number + 1 - }) - .ToList() - .ForEach(obj => - { - _instructions[obj.Jump].Leader = true; - _instructions[obj.Next].Leader = true; - }); - - var basicBlocks = new Stack(); - var instructionsInBlock = new List(); - foreach (var instruction in _instructions.AsEnumerable().Reverse()) - { - instructionsInBlock.Add(instruction); - if (instruction.Leader) - { - basicBlocks.Push(new BasicBlock(instructionsInBlock)); - instructionsInBlock.Clear(); - } - } - - return basicBlocks.ToList(); - } - } -} \ No newline at end of file diff --git a/Interpreter.Lib/IR/ControlFlowGraph.cs b/Interpreter.Lib/IR/ControlFlowGraph.cs deleted file mode 100644 index 3e923fd0..00000000 --- a/Interpreter.Lib/IR/ControlFlowGraph.cs +++ /dev/null @@ -1,63 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Interpreter.Lib.IR.Instructions; -using Interpreter.Lib.IR.Optimizers; - -namespace Interpreter.Lib.IR -{ - public class ControlFlowGraph - { - private readonly Dictionary> _adjacencyList = new(); - - public ControlFlowGraph(List basicBlocks) - { - basicBlocks.ForEach(basicBlock => - _adjacencyList[basicBlock] = basicBlocks - .Where(bb => basicBlock.Out().Contains(bb.In())) - .ToList() - ); - } - - public BasicBlock Entry => _adjacencyList.Keys.Min(); - - public BasicBlock NextBlock(BasicBlock current, int jump) => - _adjacencyList[current] - .FirstOrDefault(bb => bb.In() == jump); - - public void OptimizeInstructions(params Func>[] generators) - { - foreach (var bb in _adjacencyList.Keys) - { - foreach (var instruction in bb) - { - foreach (var generator in generators) - { - var optimizer = generator(null); - if (optimizer.CanOptimize(instruction)) - { - optimizer = generator(instruction); - optimizer.Optimize(); - } - } - } - } - } - - public override string ToString() - { - var result = new StringBuilder("digraph cfg {\n"); - foreach (var basicBlock in _adjacencyList.Keys) - { - result.Append($"\t{basicBlock}\n"); - foreach (var bb in _adjacencyList[basicBlock]) - { - result.Append($"\t{basicBlock.GetHashCode()}->{bb.GetHashCode()}\n"); - } - } - - return result.Append('}').ToString(); - } - } -} \ No newline at end of file diff --git a/Interpreter.Lib/IR/Optimizers/IOptimizer.cs b/Interpreter.Lib/IR/Optimizers/IOptimizer.cs deleted file mode 100644 index 8c699cda..00000000 --- a/Interpreter.Lib/IR/Optimizers/IOptimizer.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Interpreter.Lib.IR.Instructions; - -namespace Interpreter.Lib.IR.Optimizers -{ - public interface IOptimizer where T : Instruction - { - T Instruction { get; } - - bool Test(); - - void Optimize(); - - bool CanOptimize(Instruction instruction) => - typeof(T) == instruction.GetType(); - } -} \ No newline at end of file diff --git a/Interpreter.Lib/IR/Optimizers/IdentityExpression.cs b/Interpreter.Lib/IR/Optimizers/IdentityExpression.cs deleted file mode 100644 index ad0d8bda..00000000 --- a/Interpreter.Lib/IR/Optimizers/IdentityExpression.cs +++ /dev/null @@ -1,30 +0,0 @@ -using Interpreter.Lib.IR.Instructions; - -namespace Interpreter.Lib.IR.Optimizers -{ - public class IdentityExpression : IOptimizer - { - public Simple Instruction { get; } - - public IdentityExpression(Simple instruction) - { - Instruction = instruction; - } - - public bool Test() - { - var s = Instruction.ToString().Split('=')[1].Trim(); - return s.EndsWith("+ 0") || s.StartsWith("0 +") || - s.EndsWith("* 1") || s.StartsWith("1 *") || - s.EndsWith("- 0") || s.EndsWith("/ 1"); - } - - public void Optimize() - { - if (Test()) - { - Instruction.ReduceToAssignment(); - } - } - } -} \ No newline at end of file diff --git a/Interpreter.Lib/IR/Optimizers/ZeroExpression.cs b/Interpreter.Lib/IR/Optimizers/ZeroExpression.cs deleted file mode 100644 index ab5b4654..00000000 --- a/Interpreter.Lib/IR/Optimizers/ZeroExpression.cs +++ /dev/null @@ -1,29 +0,0 @@ -using Interpreter.Lib.IR.Instructions; - -namespace Interpreter.Lib.IR.Optimizers -{ - public class ZeroExpression : IOptimizer - { - public Simple Instruction { get; } - - public ZeroExpression(Simple instruction) - { - Instruction = instruction; - } - - public bool Test() - { - var s = Instruction.ToString().Split('=')[1].Trim(); - return s == "-0" || - s.EndsWith("* 0") || s.StartsWith("0 *"); - } - - public void Optimize() - { - if (Test()) - { - Instruction.ReduceToZero(); - } - } - } -} \ No newline at end of file diff --git a/Interpreter.Lib/VM/VirtualMachine.cs b/Interpreter.Lib/VM/VirtualMachine.cs index 8b8fe1d0..4b34af75 100644 --- a/Interpreter.Lib/VM/VirtualMachine.cs +++ b/Interpreter.Lib/VM/VirtualMachine.cs @@ -1,47 +1,27 @@ using System.Collections.Generic; -using System.Linq; -using Interpreter.Lib.IR; using Interpreter.Lib.IR.Instructions; namespace Interpreter.Lib.VM { public class VirtualMachine { - private readonly ControlFlowGraph _cfg; - public Stack CallStack { get; } = new(); public Stack Frames { get; } = new(); public Stack<(string Id, object Value)> Arguments { get; } = new(); - public VirtualMachine(ControlFlowGraph cfg) - { - _cfg = cfg; - } - - public void Run() + public void Run(List instructions) { - var block = _cfg.Entry; - var instructions = new Stack(block.Reverse()); - Frames.Push(new Frame()); - while (!instructions.Peek().End()) + var address = 0; + while (!instructions[address].End()) { - var instruction = instructions.Pop(); + var instruction = instructions[address]; var jump = instruction.Execute(this); - - if (instructions.Any()) - { - continue; - } - - block = _cfg.NextBlock(block, jump); - instructions = new Stack(block.Reverse()); + address = jump; } - - instructions.Pop().Execute(this); } } } \ No newline at end of file diff --git a/Interpreter.Tests/Unit/OptimizerTests.cs b/Interpreter.Tests/Unit/OptimizerTests.cs deleted file mode 100644 index c360d1cf..00000000 --- a/Interpreter.Tests/Unit/OptimizerTests.cs +++ /dev/null @@ -1,43 +0,0 @@ -using Interpreter.Lib.IR.Instructions; -using Interpreter.Lib.IR.Optimizers; -using Interpreter.Lib.VM.Values; -using Xunit; - -namespace Interpreter.Tests.Unit -{ - public class OptimizerTests - { - private IOptimizer _optimizer; - - [Fact] - public void IdentityExpressionTests() - { - _optimizer = new IdentityExpression( - new Simple( - "i", (new Constant(0, "0"), new Name("x")), "+", 0 - ) - ); - - Assert.True(_optimizer.Test()); - _optimizer.Optimize(); - Assert.Equal("0: i = x", _optimizer.Instruction.ToString()); - - - _optimizer = new IdentityExpression( - new Simple( - "i", (new Constant(1, "1"), new Name("x")), "*", 0 - ) - ); - Assert.True(_optimizer.Test()); - _optimizer.Optimize(); - Assert.Equal("0: i = x", _optimizer.Instruction.ToString()); - - _optimizer = new IdentityExpression( - new Simple( - "i", (new Constant(2, "2"), new Name("x")), "+", 0 - ) - ); - Assert.False(_optimizer.Test()); - } - } -} \ No newline at end of file diff --git a/Interpreter/Services/Executor/Impl/Executor.cs b/Interpreter/Services/Executor/Impl/Executor.cs index dbb90264..533caaef 100644 --- a/Interpreter/Services/Executor/Impl/Executor.cs +++ b/Interpreter/Services/Executor/Impl/Executor.cs @@ -3,9 +3,6 @@ using System.Linq; using Interpreter.Lib.FrontEnd.GetTokens; using Interpreter.Lib.FrontEnd.TopDownParse; -using Interpreter.Lib.IR; -using Interpreter.Lib.IR.Instructions; -using Interpreter.Lib.IR.Optimizers; using Interpreter.Lib.Semantic.Exceptions; using Interpreter.Lib.VM; using Interpreter.Services.Providers; @@ -37,18 +34,8 @@ public void Execute() var instructions = ast.GetInstructions(); - var cfg = new ControlFlowGraph( - new BasicBlockBuilder(instructions) - .GetBasicBlocks() - ); - - cfg.OptimizeInstructions( - i => new IdentityExpression(i as Simple), - i => new ZeroExpression(i as Simple) - ); - - var vm = new VirtualMachine(cfg); - vm.Run(); + var vm = new VirtualMachine(); + vm.Run(instructions); if (_commandLineSettings.Dump) { @@ -65,9 +52,6 @@ public void Execute() var astDot = ast.ToString(); File.WriteAllText("ast.dot", astDot); - - var cfgDot = cfg.ToString(); - File.WriteAllText("cfg.dot", cfgDot); } } catch (Exception ex) From a3bab8c0fc11b05bde688f2dcef624c44121af47 Mon Sep 17 00:00:00 2001 From: Stepami Date: Mon, 12 Sep 2022 23:22:51 +0300 Subject: [PATCH 21/56] =?UTF-8?q?=D0=9F=D1=80=D0=B8=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=BB=20=D0=BF=D0=B0=D1=82=D1=82=D0=B5=D1=80=D0=BD=20?= =?UTF-8?q?=D0=94=D0=B5=D0=BA=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D1=80=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=BB=D0=BE=D0=B3=D0=B3=D0=B8=D1=80=D1=83=D0=B5?= =?UTF-8?q?=D0=BC=D1=8B=D1=85=20=D1=81=D1=83=D1=89=D0=BD=D0=BE=D1=81=D1=82?= =?UTF-8?q?=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FrontEnd/GetTokens/Impl/Lexer.cs | 3 ++ .../FrontEnd/GetTokens/Impl/LoggingLexer.cs | 29 +++++++++++++++ .../TopDownParse/Impl/LoggingParser.cs | 26 +++++++++++++ .../TopDownParse/Impl/TokensStream.cs | 33 +++++++++-------- .../Semantic/LoggingAbstractSyntaxTree.cs | 30 +++++++++++++++ Interpreter/Program.cs | 7 +++- .../Services/Executor/Impl/Executor.cs | 37 +++---------------- .../Services/Parsing/IParsingService.cs | 9 +++++ .../Services/Parsing/Impl/ParsingService.cs | 21 +++++++++++ .../Services/Providers/IParserProvider.cs | 3 +- .../Services/Providers/Impl/LexerProvider.cs | 11 ++++-- .../Services/Providers/Impl/ParserProvider.cs | 20 +++++++++- 12 files changed, 172 insertions(+), 57 deletions(-) create mode 100644 Interpreter.Lib/FrontEnd/GetTokens/Impl/LoggingLexer.cs create mode 100644 Interpreter.Lib/FrontEnd/TopDownParse/Impl/LoggingParser.cs create mode 100644 Interpreter.Lib/Semantic/LoggingAbstractSyntaxTree.cs create mode 100644 Interpreter/Services/Parsing/IParsingService.cs create mode 100644 Interpreter/Services/Parsing/Impl/ParsingService.cs diff --git a/Interpreter.Lib/FrontEnd/GetTokens/Impl/Lexer.cs b/Interpreter.Lib/FrontEnd/GetTokens/Impl/Lexer.cs index 65541c5a..1e26911b 100644 --- a/Interpreter.Lib/FrontEnd/GetTokens/Impl/Lexer.cs +++ b/Interpreter.Lib/FrontEnd/GetTokens/Impl/Lexer.cs @@ -58,5 +58,8 @@ public IEnumerator GetEnumerator() } IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + + public override string ToString() => + string.Join('\n', this); } } \ No newline at end of file diff --git a/Interpreter.Lib/FrontEnd/GetTokens/Impl/LoggingLexer.cs b/Interpreter.Lib/FrontEnd/GetTokens/Impl/LoggingLexer.cs new file mode 100644 index 00000000..da8820ff --- /dev/null +++ b/Interpreter.Lib/FrontEnd/GetTokens/Impl/LoggingLexer.cs @@ -0,0 +1,29 @@ +using System.Collections.Generic; +using System.IO; + +namespace Interpreter.Lib.FrontEnd.GetTokens.Impl +{ + public class LoggingLexer : ILexer + { + private readonly ILexer _lexer; + private readonly string _fileName; + + public LoggingLexer(ILexer lexer, string fileName) + { + _lexer = lexer; + _fileName = fileName; + } + + public Structure Structure => _lexer.Structure; + + public List GetTokens(string text) + { + var tokens = _lexer.GetTokens(text); + File.WriteAllText( + $"{_fileName}.tokens", + _lexer.ToString() + ); + return tokens; + } + } +} \ No newline at end of file diff --git a/Interpreter.Lib/FrontEnd/TopDownParse/Impl/LoggingParser.cs b/Interpreter.Lib/FrontEnd/TopDownParse/Impl/LoggingParser.cs new file mode 100644 index 00000000..6314f084 --- /dev/null +++ b/Interpreter.Lib/FrontEnd/TopDownParse/Impl/LoggingParser.cs @@ -0,0 +1,26 @@ +using System.IO; +using Interpreter.Lib.Contracts; +using Interpreter.Lib.Semantic; + +namespace Interpreter.Lib.FrontEnd.TopDownParse.Impl +{ + public class LoggingParser : IParser + { + private readonly IParser _parser; + private readonly string _fileName; + + public LoggingParser(IParser parser, string fileName) + { + _parser = parser; + _fileName = fileName; + } + + public IAbstractSyntaxTree TopDownParse(string text) + { + var ast = _parser.TopDownParse(text); + var astDot = ast.ToString(); + File.WriteAllText("ast.dot", astDot); + return new LoggingAbstractSyntaxTree(ast, _fileName); + } + } +} \ No newline at end of file diff --git a/Interpreter.Lib/FrontEnd/TopDownParse/Impl/TokensStream.cs b/Interpreter.Lib/FrontEnd/TopDownParse/Impl/TokensStream.cs index 6acf5862..3ec74551 100644 --- a/Interpreter.Lib/FrontEnd/TopDownParse/Impl/TokensStream.cs +++ b/Interpreter.Lib/FrontEnd/TopDownParse/Impl/TokensStream.cs @@ -2,28 +2,29 @@ using System.Collections.Generic; using Interpreter.Lib.FrontEnd.GetTokens.Impl; -namespace Interpreter.Lib.FrontEnd.TopDownParse.Impl; - -public class TokensStream : IEnumerator +namespace Interpreter.Lib.FrontEnd.TopDownParse.Impl { - private readonly IEnumerator _inner; - - private TokensStream(IEnumerator enumerator) + public class TokensStream : IEnumerator { - _inner = enumerator; - _inner.MoveNext(); - } + private readonly IEnumerator _inner; - public bool MoveNext() => _inner.MoveNext(); + private TokensStream(IEnumerator enumerator) + { + _inner = enumerator; + _inner.MoveNext(); + } - public void Reset() => _inner.Reset(); + public bool MoveNext() => _inner.MoveNext(); - public Token Current => _inner.Current; + public void Reset() => _inner.Reset(); - object IEnumerator.Current => Current; + public Token Current => _inner.Current; - public void Dispose() => _inner.Dispose(); + object IEnumerator.Current => Current; - public static implicit operator TokensStream(List tokens) => - new (tokens.GetEnumerator()); + public void Dispose() => _inner.Dispose(); + + public static implicit operator TokensStream(List tokens) => + new (tokens.GetEnumerator()); + } } \ No newline at end of file diff --git a/Interpreter.Lib/Semantic/LoggingAbstractSyntaxTree.cs b/Interpreter.Lib/Semantic/LoggingAbstractSyntaxTree.cs new file mode 100644 index 00000000..da5f433a --- /dev/null +++ b/Interpreter.Lib/Semantic/LoggingAbstractSyntaxTree.cs @@ -0,0 +1,30 @@ +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Interpreter.Lib.Contracts; +using Interpreter.Lib.IR.Instructions; + +namespace Interpreter.Lib.Semantic +{ + public class LoggingAbstractSyntaxTree : IAbstractSyntaxTree + { + private readonly IAbstractSyntaxTree _ast; + private readonly string _fileName; + + public LoggingAbstractSyntaxTree(IAbstractSyntaxTree ast, string fileName) + { + _ast = ast; + _fileName = fileName; + } + + public List GetInstructions() + { + var instructions = _ast.GetInstructions(); + File.WriteAllLines( + $"{_fileName}.tac", + instructions.OrderBy(i => i).Select(i => i.ToString()) + ); + return instructions; + } + } +} \ No newline at end of file diff --git a/Interpreter/Program.cs b/Interpreter/Program.cs index a4803655..b2a67a06 100644 --- a/Interpreter/Program.cs +++ b/Interpreter/Program.cs @@ -4,6 +4,8 @@ using Interpreter.MappingProfiles; using Interpreter.Services.Executor; using Interpreter.Services.Executor.Impl; +using Interpreter.Services.Parsing; +using Interpreter.Services.Parsing.Impl; using Interpreter.Services.Providers; using Interpreter.Services.Providers.Impl; using Microsoft.Extensions.Options; @@ -29,8 +31,9 @@ private static void Main(string[] args) => private static void ConfigureServices(CommandLineSettings settings) { - ServiceCollection.AddTransient(); - ServiceCollection.AddTransient(); + ServiceCollection.AddSingleton(); + ServiceCollection.AddSingleton(); + ServiceCollection.AddSingleton(); ServiceCollection.AddAutoMapper(typeof(TokenTypeProfile), typeof(StructureProfile)); diff --git a/Interpreter/Services/Executor/Impl/Executor.cs b/Interpreter/Services/Executor/Impl/Executor.cs index 533caaef..399f5c2f 100644 --- a/Interpreter/Services/Executor/Impl/Executor.cs +++ b/Interpreter/Services/Executor/Impl/Executor.cs @@ -1,58 +1,33 @@ using System; -using System.IO; -using System.Linq; using Interpreter.Lib.FrontEnd.GetTokens; using Interpreter.Lib.FrontEnd.TopDownParse; using Interpreter.Lib.Semantic.Exceptions; using Interpreter.Lib.VM; -using Interpreter.Services.Providers; +using Interpreter.Services.Parsing; using Microsoft.Extensions.Options; namespace Interpreter.Services.Executor.Impl { public class Executor : IExecutor { - private readonly ILexerProvider _lexerProvider; - private readonly IParserProvider _parserProvider; + private readonly IParsingService _parsingService; private readonly CommandLineSettings _commandLineSettings; - public Executor(ILexerProvider lexerProvider, IParserProvider parserProvider, IOptions optionsProvider) + public Executor(IParsingService parsingService, IOptions options) { - _lexerProvider = lexerProvider; - _parserProvider = parserProvider; - _commandLineSettings = optionsProvider.Value; + _parsingService = parsingService; + _commandLineSettings = options.Value; } public void Execute() { try { - var lexer = _lexerProvider.CreateLexer(); - var parser = _parserProvider.CreateParser(lexer); - - var ast = parser.TopDownParse(_commandLineSettings.GetText()); - + var ast = _parsingService.Parse(_commandLineSettings.GetText()); var instructions = ast.GetInstructions(); var vm = new VirtualMachine(); vm.Run(instructions); - - if (_commandLineSettings.Dump) - { - var fileName = _commandLineSettings.GetInputFileName(); - File.WriteAllLines( - $"{fileName}.tac", - instructions.OrderBy(i => i).Select(i => i.ToString()) - ); - - File.WriteAllText( - $"{fileName}.tokens", - string.Join('\n', lexer) - ); - - var astDot = ast.ToString(); - File.WriteAllText("ast.dot", astDot); - } } catch (Exception ex) when (ex is LexerException or ParserException or SemanticException) diff --git a/Interpreter/Services/Parsing/IParsingService.cs b/Interpreter/Services/Parsing/IParsingService.cs new file mode 100644 index 00000000..75ad0138 --- /dev/null +++ b/Interpreter/Services/Parsing/IParsingService.cs @@ -0,0 +1,9 @@ +using Interpreter.Lib.Contracts; + +namespace Interpreter.Services.Parsing +{ + public interface IParsingService + { + IAbstractSyntaxTree Parse(string text); + } +} \ No newline at end of file diff --git a/Interpreter/Services/Parsing/Impl/ParsingService.cs b/Interpreter/Services/Parsing/Impl/ParsingService.cs new file mode 100644 index 00000000..4135a464 --- /dev/null +++ b/Interpreter/Services/Parsing/Impl/ParsingService.cs @@ -0,0 +1,21 @@ +using Interpreter.Lib.Contracts; +using Interpreter.Services.Providers; + +namespace Interpreter.Services.Parsing.Impl +{ + public class ParsingService : IParsingService + { + private readonly IParserProvider _parserProvider; + + public ParsingService(IParserProvider parserProvider) + { + _parserProvider = parserProvider; + } + + public IAbstractSyntaxTree Parse(string text) + { + var parser = _parserProvider.CreateParser(); + return parser.TopDownParse(text); + } + } +} \ No newline at end of file diff --git a/Interpreter/Services/Providers/IParserProvider.cs b/Interpreter/Services/Providers/IParserProvider.cs index 789a1244..48b188c5 100644 --- a/Interpreter/Services/Providers/IParserProvider.cs +++ b/Interpreter/Services/Providers/IParserProvider.cs @@ -1,10 +1,9 @@ -using Interpreter.Lib.FrontEnd.GetTokens; using Interpreter.Lib.FrontEnd.TopDownParse; namespace Interpreter.Services.Providers { public interface IParserProvider { - IParser CreateParser(ILexer lexer); + IParser CreateParser(); } } \ No newline at end of file diff --git a/Interpreter/Services/Providers/Impl/LexerProvider.cs b/Interpreter/Services/Providers/Impl/LexerProvider.cs index 35f302e2..c7a7d72e 100644 --- a/Interpreter/Services/Providers/Impl/LexerProvider.cs +++ b/Interpreter/Services/Providers/Impl/LexerProvider.cs @@ -9,18 +9,21 @@ namespace Interpreter.Services.Providers.Impl public class LexerProvider : ILexerProvider { private readonly IMapper _mapper; - private readonly StructureModel _structureModel; + private readonly CommandLineSettings _settings; public LexerProvider(IMapper mapper, IOptions options) { _mapper = mapper; - _structureModel = options.Value.StructureModel; + _settings = options.Value; } public ILexer CreateLexer() { - var domain = _mapper.Map(_structureModel); - return new Lexer(domain); + var domain = _mapper.Map(_settings.StructureModel); + var lexer = new Lexer(domain); + return _settings.Dump + ? new LoggingLexer(lexer, _settings.GetInputFileName()) + : lexer; } } } \ No newline at end of file diff --git a/Interpreter/Services/Providers/Impl/ParserProvider.cs b/Interpreter/Services/Providers/Impl/ParserProvider.cs index 6e98bd59..4e0f2ded 100644 --- a/Interpreter/Services/Providers/Impl/ParserProvider.cs +++ b/Interpreter/Services/Providers/Impl/ParserProvider.cs @@ -1,11 +1,27 @@ -using Interpreter.Lib.FrontEnd.GetTokens; using Interpreter.Lib.FrontEnd.TopDownParse; using Interpreter.Lib.FrontEnd.TopDownParse.Impl; +using Microsoft.Extensions.Options; namespace Interpreter.Services.Providers.Impl { public class ParserProvider : IParserProvider { - public IParser CreateParser(ILexer lexer) => new Parser(lexer); + private readonly ILexerProvider _lexerProvider; + private readonly CommandLineSettings _settings; + + public ParserProvider(ILexerProvider lexerProvider, IOptions options) + { + _lexerProvider = lexerProvider; + _settings = options.Value; + } + + public IParser CreateParser() + { + var lexer = _lexerProvider.CreateLexer(); + var parser = new Parser(lexer); + return _settings.Dump + ? new LoggingParser(parser, _settings.GetInputFileName()) + : parser; + } } } \ No newline at end of file From e054ae0de3dcb24b4702c6fa9feea1e37fb502bb Mon Sep 17 00:00:00 2001 From: Stepami Date: Mon, 12 Sep 2022 23:36:27 +0300 Subject: [PATCH 22/56] =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B5=D0=BC=D0=B5?= =?UTF-8?q?=D1=81=D1=82=D0=B8=D0=BB=20=D0=BB=D0=BE=D0=B3=D0=B3=D0=B8=D1=80?= =?UTF-8?q?=D1=83=D0=B5=D0=BC=D1=8B=D0=B5=20=D1=81=D1=83=D1=89=D0=BD=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D0=B8=20=D0=B2=20=D0=B8=D0=BD=D1=84=D1=80=D0=B0?= =?UTF-8?q?=D1=81=D1=82=D1=80=D1=83=D0=BA=D1=82=D1=83=D1=80=D1=83,=20?= =?UTF-8?q?=D1=82=D0=B0=D0=BA=20=D0=BA=D0=B0=D0=BA,=20=D0=BF=D0=BE=20?= =?UTF-8?q?=D1=81=D1=83=D1=82=D0=B8=20=D0=BE=D0=BD=D0=B8=20=D0=BD=D0=B5=20?= =?UTF-8?q?=D0=BE=D1=82=D0=BD=D0=BE=D1=81=D1=8F=D1=82=D1=81=D1=8F=20=D0=BA?= =?UTF-8?q?=20=D0=B4=D0=BE=D0=BC=D0=B5=D0=BD=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Interpreter/Program.cs | 3 ++- .../Providers/Impl/{ => LexerProvider}/LexerProvider.cs | 2 +- .../Services/Providers/Impl/LexerProvider}/LoggingLexer.cs | 4 +++- .../Impl/ParserProvider}/LoggingAbstractSyntaxTree.cs | 2 +- .../Providers/Impl/ParserProvider}/LoggingParser.cs | 4 ++-- .../Providers/Impl/{ => ParserProvider}/ParserProvider.cs | 6 +++--- 6 files changed, 12 insertions(+), 9 deletions(-) rename Interpreter/Services/Providers/Impl/{ => LexerProvider}/LexerProvider.cs (93%) rename {Interpreter.Lib/FrontEnd/GetTokens/Impl => Interpreter/Services/Providers/Impl/LexerProvider}/LoggingLexer.cs (81%) rename {Interpreter.Lib/Semantic => Interpreter/Services/Providers/Impl/ParserProvider}/LoggingAbstractSyntaxTree.cs (92%) rename {Interpreter.Lib/FrontEnd/TopDownParse/Impl => Interpreter/Services/Providers/Impl/ParserProvider}/LoggingParser.cs (85%) rename Interpreter/Services/Providers/Impl/{ => ParserProvider}/ParserProvider.cs (85%) diff --git a/Interpreter/Program.cs b/Interpreter/Program.cs index b2a67a06..3e020de7 100644 --- a/Interpreter/Program.cs +++ b/Interpreter/Program.cs @@ -7,7 +7,8 @@ using Interpreter.Services.Parsing; using Interpreter.Services.Parsing.Impl; using Interpreter.Services.Providers; -using Interpreter.Services.Providers.Impl; +using Interpreter.Services.Providers.Impl.LexerProvider; +using Interpreter.Services.Providers.Impl.ParserProvider; using Microsoft.Extensions.Options; namespace Interpreter diff --git a/Interpreter/Services/Providers/Impl/LexerProvider.cs b/Interpreter/Services/Providers/Impl/LexerProvider/LexerProvider.cs similarity index 93% rename from Interpreter/Services/Providers/Impl/LexerProvider.cs rename to Interpreter/Services/Providers/Impl/LexerProvider/LexerProvider.cs index c7a7d72e..95d235e9 100644 --- a/Interpreter/Services/Providers/Impl/LexerProvider.cs +++ b/Interpreter/Services/Providers/Impl/LexerProvider/LexerProvider.cs @@ -4,7 +4,7 @@ using Interpreter.Models; using Microsoft.Extensions.Options; -namespace Interpreter.Services.Providers.Impl +namespace Interpreter.Services.Providers.Impl.LexerProvider { public class LexerProvider : ILexerProvider { diff --git a/Interpreter.Lib/FrontEnd/GetTokens/Impl/LoggingLexer.cs b/Interpreter/Services/Providers/Impl/LexerProvider/LoggingLexer.cs similarity index 81% rename from Interpreter.Lib/FrontEnd/GetTokens/Impl/LoggingLexer.cs rename to Interpreter/Services/Providers/Impl/LexerProvider/LoggingLexer.cs index da8820ff..f31bc63e 100644 --- a/Interpreter.Lib/FrontEnd/GetTokens/Impl/LoggingLexer.cs +++ b/Interpreter/Services/Providers/Impl/LexerProvider/LoggingLexer.cs @@ -1,7 +1,9 @@ using System.Collections.Generic; using System.IO; +using Interpreter.Lib.FrontEnd.GetTokens; +using Interpreter.Lib.FrontEnd.GetTokens.Impl; -namespace Interpreter.Lib.FrontEnd.GetTokens.Impl +namespace Interpreter.Services.Providers.Impl.LexerProvider { public class LoggingLexer : ILexer { diff --git a/Interpreter.Lib/Semantic/LoggingAbstractSyntaxTree.cs b/Interpreter/Services/Providers/Impl/ParserProvider/LoggingAbstractSyntaxTree.cs similarity index 92% rename from Interpreter.Lib/Semantic/LoggingAbstractSyntaxTree.cs rename to Interpreter/Services/Providers/Impl/ParserProvider/LoggingAbstractSyntaxTree.cs index da5f433a..87065525 100644 --- a/Interpreter.Lib/Semantic/LoggingAbstractSyntaxTree.cs +++ b/Interpreter/Services/Providers/Impl/ParserProvider/LoggingAbstractSyntaxTree.cs @@ -4,7 +4,7 @@ using Interpreter.Lib.Contracts; using Interpreter.Lib.IR.Instructions; -namespace Interpreter.Lib.Semantic +namespace Interpreter.Services.Providers.Impl.ParserProvider { public class LoggingAbstractSyntaxTree : IAbstractSyntaxTree { diff --git a/Interpreter.Lib/FrontEnd/TopDownParse/Impl/LoggingParser.cs b/Interpreter/Services/Providers/Impl/ParserProvider/LoggingParser.cs similarity index 85% rename from Interpreter.Lib/FrontEnd/TopDownParse/Impl/LoggingParser.cs rename to Interpreter/Services/Providers/Impl/ParserProvider/LoggingParser.cs index 6314f084..01b912e7 100644 --- a/Interpreter.Lib/FrontEnd/TopDownParse/Impl/LoggingParser.cs +++ b/Interpreter/Services/Providers/Impl/ParserProvider/LoggingParser.cs @@ -1,8 +1,8 @@ using System.IO; using Interpreter.Lib.Contracts; -using Interpreter.Lib.Semantic; +using Interpreter.Lib.FrontEnd.TopDownParse; -namespace Interpreter.Lib.FrontEnd.TopDownParse.Impl +namespace Interpreter.Services.Providers.Impl.ParserProvider { public class LoggingParser : IParser { diff --git a/Interpreter/Services/Providers/Impl/ParserProvider.cs b/Interpreter/Services/Providers/Impl/ParserProvider/ParserProvider.cs similarity index 85% rename from Interpreter/Services/Providers/Impl/ParserProvider.cs rename to Interpreter/Services/Providers/Impl/ParserProvider/ParserProvider.cs index 4e0f2ded..658faab4 100644 --- a/Interpreter/Services/Providers/Impl/ParserProvider.cs +++ b/Interpreter/Services/Providers/Impl/ParserProvider/ParserProvider.cs @@ -1,8 +1,8 @@ using Interpreter.Lib.FrontEnd.TopDownParse; -using Interpreter.Lib.FrontEnd.TopDownParse.Impl; +using Parser = Interpreter.Lib.FrontEnd.TopDownParse.Impl.Parser; using Microsoft.Extensions.Options; -namespace Interpreter.Services.Providers.Impl +namespace Interpreter.Services.Providers.Impl.ParserProvider { public class ParserProvider : IParserProvider { @@ -14,7 +14,7 @@ public ParserProvider(ILexerProvider lexerProvider, IOptions Date: Wed, 14 Sep 2022 14:16:20 +0300 Subject: [PATCH 23/56] =?UTF-8?q?=D0=BC=D0=B0=D1=88=D1=82=D0=B0=D0=B1?= =?UTF-8?q?=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B5=D0=BE=D1=80=D0=B3=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20=D1=84=D0=B0=D0=B9=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2=20-=203=20=D0=B2=D0=B5=D1=80=D1=85=D0=BD=D0=B5?= =?UTF-8?q?=D1=83=D1=80=D0=BE=D0=B2=D0=BD=D0=B5=D0=B2=D1=8B=D1=85=20=D0=BA?= =?UTF-8?q?=D0=BE=D0=BD=D1=82=D0=B5=D0=BA=D1=81=D1=82=D0=B0:?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit FrontEnd - лексер, парсер (создание AST) IR - промежуточное представление (AST, проверка семантики) BackEnd - виртуальная машина и её инструкции --- Interpreter.Lib/{VM => BackEnd}/Call.cs | 2 +- Interpreter.Lib/{VM => BackEnd}/Frame.cs | 2 +- .../{VM => BackEnd}/FunctionInfo.cs | 2 +- .../{IR => BackEnd}/Instructions/AsString.cs | 5 ++-- .../Instructions/BeginFunction.cs | 4 +-- .../Instructions/CallFunction.cs | 3 +- .../Instructions/CreateArray.cs | 3 +- .../Instructions/CreateObject.cs | 3 +- .../Instructions/DotAssignment.cs | 5 ++-- .../{IR => BackEnd}/Instructions/Goto.cs | 4 +-- .../{IR => BackEnd}/Instructions/Halt.cs | 4 +-- .../{IR => BackEnd}/Instructions/IfNotGoto.cs | 5 ++-- .../Instructions/IndexAssignment.cs | 5 ++-- .../Instructions/Instruction.cs | 3 +- .../{IR => BackEnd}/Instructions/Print.cs | 5 ++-- .../Instructions/PushParameter.cs | 5 ++-- .../Instructions/RemoveFromArray.cs | 5 ++-- .../{IR => BackEnd}/Instructions/Return.cs | 5 ++-- .../{IR => BackEnd}/Instructions/Simple.cs | 5 ++-- .../{VM => BackEnd}/Values/Constant.cs | 2 +- .../{VM => BackEnd}/Values/IValue.cs | 2 +- .../{VM => BackEnd}/Values/Name.cs | 2 +- .../{VM => BackEnd}/VirtualMachine.cs | 4 +-- .../FrontEnd/TopDownParse/IParser.cs | 2 +- .../FrontEnd/TopDownParse/Impl/Parser.cs | 28 +++++++++---------- .../Ast}/IAbstractSyntaxTree.cs | 4 +-- .../Ast/Impl}/AbstractSyntaxTree.cs | 7 ++--- .../Ast}/Nodes/AbstractSyntaxTreeNode.cs | 9 +++--- .../Ast}/Nodes/Declarations/Declaration.cs | 2 +- .../Nodes/Declarations/FunctionDeclaration.cs | 12 ++++---- .../Nodes/Declarations/LexicalDeclaration.cs | 10 +++---- .../AccessExpressions/AccessExpression.cs | 4 +-- .../AccessExpressions/DotAccess.cs | 14 +++++----- .../AccessExpressions/IndexAccess.cs | 15 +++++----- .../Nodes/Expressions/AssignmentExpression.cs | 21 +++++++------- .../Nodes/Expressions/BinaryExpression.cs | 19 ++++++------- .../Ast}/Nodes/Expressions/CallExpression.cs | 22 +++++++-------- .../Nodes/Expressions/CastAsExpression.cs | 11 ++++---- .../ComplexLiterals/ArrayLiteral.cs | 13 ++++----- .../ComplexLiterals/ObjectLiteral.cs | 14 +++++----- .../Expressions/ComplexLiterals/Property.cs | 6 ++-- .../Expressions/ConditionalExpression.cs | 13 ++++----- .../Ast}/Nodes/Expressions/Expression.cs | 4 +-- .../Nodes/Expressions/MemberExpression.cs | 14 +++++----- .../PrimaryExpressions/IdentifierReference.cs | 12 ++++---- .../Expressions/PrimaryExpressions/Literal.cs | 6 ++-- .../PrimaryExpressions/PrimaryExpression.cs | 6 ++-- .../Ast}/Nodes/Expressions/UnaryExpression.cs | 17 ++++++----- .../{Semantic => IR/Ast}/Nodes/ScriptBody.cs | 2 +- .../Ast}/Nodes/StatementListItem.cs | 2 +- .../Ast}/Nodes/Statements/BlockStatement.cs | 4 +-- .../Ast}/Nodes/Statements/BreakStatement.cs | 4 +-- .../Nodes/Statements/ContinueStatement.cs | 4 +-- .../Nodes/Statements/ExpressionStatement.cs | 6 ++-- .../Ast}/Nodes/Statements/IfStatement.cs | 17 ++++++----- .../Nodes/Statements/InsideLoopStatement.cs | 6 ++-- .../Ast}/Nodes/Statements/ReturnStatement.cs | 19 ++++++------- .../Ast}/Nodes/Statements/Statement.cs | 2 +- .../Ast}/Nodes/Statements/TypeStatement.cs | 4 +-- .../Ast}/Nodes/Statements/WhileStatement.cs | 15 +++++----- .../Exceptions/ArrayAccessException.cs | 4 +-- .../Exceptions/AssignmentToConst.cs | 4 +-- .../Exceptions/CannotDefineType.cs | 2 +- .../Exceptions/ConstWithoutInitializer.cs | 4 +-- .../Exceptions/DeclarationAlreadyExists.cs | 4 +-- .../FunctionWithoutReturnStatement.cs | 2 +- .../Exceptions/IncompatibleTypesOfOperands.cs | 4 +-- .../Exceptions/NotBooleanTestExpression.cs | 4 +-- .../Exceptions/ObjectAccessException.cs | 4 +-- .../Exceptions/OutsideOfLoop.cs | 2 +- .../Exceptions/ReturnOutsideFunction.cs | 2 +- .../Exceptions/SemanticException.cs | 2 +- .../Exceptions/SymbolIsNotCallable.cs | 2 +- .../Exceptions/UnknownIdentifierReference.cs | 4 +-- .../Exceptions/UnsupportedOperation.cs | 4 +-- .../WrongArrayLiteralDeclaration.cs | 4 +-- .../Exceptions/WrongConditionalTypes.cs | 4 +-- .../Exceptions/WrongNumberOfArguments.cs | 2 +- .../Exceptions/WrongReturnType.cs | 4 +-- .../Exceptions/WrongTypeOfArgument.cs | 4 +-- .../CheckSemantics}/Types/Any.cs | 2 +- .../CheckSemantics}/Types/ArrayType.cs | 4 +-- .../CheckSemantics}/Types/FunctionType.cs | 4 +-- .../CheckSemantics}/Types/NullType.cs | 2 +- .../CheckSemantics}/Types/NullableType.cs | 4 +-- .../CheckSemantics}/Types/ObjectType.cs | 4 +-- .../CheckSemantics}/Types/Type.cs | 4 +-- .../CheckSemantics/Types}/TypeUtils.cs | 3 +- .../Types/Visitors/ObjectTypePrinter.cs | 2 +- .../Types/Visitors/ReferenceResolver.cs | 2 +- .../CheckSemantics/Variables}/SymbolTable.cs | 6 ++-- .../Variables}/SymbolTableUtils.cs | 12 ++++---- .../Variables}/Symbols/FunctionSymbol.cs | 8 +++--- .../Variables}/Symbols/ObjectSymbol.cs | 4 +-- .../Variables}/Symbols/Symbol.cs | 2 +- .../Variables}/Symbols/VariableSymbol.cs | 4 +-- Interpreter.Tests/Unit/AstNodeTests.cs | 10 +++---- Interpreter.Tests/Unit/ExpressionTests.cs | 6 ++-- Interpreter.Tests/Unit/SymbolTableTests.cs | 6 ++-- Interpreter.Tests/Unit/TypeTests.cs | 3 +- .../Services/Executor/Impl/Executor.cs | 4 +-- .../Services/Parsing/IParsingService.cs | 2 +- .../Services/Parsing/Impl/ParsingService.cs | 2 +- .../LoggingAbstractSyntaxTree.cs | 4 +-- .../Impl/ParserProvider/LoggingParser.cs | 2 +- 105 files changed, 298 insertions(+), 329 deletions(-) rename Interpreter.Lib/{VM => BackEnd}/Call.cs (91%) rename Interpreter.Lib/{VM => BackEnd}/Frame.cs (94%) rename Interpreter.Lib/{VM => BackEnd}/FunctionInfo.cs (94%) rename Interpreter.Lib/{IR => BackEnd}/Instructions/AsString.cs (95%) rename Interpreter.Lib/{IR => BackEnd}/Instructions/BeginFunction.cs (86%) rename Interpreter.Lib/{IR => BackEnd}/Instructions/CallFunction.cs (95%) rename Interpreter.Lib/{IR => BackEnd}/Instructions/CreateArray.cs (89%) rename Interpreter.Lib/{IR => BackEnd}/Instructions/CreateObject.cs (88%) rename Interpreter.Lib/{IR => BackEnd}/Instructions/DotAssignment.cs (87%) rename Interpreter.Lib/{IR => BackEnd}/Instructions/Goto.cs (86%) rename Interpreter.Lib/{IR => BackEnd}/Instructions/Halt.cs (83%) rename Interpreter.Lib/{IR => BackEnd}/Instructions/IfNotGoto.cs (85%) rename Interpreter.Lib/{IR => BackEnd}/Instructions/IndexAssignment.cs (87%) rename Interpreter.Lib/{IR => BackEnd}/Instructions/Instruction.cs (93%) rename Interpreter.Lib/{IR => BackEnd}/Instructions/Print.cs (82%) rename Interpreter.Lib/{IR => BackEnd}/Instructions/PushParameter.cs (86%) rename Interpreter.Lib/{IR => BackEnd}/Instructions/RemoveFromArray.cs (87%) rename Interpreter.Lib/{IR => BackEnd}/Instructions/Return.cs (91%) rename Interpreter.Lib/{IR => BackEnd}/Instructions/Simple.cs (97%) rename Interpreter.Lib/{VM => BackEnd}/Values/Constant.cs (93%) rename Interpreter.Lib/{VM => BackEnd}/Values/IValue.cs (73%) rename Interpreter.Lib/{VM => BackEnd}/Values/Name.cs (91%) rename Interpreter.Lib/{VM => BackEnd}/VirtualMachine.cs (89%) rename Interpreter.Lib/{Contracts => IR/Ast}/IAbstractSyntaxTree.cs (63%) rename Interpreter.Lib/{Semantic => IR/Ast/Impl}/AbstractSyntaxTree.cs (93%) rename Interpreter.Lib/{Semantic => IR/Ast}/Nodes/AbstractSyntaxTreeNode.cs (89%) rename Interpreter.Lib/{Semantic => IR/Ast}/Nodes/Declarations/Declaration.cs (70%) rename Interpreter.Lib/{Semantic => IR/Ast}/Nodes/Declarations/FunctionDeclaration.cs (90%) rename Interpreter.Lib/{Semantic => IR/Ast}/Nodes/Declarations/LexicalDeclaration.cs (88%) rename Interpreter.Lib/{Semantic => IR/Ast}/Nodes/Expressions/AccessExpressions/AccessExpression.cs (85%) rename Interpreter.Lib/{Semantic => IR/Ast}/Nodes/Expressions/AccessExpressions/DotAccess.cs (80%) rename Interpreter.Lib/{Semantic => IR/Ast}/Nodes/Expressions/AccessExpressions/IndexAccess.cs (83%) rename Interpreter.Lib/{Semantic => IR/Ast}/Nodes/Expressions/AssignmentExpression.cs (93%) rename Interpreter.Lib/{Semantic => IR/Ast}/Nodes/Expressions/BinaryExpression.cs (94%) rename Interpreter.Lib/{Semantic => IR/Ast}/Nodes/Expressions/CallExpression.cs (92%) rename Interpreter.Lib/{Semantic => IR/Ast}/Nodes/Expressions/CastAsExpression.cs (84%) rename Interpreter.Lib/{Semantic => IR/Ast}/Nodes/Expressions/ComplexLiterals/ArrayLiteral.cs (87%) rename Interpreter.Lib/{Semantic => IR/Ast}/Nodes/Expressions/ComplexLiterals/ObjectLiteral.cs (89%) rename Interpreter.Lib/{Semantic => IR/Ast}/Nodes/Expressions/ComplexLiterals/Property.cs (84%) rename Interpreter.Lib/{Semantic => IR/Ast}/Nodes/Expressions/ConditionalExpression.cs (89%) rename Interpreter.Lib/{Semantic => IR/Ast}/Nodes/Expressions/Expression.cs (78%) rename Interpreter.Lib/{Semantic => IR/Ast}/Nodes/Expressions/MemberExpression.cs (82%) rename Interpreter.Lib/{Semantic => IR/Ast}/Nodes/Expressions/PrimaryExpressions/IdentifierReference.cs (69%) rename Interpreter.Lib/{Semantic => IR/Ast}/Nodes/Expressions/PrimaryExpressions/Literal.cs (80%) rename Interpreter.Lib/{Semantic => IR/Ast}/Nodes/Expressions/PrimaryExpressions/PrimaryExpression.cs (75%) rename Interpreter.Lib/{Semantic => IR/Ast}/Nodes/Expressions/UnaryExpression.cs (87%) rename Interpreter.Lib/{Semantic => IR/Ast}/Nodes/ScriptBody.cs (93%) rename Interpreter.Lib/{Semantic => IR/Ast}/Nodes/StatementListItem.cs (82%) rename Interpreter.Lib/{Semantic => IR/Ast}/Nodes/Statements/BlockStatement.cs (94%) rename Interpreter.Lib/{Semantic => IR/Ast}/Nodes/Statements/BreakStatement.cs (77%) rename Interpreter.Lib/{Semantic => IR/Ast}/Nodes/Statements/ContinueStatement.cs (78%) rename Interpreter.Lib/{Semantic => IR/Ast}/Nodes/Statements/ExpressionStatement.cs (81%) rename Interpreter.Lib/{Semantic => IR/Ast}/Nodes/Statements/IfStatement.cs (90%) rename Interpreter.Lib/{Semantic => IR/Ast}/Nodes/Statements/InsideLoopStatement.cs (79%) rename Interpreter.Lib/{Semantic => IR/Ast}/Nodes/Statements/ReturnStatement.cs (84%) rename Interpreter.Lib/{Semantic => IR/Ast}/Nodes/Statements/Statement.cs (70%) rename Interpreter.Lib/{Semantic => IR/Ast}/Nodes/Statements/TypeStatement.cs (85%) rename Interpreter.Lib/{Semantic => IR/Ast}/Nodes/Statements/WhileStatement.cs (88%) rename Interpreter.Lib/{Semantic => IR/CheckSemantics}/Exceptions/ArrayAccessException.cs (75%) rename Interpreter.Lib/{Semantic => IR/CheckSemantics}/Exceptions/AssignmentToConst.cs (67%) rename Interpreter.Lib/{Semantic => IR/CheckSemantics}/Exceptions/CannotDefineType.cs (81%) rename Interpreter.Lib/{Semantic => IR/CheckSemantics}/Exceptions/ConstWithoutInitializer.cs (65%) rename Interpreter.Lib/{Semantic => IR/CheckSemantics}/Exceptions/DeclarationAlreadyExists.cs (65%) rename Interpreter.Lib/{Semantic => IR/CheckSemantics}/Exceptions/FunctionWithoutReturnStatement.cs (86%) rename Interpreter.Lib/{Semantic => IR/CheckSemantics}/Exceptions/IncompatibleTypesOfOperands.cs (77%) rename Interpreter.Lib/{Semantic => IR/CheckSemantics}/Exceptions/NotBooleanTestExpression.cs (76%) rename Interpreter.Lib/{Semantic => IR/CheckSemantics}/Exceptions/ObjectAccessException.cs (75%) rename Interpreter.Lib/{Semantic => IR/CheckSemantics}/Exceptions/OutsideOfLoop.cs (84%) rename Interpreter.Lib/{Semantic => IR/CheckSemantics}/Exceptions/ReturnOutsideFunction.cs (83%) rename Interpreter.Lib/{Semantic => IR/CheckSemantics}/Exceptions/SemanticException.cs (75%) rename Interpreter.Lib/{Semantic => IR/CheckSemantics}/Exceptions/SymbolIsNotCallable.cs (83%) rename Interpreter.Lib/{Semantic => IR/CheckSemantics}/Exceptions/UnknownIdentifierReference.cs (69%) rename Interpreter.Lib/{Semantic => IR/CheckSemantics}/Exceptions/UnsupportedOperation.cs (76%) rename Interpreter.Lib/{Semantic => IR/CheckSemantics}/Exceptions/WrongArrayLiteralDeclaration.cs (76%) rename Interpreter.Lib/{Semantic => IR/CheckSemantics}/Exceptions/WrongConditionalTypes.cs (79%) rename Interpreter.Lib/{Semantic => IR/CheckSemantics}/Exceptions/WrongNumberOfArguments.cs (86%) rename Interpreter.Lib/{Semantic => IR/CheckSemantics}/Exceptions/WrongReturnType.cs (75%) rename Interpreter.Lib/{Semantic => IR/CheckSemantics}/Exceptions/WrongTypeOfArgument.cs (77%) rename Interpreter.Lib/{Semantic => IR/CheckSemantics}/Types/Any.cs (81%) rename Interpreter.Lib/{Semantic => IR/CheckSemantics}/Types/ArrayType.cs (89%) rename Interpreter.Lib/{Semantic => IR/CheckSemantics}/Types/FunctionType.cs (94%) rename Interpreter.Lib/{Semantic => IR/CheckSemantics}/Types/NullType.cs (86%) rename Interpreter.Lib/{Semantic => IR/CheckSemantics}/Types/NullableType.cs (89%) rename Interpreter.Lib/{Semantic => IR/CheckSemantics}/Types/ObjectType.cs (95%) rename Interpreter.Lib/{Semantic => IR/CheckSemantics}/Types/Type.cs (91%) rename Interpreter.Lib/{Semantic/Utils => IR/CheckSemantics/Types}/TypeUtils.cs (94%) rename Interpreter.Lib/{Semantic => IR/CheckSemantics}/Types/Visitors/ObjectTypePrinter.cs (97%) rename Interpreter.Lib/{Semantic => IR/CheckSemantics}/Types/Visitors/ReferenceResolver.cs (97%) rename Interpreter.Lib/{Semantic => IR/CheckSemantics/Variables}/SymbolTable.cs (89%) rename Interpreter.Lib/{Semantic/Utils => IR/CheckSemantics/Variables}/SymbolTableUtils.cs (84%) rename Interpreter.Lib/{Semantic => IR/CheckSemantics/Variables}/Symbols/FunctionSymbol.cs (81%) rename Interpreter.Lib/{Semantic => IR/CheckSemantics/Variables}/Symbols/ObjectSymbol.cs (86%) rename Interpreter.Lib/{Semantic => IR/CheckSemantics/Variables}/Symbols/Symbol.cs (79%) rename Interpreter.Lib/{Semantic => IR/CheckSemantics/Variables}/Symbols/VariableSymbol.cs (74%) diff --git a/Interpreter.Lib/VM/Call.cs b/Interpreter.Lib/BackEnd/Call.cs similarity index 91% rename from Interpreter.Lib/VM/Call.cs rename to Interpreter.Lib/BackEnd/Call.cs index 162591ab..4338c9b3 100644 --- a/Interpreter.Lib/VM/Call.cs +++ b/Interpreter.Lib/BackEnd/Call.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using System.Linq; -namespace Interpreter.Lib.VM +namespace Interpreter.Lib.BackEnd { public record Call( int From, FunctionInfo To, diff --git a/Interpreter.Lib/VM/Frame.cs b/Interpreter.Lib/BackEnd/Frame.cs similarity index 94% rename from Interpreter.Lib/VM/Frame.cs rename to Interpreter.Lib/BackEnd/Frame.cs index 389e5a52..420c2164 100644 --- a/Interpreter.Lib/VM/Frame.cs +++ b/Interpreter.Lib/BackEnd/Frame.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace Interpreter.Lib.VM +namespace Interpreter.Lib.BackEnd { public class Frame { diff --git a/Interpreter.Lib/VM/FunctionInfo.cs b/Interpreter.Lib/BackEnd/FunctionInfo.cs similarity index 94% rename from Interpreter.Lib/VM/FunctionInfo.cs rename to Interpreter.Lib/BackEnd/FunctionInfo.cs index fd21c491..d497d187 100644 --- a/Interpreter.Lib/VM/FunctionInfo.cs +++ b/Interpreter.Lib/BackEnd/FunctionInfo.cs @@ -1,4 +1,4 @@ -namespace Interpreter.Lib.VM +namespace Interpreter.Lib.BackEnd { public class FunctionInfo { diff --git a/Interpreter.Lib/IR/Instructions/AsString.cs b/Interpreter.Lib/BackEnd/Instructions/AsString.cs similarity index 95% rename from Interpreter.Lib/IR/Instructions/AsString.cs rename to Interpreter.Lib/BackEnd/Instructions/AsString.cs index 0f290169..f33e971b 100644 --- a/Interpreter.Lib/IR/Instructions/AsString.cs +++ b/Interpreter.Lib/BackEnd/Instructions/AsString.cs @@ -1,11 +1,10 @@ using System; using System.Collections.Generic; -using Interpreter.Lib.VM; -using Interpreter.Lib.VM.Values; +using Interpreter.Lib.BackEnd.Values; using Newtonsoft.Json; using Newtonsoft.Json.Serialization; -namespace Interpreter.Lib.IR.Instructions +namespace Interpreter.Lib.BackEnd.Instructions { public class AsString : Simple { diff --git a/Interpreter.Lib/IR/Instructions/BeginFunction.cs b/Interpreter.Lib/BackEnd/Instructions/BeginFunction.cs similarity index 86% rename from Interpreter.Lib/IR/Instructions/BeginFunction.cs rename to Interpreter.Lib/BackEnd/Instructions/BeginFunction.cs index 5ef3a385..69da704b 100644 --- a/Interpreter.Lib/IR/Instructions/BeginFunction.cs +++ b/Interpreter.Lib/BackEnd/Instructions/BeginFunction.cs @@ -1,6 +1,4 @@ -using Interpreter.Lib.VM; - -namespace Interpreter.Lib.IR.Instructions +namespace Interpreter.Lib.BackEnd.Instructions { public class BeginFunction : Instruction { diff --git a/Interpreter.Lib/IR/Instructions/CallFunction.cs b/Interpreter.Lib/BackEnd/Instructions/CallFunction.cs similarity index 95% rename from Interpreter.Lib/IR/Instructions/CallFunction.cs rename to Interpreter.Lib/BackEnd/Instructions/CallFunction.cs index 666b255e..dd737278 100644 --- a/Interpreter.Lib/IR/Instructions/CallFunction.cs +++ b/Interpreter.Lib/BackEnd/Instructions/CallFunction.cs @@ -1,8 +1,7 @@ using System; using System.Collections.Generic; -using Interpreter.Lib.VM; -namespace Interpreter.Lib.IR.Instructions +namespace Interpreter.Lib.BackEnd.Instructions { public class CallFunction : Simple { diff --git a/Interpreter.Lib/IR/Instructions/CreateArray.cs b/Interpreter.Lib/BackEnd/Instructions/CreateArray.cs similarity index 89% rename from Interpreter.Lib/IR/Instructions/CreateArray.cs rename to Interpreter.Lib/BackEnd/Instructions/CreateArray.cs index 2c0a2e7c..7f506a93 100644 --- a/Interpreter.Lib/IR/Instructions/CreateArray.cs +++ b/Interpreter.Lib/BackEnd/Instructions/CreateArray.cs @@ -1,7 +1,6 @@ using System.Linq; -using Interpreter.Lib.VM; -namespace Interpreter.Lib.IR.Instructions +namespace Interpreter.Lib.BackEnd.Instructions { public class CreateArray : Instruction { diff --git a/Interpreter.Lib/IR/Instructions/CreateObject.cs b/Interpreter.Lib/BackEnd/Instructions/CreateObject.cs similarity index 88% rename from Interpreter.Lib/IR/Instructions/CreateObject.cs rename to Interpreter.Lib/BackEnd/Instructions/CreateObject.cs index 002aed5d..65e05eeb 100644 --- a/Interpreter.Lib/IR/Instructions/CreateObject.cs +++ b/Interpreter.Lib/BackEnd/Instructions/CreateObject.cs @@ -1,7 +1,6 @@ using System.Collections.Generic; -using Interpreter.Lib.VM; -namespace Interpreter.Lib.IR.Instructions +namespace Interpreter.Lib.BackEnd.Instructions { public class CreateObject : Instruction { diff --git a/Interpreter.Lib/IR/Instructions/DotAssignment.cs b/Interpreter.Lib/BackEnd/Instructions/DotAssignment.cs similarity index 87% rename from Interpreter.Lib/IR/Instructions/DotAssignment.cs rename to Interpreter.Lib/BackEnd/Instructions/DotAssignment.cs index 74c8d8b4..42121337 100644 --- a/Interpreter.Lib/IR/Instructions/DotAssignment.cs +++ b/Interpreter.Lib/BackEnd/Instructions/DotAssignment.cs @@ -1,8 +1,7 @@ using System.Collections.Generic; -using Interpreter.Lib.VM; -using Interpreter.Lib.VM.Values; +using Interpreter.Lib.BackEnd.Values; -namespace Interpreter.Lib.IR.Instructions +namespace Interpreter.Lib.BackEnd.Instructions { public class DotAssignment : Simple { diff --git a/Interpreter.Lib/IR/Instructions/Goto.cs b/Interpreter.Lib/BackEnd/Instructions/Goto.cs similarity index 86% rename from Interpreter.Lib/IR/Instructions/Goto.cs rename to Interpreter.Lib/BackEnd/Instructions/Goto.cs index 6881fffc..96e03b9a 100644 --- a/Interpreter.Lib/IR/Instructions/Goto.cs +++ b/Interpreter.Lib/BackEnd/Instructions/Goto.cs @@ -1,6 +1,4 @@ -using Interpreter.Lib.VM; - -namespace Interpreter.Lib.IR.Instructions +namespace Interpreter.Lib.BackEnd.Instructions { public class Goto : Instruction { diff --git a/Interpreter.Lib/IR/Instructions/Halt.cs b/Interpreter.Lib/BackEnd/Instructions/Halt.cs similarity index 83% rename from Interpreter.Lib/IR/Instructions/Halt.cs rename to Interpreter.Lib/BackEnd/Instructions/Halt.cs index 0c160cfa..614a7a2f 100644 --- a/Interpreter.Lib/IR/Instructions/Halt.cs +++ b/Interpreter.Lib/BackEnd/Instructions/Halt.cs @@ -1,6 +1,4 @@ -using Interpreter.Lib.VM; - -namespace Interpreter.Lib.IR.Instructions +namespace Interpreter.Lib.BackEnd.Instructions { public class Halt : Instruction { diff --git a/Interpreter.Lib/IR/Instructions/IfNotGoto.cs b/Interpreter.Lib/BackEnd/Instructions/IfNotGoto.cs similarity index 85% rename from Interpreter.Lib/IR/Instructions/IfNotGoto.cs rename to Interpreter.Lib/BackEnd/Instructions/IfNotGoto.cs index ae994416..6f275799 100644 --- a/Interpreter.Lib/IR/Instructions/IfNotGoto.cs +++ b/Interpreter.Lib/BackEnd/Instructions/IfNotGoto.cs @@ -1,8 +1,7 @@ using System; -using Interpreter.Lib.VM; -using Interpreter.Lib.VM.Values; +using Interpreter.Lib.BackEnd.Values; -namespace Interpreter.Lib.IR.Instructions +namespace Interpreter.Lib.BackEnd.Instructions { public class IfNotGoto : Goto { diff --git a/Interpreter.Lib/IR/Instructions/IndexAssignment.cs b/Interpreter.Lib/BackEnd/Instructions/IndexAssignment.cs similarity index 87% rename from Interpreter.Lib/IR/Instructions/IndexAssignment.cs rename to Interpreter.Lib/BackEnd/Instructions/IndexAssignment.cs index fe022674..3865d73e 100644 --- a/Interpreter.Lib/IR/Instructions/IndexAssignment.cs +++ b/Interpreter.Lib/BackEnd/Instructions/IndexAssignment.cs @@ -1,9 +1,8 @@ using System; using System.Collections.Generic; -using Interpreter.Lib.VM; -using Interpreter.Lib.VM.Values; +using Interpreter.Lib.BackEnd.Values; -namespace Interpreter.Lib.IR.Instructions +namespace Interpreter.Lib.BackEnd.Instructions { public class IndexAssignment : Simple { diff --git a/Interpreter.Lib/IR/Instructions/Instruction.cs b/Interpreter.Lib/BackEnd/Instructions/Instruction.cs similarity index 93% rename from Interpreter.Lib/IR/Instructions/Instruction.cs rename to Interpreter.Lib/BackEnd/Instructions/Instruction.cs index 4f126b5f..8c8443da 100644 --- a/Interpreter.Lib/IR/Instructions/Instruction.cs +++ b/Interpreter.Lib/BackEnd/Instructions/Instruction.cs @@ -1,7 +1,6 @@ using System; -using Interpreter.Lib.VM; -namespace Interpreter.Lib.IR.Instructions +namespace Interpreter.Lib.BackEnd.Instructions { public abstract class Instruction : IComparable, IEquatable { diff --git a/Interpreter.Lib/IR/Instructions/Print.cs b/Interpreter.Lib/BackEnd/Instructions/Print.cs similarity index 82% rename from Interpreter.Lib/IR/Instructions/Print.cs rename to Interpreter.Lib/BackEnd/Instructions/Print.cs index a025bf46..1a05d832 100644 --- a/Interpreter.Lib/IR/Instructions/Print.cs +++ b/Interpreter.Lib/BackEnd/Instructions/Print.cs @@ -1,8 +1,7 @@ using System; -using Interpreter.Lib.VM; -using Interpreter.Lib.VM.Values; +using Interpreter.Lib.BackEnd.Values; -namespace Interpreter.Lib.IR.Instructions +namespace Interpreter.Lib.BackEnd.Instructions { public class Print : Instruction { diff --git a/Interpreter.Lib/IR/Instructions/PushParameter.cs b/Interpreter.Lib/BackEnd/Instructions/PushParameter.cs similarity index 86% rename from Interpreter.Lib/IR/Instructions/PushParameter.cs rename to Interpreter.Lib/BackEnd/Instructions/PushParameter.cs index 7f8647d5..97358e4c 100644 --- a/Interpreter.Lib/IR/Instructions/PushParameter.cs +++ b/Interpreter.Lib/BackEnd/Instructions/PushParameter.cs @@ -1,7 +1,6 @@ -using Interpreter.Lib.VM; -using Interpreter.Lib.VM.Values; +using Interpreter.Lib.BackEnd.Values; -namespace Interpreter.Lib.IR.Instructions +namespace Interpreter.Lib.BackEnd.Instructions { public class PushParameter : Instruction { diff --git a/Interpreter.Lib/IR/Instructions/RemoveFromArray.cs b/Interpreter.Lib/BackEnd/Instructions/RemoveFromArray.cs similarity index 87% rename from Interpreter.Lib/IR/Instructions/RemoveFromArray.cs rename to Interpreter.Lib/BackEnd/Instructions/RemoveFromArray.cs index bceb79ba..11f65e17 100644 --- a/Interpreter.Lib/IR/Instructions/RemoveFromArray.cs +++ b/Interpreter.Lib/BackEnd/Instructions/RemoveFromArray.cs @@ -1,9 +1,8 @@ using System; using System.Collections.Generic; -using Interpreter.Lib.VM; -using Interpreter.Lib.VM.Values; +using Interpreter.Lib.BackEnd.Values; -namespace Interpreter.Lib.IR.Instructions +namespace Interpreter.Lib.BackEnd.Instructions { public class RemoveFromArray : Instruction { diff --git a/Interpreter.Lib/IR/Instructions/Return.cs b/Interpreter.Lib/BackEnd/Instructions/Return.cs similarity index 91% rename from Interpreter.Lib/IR/Instructions/Return.cs rename to Interpreter.Lib/BackEnd/Instructions/Return.cs index 01de99da..b1355aaa 100644 --- a/Interpreter.Lib/IR/Instructions/Return.cs +++ b/Interpreter.Lib/BackEnd/Instructions/Return.cs @@ -1,9 +1,8 @@ using System.Collections; using System.Collections.Generic; -using Interpreter.Lib.VM; -using Interpreter.Lib.VM.Values; +using Interpreter.Lib.BackEnd.Values; -namespace Interpreter.Lib.IR.Instructions +namespace Interpreter.Lib.BackEnd.Instructions { public class Return : Instruction, IEnumerable { diff --git a/Interpreter.Lib/IR/Instructions/Simple.cs b/Interpreter.Lib/BackEnd/Instructions/Simple.cs similarity index 97% rename from Interpreter.Lib/IR/Instructions/Simple.cs rename to Interpreter.Lib/BackEnd/Instructions/Simple.cs index cf1dbc42..7ad6d5b4 100644 --- a/Interpreter.Lib/IR/Instructions/Simple.cs +++ b/Interpreter.Lib/BackEnd/Instructions/Simple.cs @@ -1,10 +1,9 @@ using System; using System.Collections.Generic; using System.Linq; -using Interpreter.Lib.VM; -using Interpreter.Lib.VM.Values; +using Interpreter.Lib.BackEnd.Values; -namespace Interpreter.Lib.IR.Instructions +namespace Interpreter.Lib.BackEnd.Instructions { public class Simple : Instruction { diff --git a/Interpreter.Lib/VM/Values/Constant.cs b/Interpreter.Lib/BackEnd/Values/Constant.cs similarity index 93% rename from Interpreter.Lib/VM/Values/Constant.cs rename to Interpreter.Lib/BackEnd/Values/Constant.cs index f11e8788..70c87341 100644 --- a/Interpreter.Lib/VM/Values/Constant.cs +++ b/Interpreter.Lib/BackEnd/Values/Constant.cs @@ -1,4 +1,4 @@ -namespace Interpreter.Lib.VM.Values +namespace Interpreter.Lib.BackEnd.Values { public class Constant : IValue { diff --git a/Interpreter.Lib/VM/Values/IValue.cs b/Interpreter.Lib/BackEnd/Values/IValue.cs similarity index 73% rename from Interpreter.Lib/VM/Values/IValue.cs rename to Interpreter.Lib/BackEnd/Values/IValue.cs index 2f235d1f..06255e67 100644 --- a/Interpreter.Lib/VM/Values/IValue.cs +++ b/Interpreter.Lib/BackEnd/Values/IValue.cs @@ -1,6 +1,6 @@ using System; -namespace Interpreter.Lib.VM.Values +namespace Interpreter.Lib.BackEnd.Values { public interface IValue : IEquatable { diff --git a/Interpreter.Lib/VM/Values/Name.cs b/Interpreter.Lib/BackEnd/Values/Name.cs similarity index 91% rename from Interpreter.Lib/VM/Values/Name.cs rename to Interpreter.Lib/BackEnd/Values/Name.cs index 92d643e7..7c01b685 100644 --- a/Interpreter.Lib/VM/Values/Name.cs +++ b/Interpreter.Lib/BackEnd/Values/Name.cs @@ -1,4 +1,4 @@ -namespace Interpreter.Lib.VM.Values +namespace Interpreter.Lib.BackEnd.Values { public class Name : IValue { diff --git a/Interpreter.Lib/VM/VirtualMachine.cs b/Interpreter.Lib/BackEnd/VirtualMachine.cs similarity index 89% rename from Interpreter.Lib/VM/VirtualMachine.cs rename to Interpreter.Lib/BackEnd/VirtualMachine.cs index 4b34af75..5e8be74c 100644 --- a/Interpreter.Lib/VM/VirtualMachine.cs +++ b/Interpreter.Lib/BackEnd/VirtualMachine.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; -using Interpreter.Lib.IR.Instructions; +using Interpreter.Lib.BackEnd.Instructions; -namespace Interpreter.Lib.VM +namespace Interpreter.Lib.BackEnd { public class VirtualMachine { diff --git a/Interpreter.Lib/FrontEnd/TopDownParse/IParser.cs b/Interpreter.Lib/FrontEnd/TopDownParse/IParser.cs index 5cdbb154..f91f82c3 100644 --- a/Interpreter.Lib/FrontEnd/TopDownParse/IParser.cs +++ b/Interpreter.Lib/FrontEnd/TopDownParse/IParser.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.Contracts; +using Interpreter.Lib.IR.Ast; namespace Interpreter.Lib.FrontEnd.TopDownParse { diff --git a/Interpreter.Lib/FrontEnd/TopDownParse/Impl/Parser.cs b/Interpreter.Lib/FrontEnd/TopDownParse/Impl/Parser.cs index b11282ab..11c72988 100644 --- a/Interpreter.Lib/FrontEnd/TopDownParse/Impl/Parser.cs +++ b/Interpreter.Lib/FrontEnd/TopDownParse/Impl/Parser.cs @@ -1,22 +1,22 @@ using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; -using Interpreter.Lib.Contracts; using Interpreter.Lib.FrontEnd.GetTokens; using Interpreter.Lib.FrontEnd.GetTokens.Impl; -using Interpreter.Lib.Semantic; -using Interpreter.Lib.Semantic.Exceptions; -using Interpreter.Lib.Semantic.Nodes; -using Interpreter.Lib.Semantic.Nodes.Declarations; -using Interpreter.Lib.Semantic.Nodes.Expressions; -using Interpreter.Lib.Semantic.Nodes.Expressions.AccessExpressions; -using Interpreter.Lib.Semantic.Nodes.Expressions.ComplexLiterals; -using Interpreter.Lib.Semantic.Nodes.Expressions.PrimaryExpressions; -using Interpreter.Lib.Semantic.Nodes.Statements; -using Interpreter.Lib.Semantic.Symbols; -using Interpreter.Lib.Semantic.Types; -using Interpreter.Lib.Semantic.Utils; -using Expression = Interpreter.Lib.Semantic.Nodes.Expressions.Expression; +using Interpreter.Lib.IR.Ast; +using Interpreter.Lib.IR.Ast.Impl; +using Interpreter.Lib.IR.Ast.Nodes; +using Interpreter.Lib.IR.Ast.Nodes.Declarations; +using Interpreter.Lib.IR.Ast.Nodes.Expressions; +using Interpreter.Lib.IR.Ast.Nodes.Expressions.AccessExpressions; +using Interpreter.Lib.IR.Ast.Nodes.Expressions.ComplexLiterals; +using Interpreter.Lib.IR.Ast.Nodes.Expressions.PrimaryExpressions; +using Interpreter.Lib.IR.Ast.Nodes.Statements; +using Interpreter.Lib.IR.CheckSemantics.Exceptions; +using Interpreter.Lib.IR.CheckSemantics.Types; +using Interpreter.Lib.IR.CheckSemantics.Variables; +using Interpreter.Lib.IR.CheckSemantics.Variables.Symbols; +using Expression = Interpreter.Lib.IR.Ast.Nodes.Expressions.Expression; namespace Interpreter.Lib.FrontEnd.TopDownParse.Impl { diff --git a/Interpreter.Lib/Contracts/IAbstractSyntaxTree.cs b/Interpreter.Lib/IR/Ast/IAbstractSyntaxTree.cs similarity index 63% rename from Interpreter.Lib/Contracts/IAbstractSyntaxTree.cs rename to Interpreter.Lib/IR/Ast/IAbstractSyntaxTree.cs index 2d7913cf..d8482dbe 100644 --- a/Interpreter.Lib/Contracts/IAbstractSyntaxTree.cs +++ b/Interpreter.Lib/IR/Ast/IAbstractSyntaxTree.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; -using Interpreter.Lib.IR.Instructions; +using Interpreter.Lib.BackEnd.Instructions; -namespace Interpreter.Lib.Contracts +namespace Interpreter.Lib.IR.Ast { public interface IAbstractSyntaxTree { diff --git a/Interpreter.Lib/Semantic/AbstractSyntaxTree.cs b/Interpreter.Lib/IR/Ast/Impl/AbstractSyntaxTree.cs similarity index 93% rename from Interpreter.Lib/Semantic/AbstractSyntaxTree.cs rename to Interpreter.Lib/IR/Ast/Impl/AbstractSyntaxTree.cs index c1494031..d8981a38 100644 --- a/Interpreter.Lib/Semantic/AbstractSyntaxTree.cs +++ b/Interpreter.Lib/IR/Ast/Impl/AbstractSyntaxTree.cs @@ -1,11 +1,10 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using Interpreter.Lib.Contracts; -using Interpreter.Lib.IR.Instructions; -using Interpreter.Lib.Semantic.Nodes; +using Interpreter.Lib.BackEnd.Instructions; +using Interpreter.Lib.IR.Ast.Nodes; -namespace Interpreter.Lib.Semantic +namespace Interpreter.Lib.IR.Ast.Impl { public class AbstractSyntaxTree : IAbstractSyntaxTree { diff --git a/Interpreter.Lib/Semantic/Nodes/AbstractSyntaxTreeNode.cs b/Interpreter.Lib/IR/Ast/Nodes/AbstractSyntaxTreeNode.cs similarity index 89% rename from Interpreter.Lib/Semantic/Nodes/AbstractSyntaxTreeNode.cs rename to Interpreter.Lib/IR/Ast/Nodes/AbstractSyntaxTreeNode.cs index 3f81b12f..32d7b5d5 100644 --- a/Interpreter.Lib/Semantic/Nodes/AbstractSyntaxTreeNode.cs +++ b/Interpreter.Lib/IR/Ast/Nodes/AbstractSyntaxTreeNode.cs @@ -1,11 +1,12 @@ using System.Collections; using System.Collections.Generic; +using Interpreter.Lib.BackEnd.Instructions; using Interpreter.Lib.FrontEnd.GetTokens.Impl; -using Interpreter.Lib.IR.Instructions; -using Interpreter.Lib.Semantic.Nodes.Declarations; -using Interpreter.Lib.Semantic.Types; +using Interpreter.Lib.IR.Ast.Nodes.Declarations; +using Interpreter.Lib.IR.CheckSemantics.Types; +using Interpreter.Lib.IR.CheckSemantics.Variables; -namespace Interpreter.Lib.Semantic.Nodes +namespace Interpreter.Lib.IR.Ast.Nodes { public abstract class AbstractSyntaxTreeNode : IEnumerable { diff --git a/Interpreter.Lib/Semantic/Nodes/Declarations/Declaration.cs b/Interpreter.Lib/IR/Ast/Nodes/Declarations/Declaration.cs similarity index 70% rename from Interpreter.Lib/Semantic/Nodes/Declarations/Declaration.cs rename to Interpreter.Lib/IR/Ast/Nodes/Declarations/Declaration.cs index 67f3a15e..d96ce825 100644 --- a/Interpreter.Lib/Semantic/Nodes/Declarations/Declaration.cs +++ b/Interpreter.Lib/IR/Ast/Nodes/Declarations/Declaration.cs @@ -1,4 +1,4 @@ -namespace Interpreter.Lib.Semantic.Nodes.Declarations +namespace Interpreter.Lib.IR.Ast.Nodes.Declarations { public abstract class Declaration : StatementListItem { diff --git a/Interpreter.Lib/Semantic/Nodes/Declarations/FunctionDeclaration.cs b/Interpreter.Lib/IR/Ast/Nodes/Declarations/FunctionDeclaration.cs similarity index 90% rename from Interpreter.Lib/Semantic/Nodes/Declarations/FunctionDeclaration.cs rename to Interpreter.Lib/IR/Ast/Nodes/Declarations/FunctionDeclaration.cs index 658ec819..8403d6d7 100644 --- a/Interpreter.Lib/Semantic/Nodes/Declarations/FunctionDeclaration.cs +++ b/Interpreter.Lib/IR/Ast/Nodes/Declarations/FunctionDeclaration.cs @@ -1,12 +1,12 @@ using System.Collections.Generic; using System.Linq; -using Interpreter.Lib.IR.Instructions; -using Interpreter.Lib.Semantic.Exceptions; -using Interpreter.Lib.Semantic.Nodes.Expressions; -using Interpreter.Lib.Semantic.Nodes.Statements; -using Interpreter.Lib.Semantic.Symbols; +using Interpreter.Lib.BackEnd.Instructions; +using Interpreter.Lib.IR.Ast.Nodes.Expressions; +using Interpreter.Lib.IR.Ast.Nodes.Statements; +using Interpreter.Lib.IR.CheckSemantics.Exceptions; +using Interpreter.Lib.IR.CheckSemantics.Variables.Symbols; -namespace Interpreter.Lib.Semantic.Nodes.Declarations +namespace Interpreter.Lib.IR.Ast.Nodes.Declarations { public class FunctionDeclaration : Declaration { diff --git a/Interpreter.Lib/Semantic/Nodes/Declarations/LexicalDeclaration.cs b/Interpreter.Lib/IR/Ast/Nodes/Declarations/LexicalDeclaration.cs similarity index 88% rename from Interpreter.Lib/Semantic/Nodes/Declarations/LexicalDeclaration.cs rename to Interpreter.Lib/IR/Ast/Nodes/Declarations/LexicalDeclaration.cs index f5df8056..407155da 100644 --- a/Interpreter.Lib/Semantic/Nodes/Declarations/LexicalDeclaration.cs +++ b/Interpreter.Lib/IR/Ast/Nodes/Declarations/LexicalDeclaration.cs @@ -1,12 +1,12 @@ using System.Collections.Generic; using System.Linq; +using Interpreter.Lib.BackEnd.Instructions; using Interpreter.Lib.FrontEnd.GetTokens.Impl; -using Interpreter.Lib.IR.Instructions; -using Interpreter.Lib.Semantic.Nodes.Expressions; -using Interpreter.Lib.Semantic.Nodes.Expressions.PrimaryExpressions; -using Interpreter.Lib.Semantic.Types; +using Interpreter.Lib.IR.Ast.Nodes.Expressions; +using Interpreter.Lib.IR.Ast.Nodes.Expressions.PrimaryExpressions; +using Interpreter.Lib.IR.CheckSemantics.Types; -namespace Interpreter.Lib.Semantic.Nodes.Declarations +namespace Interpreter.Lib.IR.Ast.Nodes.Declarations { public class LexicalDeclaration : Declaration { diff --git a/Interpreter.Lib/Semantic/Nodes/Expressions/AccessExpressions/AccessExpression.cs b/Interpreter.Lib/IR/Ast/Nodes/Expressions/AccessExpressions/AccessExpression.cs similarity index 85% rename from Interpreter.Lib/Semantic/Nodes/Expressions/AccessExpressions/AccessExpression.cs rename to Interpreter.Lib/IR/Ast/Nodes/Expressions/AccessExpressions/AccessExpression.cs index 75644115..9b1f3dd4 100644 --- a/Interpreter.Lib/Semantic/Nodes/Expressions/AccessExpressions/AccessExpression.cs +++ b/Interpreter.Lib/IR/Ast/Nodes/Expressions/AccessExpressions/AccessExpression.cs @@ -1,6 +1,6 @@ -using Interpreter.Lib.Semantic.Types; +using Interpreter.Lib.IR.CheckSemantics.Types; -namespace Interpreter.Lib.Semantic.Nodes.Expressions.AccessExpressions +namespace Interpreter.Lib.IR.Ast.Nodes.Expressions.AccessExpressions { public abstract class AccessExpression : Expression { diff --git a/Interpreter.Lib/Semantic/Nodes/Expressions/AccessExpressions/DotAccess.cs b/Interpreter.Lib/IR/Ast/Nodes/Expressions/AccessExpressions/DotAccess.cs similarity index 80% rename from Interpreter.Lib/Semantic/Nodes/Expressions/AccessExpressions/DotAccess.cs rename to Interpreter.Lib/IR/Ast/Nodes/Expressions/AccessExpressions/DotAccess.cs index 44057010..4ba43fce 100644 --- a/Interpreter.Lib/Semantic/Nodes/Expressions/AccessExpressions/DotAccess.cs +++ b/Interpreter.Lib/IR/Ast/Nodes/Expressions/AccessExpressions/DotAccess.cs @@ -1,12 +1,12 @@ using System.Collections.Generic; -using Interpreter.Lib.IR.Instructions; -using Interpreter.Lib.Semantic.Exceptions; -using Interpreter.Lib.Semantic.Nodes.Expressions.PrimaryExpressions; -using Interpreter.Lib.Semantic.Types; -using Interpreter.Lib.VM.Values; -using Type = Interpreter.Lib.Semantic.Types.Type; +using Interpreter.Lib.BackEnd.Instructions; +using Interpreter.Lib.BackEnd.Values; +using Interpreter.Lib.IR.Ast.Nodes.Expressions.PrimaryExpressions; +using Interpreter.Lib.IR.CheckSemantics.Exceptions; +using Interpreter.Lib.IR.CheckSemantics.Types; +using Type = Interpreter.Lib.IR.CheckSemantics.Types.Type; -namespace Interpreter.Lib.Semantic.Nodes.Expressions.AccessExpressions +namespace Interpreter.Lib.IR.Ast.Nodes.Expressions.AccessExpressions { public class DotAccess : AccessExpression { diff --git a/Interpreter.Lib/Semantic/Nodes/Expressions/AccessExpressions/IndexAccess.cs b/Interpreter.Lib/IR/Ast/Nodes/Expressions/AccessExpressions/IndexAccess.cs similarity index 83% rename from Interpreter.Lib/Semantic/Nodes/Expressions/AccessExpressions/IndexAccess.cs rename to Interpreter.Lib/IR/Ast/Nodes/Expressions/AccessExpressions/IndexAccess.cs index 6d8f0223..9116e281 100644 --- a/Interpreter.Lib/Semantic/Nodes/Expressions/AccessExpressions/IndexAccess.cs +++ b/Interpreter.Lib/IR/Ast/Nodes/Expressions/AccessExpressions/IndexAccess.cs @@ -1,14 +1,13 @@ using System; using System.Collections.Generic; -using Interpreter.Lib.IR.Instructions; -using Interpreter.Lib.Semantic.Exceptions; -using Interpreter.Lib.Semantic.Nodes.Expressions.PrimaryExpressions; -using Interpreter.Lib.Semantic.Types; -using Interpreter.Lib.Semantic.Utils; -using Interpreter.Lib.VM.Values; -using Type = Interpreter.Lib.Semantic.Types.Type; +using Interpreter.Lib.BackEnd.Instructions; +using Interpreter.Lib.BackEnd.Values; +using Interpreter.Lib.IR.Ast.Nodes.Expressions.PrimaryExpressions; +using Interpreter.Lib.IR.CheckSemantics.Exceptions; +using Interpreter.Lib.IR.CheckSemantics.Types; +using Type = Interpreter.Lib.IR.CheckSemantics.Types.Type; -namespace Interpreter.Lib.Semantic.Nodes.Expressions.AccessExpressions +namespace Interpreter.Lib.IR.Ast.Nodes.Expressions.AccessExpressions { public class IndexAccess : AccessExpression { diff --git a/Interpreter.Lib/Semantic/Nodes/Expressions/AssignmentExpression.cs b/Interpreter.Lib/IR/Ast/Nodes/Expressions/AssignmentExpression.cs similarity index 93% rename from Interpreter.Lib/Semantic/Nodes/Expressions/AssignmentExpression.cs rename to Interpreter.Lib/IR/Ast/Nodes/Expressions/AssignmentExpression.cs index 8de06831..214b25da 100644 --- a/Interpreter.Lib/Semantic/Nodes/Expressions/AssignmentExpression.cs +++ b/Interpreter.Lib/IR/Ast/Nodes/Expressions/AssignmentExpression.cs @@ -1,17 +1,16 @@ using System; using System.Collections.Generic; using System.Linq; -using Interpreter.Lib.IR.Instructions; -using Interpreter.Lib.Semantic.Exceptions; -using Interpreter.Lib.Semantic.Nodes.Declarations; -using Interpreter.Lib.Semantic.Nodes.Expressions.AccessExpressions; -using Interpreter.Lib.Semantic.Symbols; -using Interpreter.Lib.Semantic.Types; -using Interpreter.Lib.Semantic.Utils; -using Interpreter.Lib.VM.Values; -using Type = Interpreter.Lib.Semantic.Types.Type; - -namespace Interpreter.Lib.Semantic.Nodes.Expressions +using Interpreter.Lib.BackEnd.Instructions; +using Interpreter.Lib.BackEnd.Values; +using Interpreter.Lib.IR.Ast.Nodes.Declarations; +using Interpreter.Lib.IR.Ast.Nodes.Expressions.AccessExpressions; +using Interpreter.Lib.IR.CheckSemantics.Exceptions; +using Interpreter.Lib.IR.CheckSemantics.Types; +using Interpreter.Lib.IR.CheckSemantics.Variables.Symbols; +using Type = Interpreter.Lib.IR.CheckSemantics.Types.Type; + +namespace Interpreter.Lib.IR.Ast.Nodes.Expressions { public class AssignmentExpression : Expression { diff --git a/Interpreter.Lib/Semantic/Nodes/Expressions/BinaryExpression.cs b/Interpreter.Lib/IR/Ast/Nodes/Expressions/BinaryExpression.cs similarity index 94% rename from Interpreter.Lib/Semantic/Nodes/Expressions/BinaryExpression.cs rename to Interpreter.Lib/IR/Ast/Nodes/Expressions/BinaryExpression.cs index d84372b9..d727d508 100644 --- a/Interpreter.Lib/Semantic/Nodes/Expressions/BinaryExpression.cs +++ b/Interpreter.Lib/IR/Ast/Nodes/Expressions/BinaryExpression.cs @@ -1,16 +1,15 @@ using System; using System.Collections.Generic; using System.Linq; -using Interpreter.Lib.IR.Instructions; -using Interpreter.Lib.Semantic.Exceptions; -using Interpreter.Lib.Semantic.Nodes.Expressions.AccessExpressions; -using Interpreter.Lib.Semantic.Nodes.Expressions.PrimaryExpressions; -using Interpreter.Lib.Semantic.Types; -using Interpreter.Lib.Semantic.Utils; -using Interpreter.Lib.VM.Values; -using Type = Interpreter.Lib.Semantic.Types.Type; - -namespace Interpreter.Lib.Semantic.Nodes.Expressions +using Interpreter.Lib.BackEnd.Instructions; +using Interpreter.Lib.BackEnd.Values; +using Interpreter.Lib.IR.Ast.Nodes.Expressions.AccessExpressions; +using Interpreter.Lib.IR.Ast.Nodes.Expressions.PrimaryExpressions; +using Interpreter.Lib.IR.CheckSemantics.Exceptions; +using Interpreter.Lib.IR.CheckSemantics.Types; +using Type = Interpreter.Lib.IR.CheckSemantics.Types.Type; + +namespace Interpreter.Lib.IR.Ast.Nodes.Expressions { public class BinaryExpression : Expression { diff --git a/Interpreter.Lib/Semantic/Nodes/Expressions/CallExpression.cs b/Interpreter.Lib/IR/Ast/Nodes/Expressions/CallExpression.cs similarity index 92% rename from Interpreter.Lib/Semantic/Nodes/Expressions/CallExpression.cs rename to Interpreter.Lib/IR/Ast/Nodes/Expressions/CallExpression.cs index 53044b6a..23d17b08 100644 --- a/Interpreter.Lib/Semantic/Nodes/Expressions/CallExpression.cs +++ b/Interpreter.Lib/IR/Ast/Nodes/Expressions/CallExpression.cs @@ -1,17 +1,17 @@ using System; using System.Collections.Generic; using System.Linq; -using Interpreter.Lib.IR.Instructions; -using Interpreter.Lib.Semantic.Exceptions; -using Interpreter.Lib.Semantic.Nodes.Expressions.AccessExpressions; -using Interpreter.Lib.Semantic.Nodes.Expressions.PrimaryExpressions; -using Interpreter.Lib.Semantic.Nodes.Statements; -using Interpreter.Lib.Semantic.Symbols; -using Interpreter.Lib.Semantic.Utils; -using Interpreter.Lib.VM.Values; -using Type = Interpreter.Lib.Semantic.Types.Type; - -namespace Interpreter.Lib.Semantic.Nodes.Expressions +using Interpreter.Lib.BackEnd.Instructions; +using Interpreter.Lib.BackEnd.Values; +using Interpreter.Lib.IR.Ast.Nodes.Expressions.AccessExpressions; +using Interpreter.Lib.IR.Ast.Nodes.Expressions.PrimaryExpressions; +using Interpreter.Lib.IR.Ast.Nodes.Statements; +using Interpreter.Lib.IR.CheckSemantics.Exceptions; +using Interpreter.Lib.IR.CheckSemantics.Types; +using Interpreter.Lib.IR.CheckSemantics.Variables.Symbols; +using Type = Interpreter.Lib.IR.CheckSemantics.Types.Type; + +namespace Interpreter.Lib.IR.Ast.Nodes.Expressions { public class CallExpression : Expression { diff --git a/Interpreter.Lib/Semantic/Nodes/Expressions/CastAsExpression.cs b/Interpreter.Lib/IR/Ast/Nodes/Expressions/CastAsExpression.cs similarity index 84% rename from Interpreter.Lib/Semantic/Nodes/Expressions/CastAsExpression.cs rename to Interpreter.Lib/IR/Ast/Nodes/Expressions/CastAsExpression.cs index 1a49870b..b2b7a433 100644 --- a/Interpreter.Lib/Semantic/Nodes/Expressions/CastAsExpression.cs +++ b/Interpreter.Lib/IR/Ast/Nodes/Expressions/CastAsExpression.cs @@ -1,12 +1,11 @@ using System.Collections.Generic; using System.Linq; -using Interpreter.Lib.IR.Instructions; -using Interpreter.Lib.Semantic.Nodes.Expressions.PrimaryExpressions; -using Interpreter.Lib.Semantic.Types; -using Interpreter.Lib.Semantic.Utils; -using Interpreter.Lib.VM.Values; +using Interpreter.Lib.BackEnd.Instructions; +using Interpreter.Lib.BackEnd.Values; +using Interpreter.Lib.IR.Ast.Nodes.Expressions.PrimaryExpressions; +using Interpreter.Lib.IR.CheckSemantics.Types; -namespace Interpreter.Lib.Semantic.Nodes.Expressions +namespace Interpreter.Lib.IR.Ast.Nodes.Expressions { public class CastAsExpression : Expression { diff --git a/Interpreter.Lib/Semantic/Nodes/Expressions/ComplexLiterals/ArrayLiteral.cs b/Interpreter.Lib/IR/Ast/Nodes/Expressions/ComplexLiterals/ArrayLiteral.cs similarity index 87% rename from Interpreter.Lib/Semantic/Nodes/Expressions/ComplexLiterals/ArrayLiteral.cs rename to Interpreter.Lib/IR/Ast/Nodes/Expressions/ComplexLiterals/ArrayLiteral.cs index 149fc5ef..d9cc81d6 100644 --- a/Interpreter.Lib/Semantic/Nodes/Expressions/ComplexLiterals/ArrayLiteral.cs +++ b/Interpreter.Lib/IR/Ast/Nodes/Expressions/ComplexLiterals/ArrayLiteral.cs @@ -1,13 +1,12 @@ using System.Collections.Generic; using System.Linq; -using Interpreter.Lib.IR.Instructions; -using Interpreter.Lib.Semantic.Exceptions; -using Interpreter.Lib.Semantic.Nodes.Expressions.PrimaryExpressions; -using Interpreter.Lib.Semantic.Types; -using Interpreter.Lib.Semantic.Utils; -using Interpreter.Lib.VM.Values; +using Interpreter.Lib.BackEnd.Instructions; +using Interpreter.Lib.BackEnd.Values; +using Interpreter.Lib.IR.Ast.Nodes.Expressions.PrimaryExpressions; +using Interpreter.Lib.IR.CheckSemantics.Exceptions; +using Interpreter.Lib.IR.CheckSemantics.Types; -namespace Interpreter.Lib.Semantic.Nodes.Expressions.ComplexLiterals +namespace Interpreter.Lib.IR.Ast.Nodes.Expressions.ComplexLiterals { public class ArrayLiteral : Expression { diff --git a/Interpreter.Lib/Semantic/Nodes/Expressions/ComplexLiterals/ObjectLiteral.cs b/Interpreter.Lib/IR/Ast/Nodes/Expressions/ComplexLiterals/ObjectLiteral.cs similarity index 89% rename from Interpreter.Lib/Semantic/Nodes/Expressions/ComplexLiterals/ObjectLiteral.cs rename to Interpreter.Lib/IR/Ast/Nodes/Expressions/ComplexLiterals/ObjectLiteral.cs index 57877015..6a58e1bc 100644 --- a/Interpreter.Lib/Semantic/Nodes/Expressions/ComplexLiterals/ObjectLiteral.cs +++ b/Interpreter.Lib/IR/Ast/Nodes/Expressions/ComplexLiterals/ObjectLiteral.cs @@ -1,13 +1,13 @@ using System.Collections.Generic; using System.Linq; -using Interpreter.Lib.IR.Instructions; -using Interpreter.Lib.Semantic.Nodes.Declarations; -using Interpreter.Lib.Semantic.Nodes.Expressions.PrimaryExpressions; -using Interpreter.Lib.Semantic.Symbols; -using Interpreter.Lib.Semantic.Types; -using Interpreter.Lib.VM.Values; +using Interpreter.Lib.BackEnd.Instructions; +using Interpreter.Lib.BackEnd.Values; +using Interpreter.Lib.IR.Ast.Nodes.Declarations; +using Interpreter.Lib.IR.Ast.Nodes.Expressions.PrimaryExpressions; +using Interpreter.Lib.IR.CheckSemantics.Types; +using Interpreter.Lib.IR.CheckSemantics.Variables.Symbols; -namespace Interpreter.Lib.Semantic.Nodes.Expressions.ComplexLiterals +namespace Interpreter.Lib.IR.Ast.Nodes.Expressions.ComplexLiterals { public class ObjectLiteral : Expression { diff --git a/Interpreter.Lib/Semantic/Nodes/Expressions/ComplexLiterals/Property.cs b/Interpreter.Lib/IR/Ast/Nodes/Expressions/ComplexLiterals/Property.cs similarity index 84% rename from Interpreter.Lib/Semantic/Nodes/Expressions/ComplexLiterals/Property.cs rename to Interpreter.Lib/IR/Ast/Nodes/Expressions/ComplexLiterals/Property.cs index 1be999f7..d86dd5d2 100644 --- a/Interpreter.Lib/Semantic/Nodes/Expressions/ComplexLiterals/Property.cs +++ b/Interpreter.Lib/IR/Ast/Nodes/Expressions/ComplexLiterals/Property.cs @@ -1,8 +1,8 @@ using System.Collections.Generic; -using Interpreter.Lib.IR.Instructions; -using Interpreter.Lib.Semantic.Nodes.Expressions.PrimaryExpressions; +using Interpreter.Lib.BackEnd.Instructions; +using Interpreter.Lib.IR.Ast.Nodes.Expressions.PrimaryExpressions; -namespace Interpreter.Lib.Semantic.Nodes.Expressions.ComplexLiterals +namespace Interpreter.Lib.IR.Ast.Nodes.Expressions.ComplexLiterals { public class Property : Expression { diff --git a/Interpreter.Lib/Semantic/Nodes/Expressions/ConditionalExpression.cs b/Interpreter.Lib/IR/Ast/Nodes/Expressions/ConditionalExpression.cs similarity index 89% rename from Interpreter.Lib/Semantic/Nodes/Expressions/ConditionalExpression.cs rename to Interpreter.Lib/IR/Ast/Nodes/Expressions/ConditionalExpression.cs index 1947ce37..86d5a800 100644 --- a/Interpreter.Lib/Semantic/Nodes/Expressions/ConditionalExpression.cs +++ b/Interpreter.Lib/IR/Ast/Nodes/Expressions/ConditionalExpression.cs @@ -1,13 +1,12 @@ using System.Collections.Generic; using System.Linq; -using Interpreter.Lib.IR.Instructions; -using Interpreter.Lib.Semantic.Exceptions; -using Interpreter.Lib.Semantic.Nodes.Expressions.PrimaryExpressions; -using Interpreter.Lib.Semantic.Types; -using Interpreter.Lib.Semantic.Utils; -using Interpreter.Lib.VM.Values; +using Interpreter.Lib.BackEnd.Instructions; +using Interpreter.Lib.BackEnd.Values; +using Interpreter.Lib.IR.Ast.Nodes.Expressions.PrimaryExpressions; +using Interpreter.Lib.IR.CheckSemantics.Exceptions; +using Interpreter.Lib.IR.CheckSemantics.Types; -namespace Interpreter.Lib.Semantic.Nodes.Expressions +namespace Interpreter.Lib.IR.Ast.Nodes.Expressions { public class ConditionalExpression : Expression { diff --git a/Interpreter.Lib/Semantic/Nodes/Expressions/Expression.cs b/Interpreter.Lib/IR/Ast/Nodes/Expressions/Expression.cs similarity index 78% rename from Interpreter.Lib/Semantic/Nodes/Expressions/Expression.cs rename to Interpreter.Lib/IR/Ast/Nodes/Expressions/Expression.cs index ff44b0c7..a2e6b8a8 100644 --- a/Interpreter.Lib/Semantic/Nodes/Expressions/Expression.cs +++ b/Interpreter.Lib/IR/Ast/Nodes/Expressions/Expression.cs @@ -1,8 +1,8 @@ using System.Collections.Generic; using System.Linq; -using Interpreter.Lib.IR.Instructions; +using Interpreter.Lib.BackEnd.Instructions; -namespace Interpreter.Lib.Semantic.Nodes.Expressions +namespace Interpreter.Lib.IR.Ast.Nodes.Expressions { public abstract class Expression : AbstractSyntaxTreeNode { diff --git a/Interpreter.Lib/Semantic/Nodes/Expressions/MemberExpression.cs b/Interpreter.Lib/IR/Ast/Nodes/Expressions/MemberExpression.cs similarity index 82% rename from Interpreter.Lib/Semantic/Nodes/Expressions/MemberExpression.cs rename to Interpreter.Lib/IR/Ast/Nodes/Expressions/MemberExpression.cs index 31208752..7f1eac93 100644 --- a/Interpreter.Lib/Semantic/Nodes/Expressions/MemberExpression.cs +++ b/Interpreter.Lib/IR/Ast/Nodes/Expressions/MemberExpression.cs @@ -1,12 +1,12 @@ using System.Collections.Generic; -using Interpreter.Lib.IR.Instructions; -using Interpreter.Lib.Semantic.Exceptions; -using Interpreter.Lib.Semantic.Nodes.Expressions.AccessExpressions; -using Interpreter.Lib.Semantic.Nodes.Expressions.PrimaryExpressions; -using Interpreter.Lib.Semantic.Symbols; -using Interpreter.Lib.Semantic.Types; +using Interpreter.Lib.BackEnd.Instructions; +using Interpreter.Lib.IR.Ast.Nodes.Expressions.AccessExpressions; +using Interpreter.Lib.IR.Ast.Nodes.Expressions.PrimaryExpressions; +using Interpreter.Lib.IR.CheckSemantics.Exceptions; +using Interpreter.Lib.IR.CheckSemantics.Types; +using Interpreter.Lib.IR.CheckSemantics.Variables.Symbols; -namespace Interpreter.Lib.Semantic.Nodes.Expressions +namespace Interpreter.Lib.IR.Ast.Nodes.Expressions { public class MemberExpression : Expression { diff --git a/Interpreter.Lib/Semantic/Nodes/Expressions/PrimaryExpressions/IdentifierReference.cs b/Interpreter.Lib/IR/Ast/Nodes/Expressions/PrimaryExpressions/IdentifierReference.cs similarity index 69% rename from Interpreter.Lib/Semantic/Nodes/Expressions/PrimaryExpressions/IdentifierReference.cs rename to Interpreter.Lib/IR/Ast/Nodes/Expressions/PrimaryExpressions/IdentifierReference.cs index 62035388..74cd8ed8 100644 --- a/Interpreter.Lib/Semantic/Nodes/Expressions/PrimaryExpressions/IdentifierReference.cs +++ b/Interpreter.Lib/IR/Ast/Nodes/Expressions/PrimaryExpressions/IdentifierReference.cs @@ -1,10 +1,10 @@ -using Interpreter.Lib.Semantic.Exceptions; -using Interpreter.Lib.Semantic.Nodes.Expressions.AccessExpressions; -using Interpreter.Lib.Semantic.Symbols; -using Interpreter.Lib.VM.Values; -using Type = Interpreter.Lib.Semantic.Types.Type; +using Interpreter.Lib.BackEnd.Values; +using Interpreter.Lib.IR.Ast.Nodes.Expressions.AccessExpressions; +using Interpreter.Lib.IR.CheckSemantics.Exceptions; +using Interpreter.Lib.IR.CheckSemantics.Variables.Symbols; +using Type = Interpreter.Lib.IR.CheckSemantics.Types.Type; -namespace Interpreter.Lib.Semantic.Nodes.Expressions.PrimaryExpressions +namespace Interpreter.Lib.IR.Ast.Nodes.Expressions.PrimaryExpressions { public class IdentifierReference : PrimaryExpression { diff --git a/Interpreter.Lib/Semantic/Nodes/Expressions/PrimaryExpressions/Literal.cs b/Interpreter.Lib/IR/Ast/Nodes/Expressions/PrimaryExpressions/Literal.cs similarity index 80% rename from Interpreter.Lib/Semantic/Nodes/Expressions/PrimaryExpressions/Literal.cs rename to Interpreter.Lib/IR/Ast/Nodes/Expressions/PrimaryExpressions/Literal.cs index ed4acb00..037aa829 100644 --- a/Interpreter.Lib/Semantic/Nodes/Expressions/PrimaryExpressions/Literal.cs +++ b/Interpreter.Lib/IR/Ast/Nodes/Expressions/PrimaryExpressions/Literal.cs @@ -1,8 +1,8 @@ +using Interpreter.Lib.BackEnd.Values; using Interpreter.Lib.FrontEnd.GetTokens.Impl; -using Interpreter.Lib.VM.Values; -using Type = Interpreter.Lib.Semantic.Types.Type; +using Type = Interpreter.Lib.IR.CheckSemantics.Types.Type; -namespace Interpreter.Lib.Semantic.Nodes.Expressions.PrimaryExpressions +namespace Interpreter.Lib.IR.Ast.Nodes.Expressions.PrimaryExpressions { public class Literal : PrimaryExpression { diff --git a/Interpreter.Lib/Semantic/Nodes/Expressions/PrimaryExpressions/PrimaryExpression.cs b/Interpreter.Lib/IR/Ast/Nodes/Expressions/PrimaryExpressions/PrimaryExpression.cs similarity index 75% rename from Interpreter.Lib/Semantic/Nodes/Expressions/PrimaryExpressions/PrimaryExpression.cs rename to Interpreter.Lib/IR/Ast/Nodes/Expressions/PrimaryExpressions/PrimaryExpression.cs index 965e3433..59531d7e 100644 --- a/Interpreter.Lib/Semantic/Nodes/Expressions/PrimaryExpressions/PrimaryExpression.cs +++ b/Interpreter.Lib/IR/Ast/Nodes/Expressions/PrimaryExpressions/PrimaryExpression.cs @@ -1,8 +1,8 @@ using System.Collections.Generic; -using Interpreter.Lib.IR.Instructions; -using Interpreter.Lib.VM.Values; +using Interpreter.Lib.BackEnd.Instructions; +using Interpreter.Lib.BackEnd.Values; -namespace Interpreter.Lib.Semantic.Nodes.Expressions.PrimaryExpressions +namespace Interpreter.Lib.IR.Ast.Nodes.Expressions.PrimaryExpressions { public abstract class PrimaryExpression : Expression { diff --git a/Interpreter.Lib/Semantic/Nodes/Expressions/UnaryExpression.cs b/Interpreter.Lib/IR/Ast/Nodes/Expressions/UnaryExpression.cs similarity index 87% rename from Interpreter.Lib/Semantic/Nodes/Expressions/UnaryExpression.cs rename to Interpreter.Lib/IR/Ast/Nodes/Expressions/UnaryExpression.cs index 843b4698..f5530864 100644 --- a/Interpreter.Lib/Semantic/Nodes/Expressions/UnaryExpression.cs +++ b/Interpreter.Lib/IR/Ast/Nodes/Expressions/UnaryExpression.cs @@ -1,16 +1,15 @@ using System; using System.Collections.Generic; using System.Linq; -using Interpreter.Lib.IR.Instructions; -using Interpreter.Lib.Semantic.Exceptions; -using Interpreter.Lib.Semantic.Nodes.Expressions.AccessExpressions; -using Interpreter.Lib.Semantic.Nodes.Expressions.PrimaryExpressions; -using Interpreter.Lib.Semantic.Types; -using Interpreter.Lib.Semantic.Utils; -using Interpreter.Lib.VM.Values; -using Type = Interpreter.Lib.Semantic.Types.Type; +using Interpreter.Lib.BackEnd.Instructions; +using Interpreter.Lib.BackEnd.Values; +using Interpreter.Lib.IR.Ast.Nodes.Expressions.AccessExpressions; +using Interpreter.Lib.IR.Ast.Nodes.Expressions.PrimaryExpressions; +using Interpreter.Lib.IR.CheckSemantics.Exceptions; +using Interpreter.Lib.IR.CheckSemantics.Types; +using Type = Interpreter.Lib.IR.CheckSemantics.Types.Type; -namespace Interpreter.Lib.Semantic.Nodes.Expressions +namespace Interpreter.Lib.IR.Ast.Nodes.Expressions { public class UnaryExpression : Expression { diff --git a/Interpreter.Lib/Semantic/Nodes/ScriptBody.cs b/Interpreter.Lib/IR/Ast/Nodes/ScriptBody.cs similarity index 93% rename from Interpreter.Lib/Semantic/Nodes/ScriptBody.cs rename to Interpreter.Lib/IR/Ast/Nodes/ScriptBody.cs index 6c8a294e..30b8d3f1 100644 --- a/Interpreter.Lib/Semantic/Nodes/ScriptBody.cs +++ b/Interpreter.Lib/IR/Ast/Nodes/ScriptBody.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace Interpreter.Lib.Semantic.Nodes +namespace Interpreter.Lib.IR.Ast.Nodes { public class ScriptBody : AbstractSyntaxTreeNode { diff --git a/Interpreter.Lib/Semantic/Nodes/StatementListItem.cs b/Interpreter.Lib/IR/Ast/Nodes/StatementListItem.cs similarity index 82% rename from Interpreter.Lib/Semantic/Nodes/StatementListItem.cs rename to Interpreter.Lib/IR/Ast/Nodes/StatementListItem.cs index 57c01e60..ae81620f 100644 --- a/Interpreter.Lib/Semantic/Nodes/StatementListItem.cs +++ b/Interpreter.Lib/IR/Ast/Nodes/StatementListItem.cs @@ -1,4 +1,4 @@ -namespace Interpreter.Lib.Semantic.Nodes +namespace Interpreter.Lib.IR.Ast.Nodes { public abstract class StatementListItem : AbstractSyntaxTreeNode { diff --git a/Interpreter.Lib/Semantic/Nodes/Statements/BlockStatement.cs b/Interpreter.Lib/IR/Ast/Nodes/Statements/BlockStatement.cs similarity index 94% rename from Interpreter.Lib/Semantic/Nodes/Statements/BlockStatement.cs rename to Interpreter.Lib/IR/Ast/Nodes/Statements/BlockStatement.cs index 839a472b..59f55af7 100644 --- a/Interpreter.Lib/Semantic/Nodes/Statements/BlockStatement.cs +++ b/Interpreter.Lib/IR/Ast/Nodes/Statements/BlockStatement.cs @@ -1,8 +1,8 @@ using System.Collections.Generic; using System.Linq; -using Interpreter.Lib.IR.Instructions; +using Interpreter.Lib.BackEnd.Instructions; -namespace Interpreter.Lib.Semantic.Nodes.Statements +namespace Interpreter.Lib.IR.Ast.Nodes.Statements { public class BlockStatement : Statement { diff --git a/Interpreter.Lib/Semantic/Nodes/Statements/BreakStatement.cs b/Interpreter.Lib/IR/Ast/Nodes/Statements/BreakStatement.cs similarity index 77% rename from Interpreter.Lib/Semantic/Nodes/Statements/BreakStatement.cs rename to Interpreter.Lib/IR/Ast/Nodes/Statements/BreakStatement.cs index 42e1eca6..25431d32 100644 --- a/Interpreter.Lib/Semantic/Nodes/Statements/BreakStatement.cs +++ b/Interpreter.Lib/IR/Ast/Nodes/Statements/BreakStatement.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; -using Interpreter.Lib.IR.Instructions; +using Interpreter.Lib.BackEnd.Instructions; -namespace Interpreter.Lib.Semantic.Nodes.Statements +namespace Interpreter.Lib.IR.Ast.Nodes.Statements { public class BreakStatement : InsideLoopStatement { diff --git a/Interpreter.Lib/Semantic/Nodes/Statements/ContinueStatement.cs b/Interpreter.Lib/IR/Ast/Nodes/Statements/ContinueStatement.cs similarity index 78% rename from Interpreter.Lib/Semantic/Nodes/Statements/ContinueStatement.cs rename to Interpreter.Lib/IR/Ast/Nodes/Statements/ContinueStatement.cs index 085ebfab..3fe7b118 100644 --- a/Interpreter.Lib/Semantic/Nodes/Statements/ContinueStatement.cs +++ b/Interpreter.Lib/IR/Ast/Nodes/Statements/ContinueStatement.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; -using Interpreter.Lib.IR.Instructions; +using Interpreter.Lib.BackEnd.Instructions; -namespace Interpreter.Lib.Semantic.Nodes.Statements +namespace Interpreter.Lib.IR.Ast.Nodes.Statements { public class ContinueStatement : InsideLoopStatement { diff --git a/Interpreter.Lib/Semantic/Nodes/Statements/ExpressionStatement.cs b/Interpreter.Lib/IR/Ast/Nodes/Statements/ExpressionStatement.cs similarity index 81% rename from Interpreter.Lib/Semantic/Nodes/Statements/ExpressionStatement.cs rename to Interpreter.Lib/IR/Ast/Nodes/Statements/ExpressionStatement.cs index 55fb8687..be9d9a04 100644 --- a/Interpreter.Lib/Semantic/Nodes/Statements/ExpressionStatement.cs +++ b/Interpreter.Lib/IR/Ast/Nodes/Statements/ExpressionStatement.cs @@ -1,8 +1,8 @@ using System.Collections.Generic; -using Interpreter.Lib.IR.Instructions; -using Interpreter.Lib.Semantic.Nodes.Expressions; +using Interpreter.Lib.BackEnd.Instructions; +using Interpreter.Lib.IR.Ast.Nodes.Expressions; -namespace Interpreter.Lib.Semantic.Nodes.Statements +namespace Interpreter.Lib.IR.Ast.Nodes.Statements { public class ExpressionStatement : Statement { diff --git a/Interpreter.Lib/Semantic/Nodes/Statements/IfStatement.cs b/Interpreter.Lib/IR/Ast/Nodes/Statements/IfStatement.cs similarity index 90% rename from Interpreter.Lib/Semantic/Nodes/Statements/IfStatement.cs rename to Interpreter.Lib/IR/Ast/Nodes/Statements/IfStatement.cs index 8e3fd45f..d2d4694f 100644 --- a/Interpreter.Lib/Semantic/Nodes/Statements/IfStatement.cs +++ b/Interpreter.Lib/IR/Ast/Nodes/Statements/IfStatement.cs @@ -1,14 +1,13 @@ using System.Collections.Generic; using System.Linq; -using Interpreter.Lib.IR.Instructions; -using Interpreter.Lib.Semantic.Exceptions; -using Interpreter.Lib.Semantic.Nodes.Expressions; -using Interpreter.Lib.Semantic.Nodes.Expressions.PrimaryExpressions; -using Interpreter.Lib.Semantic.Types; -using Interpreter.Lib.Semantic.Utils; -using Interpreter.Lib.VM.Values; - -namespace Interpreter.Lib.Semantic.Nodes.Statements +using Interpreter.Lib.BackEnd.Instructions; +using Interpreter.Lib.BackEnd.Values; +using Interpreter.Lib.IR.Ast.Nodes.Expressions; +using Interpreter.Lib.IR.Ast.Nodes.Expressions.PrimaryExpressions; +using Interpreter.Lib.IR.CheckSemantics.Exceptions; +using Interpreter.Lib.IR.CheckSemantics.Types; + +namespace Interpreter.Lib.IR.Ast.Nodes.Statements { public class IfStatement : Statement { diff --git a/Interpreter.Lib/Semantic/Nodes/Statements/InsideLoopStatement.cs b/Interpreter.Lib/IR/Ast/Nodes/Statements/InsideLoopStatement.cs similarity index 79% rename from Interpreter.Lib/Semantic/Nodes/Statements/InsideLoopStatement.cs rename to Interpreter.Lib/IR/Ast/Nodes/Statements/InsideLoopStatement.cs index fdc7ce39..131ac296 100644 --- a/Interpreter.Lib/Semantic/Nodes/Statements/InsideLoopStatement.cs +++ b/Interpreter.Lib/IR/Ast/Nodes/Statements/InsideLoopStatement.cs @@ -1,8 +1,8 @@ using System.Collections.Generic; -using Interpreter.Lib.Semantic.Exceptions; -using Interpreter.Lib.Semantic.Types; +using Interpreter.Lib.IR.CheckSemantics.Exceptions; +using Interpreter.Lib.IR.CheckSemantics.Types; -namespace Interpreter.Lib.Semantic.Nodes.Statements +namespace Interpreter.Lib.IR.Ast.Nodes.Statements { public abstract class InsideLoopStatement : Statement { diff --git a/Interpreter.Lib/Semantic/Nodes/Statements/ReturnStatement.cs b/Interpreter.Lib/IR/Ast/Nodes/Statements/ReturnStatement.cs similarity index 84% rename from Interpreter.Lib/Semantic/Nodes/Statements/ReturnStatement.cs rename to Interpreter.Lib/IR/Ast/Nodes/Statements/ReturnStatement.cs index 58c9e190..c2f5dae7 100644 --- a/Interpreter.Lib/Semantic/Nodes/Statements/ReturnStatement.cs +++ b/Interpreter.Lib/IR/Ast/Nodes/Statements/ReturnStatement.cs @@ -1,16 +1,15 @@ using System.Collections.Generic; using System.Linq; -using Interpreter.Lib.IR.Instructions; -using Interpreter.Lib.Semantic.Exceptions; -using Interpreter.Lib.Semantic.Nodes.Declarations; -using Interpreter.Lib.Semantic.Nodes.Expressions; -using Interpreter.Lib.Semantic.Nodes.Expressions.PrimaryExpressions; -using Interpreter.Lib.Semantic.Symbols; -using Interpreter.Lib.Semantic.Types; -using Interpreter.Lib.Semantic.Utils; -using Interpreter.Lib.VM.Values; +using Interpreter.Lib.BackEnd.Instructions; +using Interpreter.Lib.BackEnd.Values; +using Interpreter.Lib.IR.Ast.Nodes.Declarations; +using Interpreter.Lib.IR.Ast.Nodes.Expressions; +using Interpreter.Lib.IR.Ast.Nodes.Expressions.PrimaryExpressions; +using Interpreter.Lib.IR.CheckSemantics.Exceptions; +using Interpreter.Lib.IR.CheckSemantics.Types; +using Interpreter.Lib.IR.CheckSemantics.Variables.Symbols; -namespace Interpreter.Lib.Semantic.Nodes.Statements +namespace Interpreter.Lib.IR.Ast.Nodes.Statements { public class ReturnStatement : Statement { diff --git a/Interpreter.Lib/Semantic/Nodes/Statements/Statement.cs b/Interpreter.Lib/IR/Ast/Nodes/Statements/Statement.cs similarity index 70% rename from Interpreter.Lib/Semantic/Nodes/Statements/Statement.cs rename to Interpreter.Lib/IR/Ast/Nodes/Statements/Statement.cs index ea639326..79f1bdd6 100644 --- a/Interpreter.Lib/Semantic/Nodes/Statements/Statement.cs +++ b/Interpreter.Lib/IR/Ast/Nodes/Statements/Statement.cs @@ -1,4 +1,4 @@ -namespace Interpreter.Lib.Semantic.Nodes.Statements +namespace Interpreter.Lib.IR.Ast.Nodes.Statements { public abstract class Statement : StatementListItem { diff --git a/Interpreter.Lib/Semantic/Nodes/Statements/TypeStatement.cs b/Interpreter.Lib/IR/Ast/Nodes/Statements/TypeStatement.cs similarity index 85% rename from Interpreter.Lib/Semantic/Nodes/Statements/TypeStatement.cs rename to Interpreter.Lib/IR/Ast/Nodes/Statements/TypeStatement.cs index 81da3508..937eee38 100644 --- a/Interpreter.Lib/Semantic/Nodes/Statements/TypeStatement.cs +++ b/Interpreter.Lib/IR/Ast/Nodes/Statements/TypeStatement.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; -using Interpreter.Lib.Semantic.Types; +using Interpreter.Lib.IR.CheckSemantics.Types; -namespace Interpreter.Lib.Semantic.Nodes.Statements +namespace Interpreter.Lib.IR.Ast.Nodes.Statements { public class TypeStatement : Statement { diff --git a/Interpreter.Lib/Semantic/Nodes/Statements/WhileStatement.cs b/Interpreter.Lib/IR/Ast/Nodes/Statements/WhileStatement.cs similarity index 88% rename from Interpreter.Lib/Semantic/Nodes/Statements/WhileStatement.cs rename to Interpreter.Lib/IR/Ast/Nodes/Statements/WhileStatement.cs index e82214f9..af2e4e7b 100644 --- a/Interpreter.Lib/Semantic/Nodes/Statements/WhileStatement.cs +++ b/Interpreter.Lib/IR/Ast/Nodes/Statements/WhileStatement.cs @@ -1,14 +1,13 @@ using System.Collections.Generic; using System.Linq; -using Interpreter.Lib.IR.Instructions; -using Interpreter.Lib.Semantic.Exceptions; -using Interpreter.Lib.Semantic.Nodes.Expressions; -using Interpreter.Lib.Semantic.Nodes.Expressions.PrimaryExpressions; -using Interpreter.Lib.Semantic.Types; -using Interpreter.Lib.Semantic.Utils; -using Interpreter.Lib.VM.Values; +using Interpreter.Lib.BackEnd.Instructions; +using Interpreter.Lib.BackEnd.Values; +using Interpreter.Lib.IR.Ast.Nodes.Expressions; +using Interpreter.Lib.IR.Ast.Nodes.Expressions.PrimaryExpressions; +using Interpreter.Lib.IR.CheckSemantics.Exceptions; +using Interpreter.Lib.IR.CheckSemantics.Types; -namespace Interpreter.Lib.Semantic.Nodes.Statements +namespace Interpreter.Lib.IR.Ast.Nodes.Statements { public class WhileStatement : Statement { diff --git a/Interpreter.Lib/Semantic/Exceptions/ArrayAccessException.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/ArrayAccessException.cs similarity index 75% rename from Interpreter.Lib/Semantic/Exceptions/ArrayAccessException.cs rename to Interpreter.Lib/IR/CheckSemantics/Exceptions/ArrayAccessException.cs index 6924f2d3..f1956aa7 100644 --- a/Interpreter.Lib/Semantic/Exceptions/ArrayAccessException.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/ArrayAccessException.cs @@ -1,7 +1,7 @@ using Interpreter.Lib.FrontEnd.GetTokens.Impl; -using Interpreter.Lib.Semantic.Types; +using Interpreter.Lib.IR.CheckSemantics.Types; -namespace Interpreter.Lib.Semantic.Exceptions +namespace Interpreter.Lib.IR.CheckSemantics.Exceptions { public class ArrayAccessException : SemanticException { diff --git a/Interpreter.Lib/Semantic/Exceptions/AssignmentToConst.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/AssignmentToConst.cs similarity index 67% rename from Interpreter.Lib/Semantic/Exceptions/AssignmentToConst.cs rename to Interpreter.Lib/IR/CheckSemantics/Exceptions/AssignmentToConst.cs index 9d792e1e..6d3cdba0 100644 --- a/Interpreter.Lib/Semantic/Exceptions/AssignmentToConst.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/AssignmentToConst.cs @@ -1,6 +1,6 @@ -using Interpreter.Lib.Semantic.Nodes.Expressions.PrimaryExpressions; +using Interpreter.Lib.IR.Ast.Nodes.Expressions.PrimaryExpressions; -namespace Interpreter.Lib.Semantic.Exceptions +namespace Interpreter.Lib.IR.CheckSemantics.Exceptions { public class AssignmentToConst : SemanticException { diff --git a/Interpreter.Lib/Semantic/Exceptions/CannotDefineType.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/CannotDefineType.cs similarity index 81% rename from Interpreter.Lib/Semantic/Exceptions/CannotDefineType.cs rename to Interpreter.Lib/IR/CheckSemantics/Exceptions/CannotDefineType.cs index 72d93949..c00de25a 100644 --- a/Interpreter.Lib/Semantic/Exceptions/CannotDefineType.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/CannotDefineType.cs @@ -1,6 +1,6 @@ using Interpreter.Lib.FrontEnd.GetTokens.Impl; -namespace Interpreter.Lib.Semantic.Exceptions +namespace Interpreter.Lib.IR.CheckSemantics.Exceptions { public class CannotDefineType : SemanticException { diff --git a/Interpreter.Lib/Semantic/Exceptions/ConstWithoutInitializer.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/ConstWithoutInitializer.cs similarity index 65% rename from Interpreter.Lib/Semantic/Exceptions/ConstWithoutInitializer.cs rename to Interpreter.Lib/IR/CheckSemantics/Exceptions/ConstWithoutInitializer.cs index 7733e26e..ec10ce3b 100644 --- a/Interpreter.Lib/Semantic/Exceptions/ConstWithoutInitializer.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/ConstWithoutInitializer.cs @@ -1,6 +1,6 @@ -using Interpreter.Lib.Semantic.Nodes.Expressions.PrimaryExpressions; +using Interpreter.Lib.IR.Ast.Nodes.Expressions.PrimaryExpressions; -namespace Interpreter.Lib.Semantic.Exceptions +namespace Interpreter.Lib.IR.CheckSemantics.Exceptions { public class ConstWithoutInitializer : SemanticException { diff --git a/Interpreter.Lib/Semantic/Exceptions/DeclarationAlreadyExists.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/DeclarationAlreadyExists.cs similarity index 65% rename from Interpreter.Lib/Semantic/Exceptions/DeclarationAlreadyExists.cs rename to Interpreter.Lib/IR/CheckSemantics/Exceptions/DeclarationAlreadyExists.cs index 7c7cb621..a026b6b6 100644 --- a/Interpreter.Lib/Semantic/Exceptions/DeclarationAlreadyExists.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/DeclarationAlreadyExists.cs @@ -1,6 +1,6 @@ -using Interpreter.Lib.Semantic.Nodes.Expressions.PrimaryExpressions; +using Interpreter.Lib.IR.Ast.Nodes.Expressions.PrimaryExpressions; -namespace Interpreter.Lib.Semantic.Exceptions +namespace Interpreter.Lib.IR.CheckSemantics.Exceptions { public class DeclarationAlreadyExists : SemanticException { diff --git a/Interpreter.Lib/Semantic/Exceptions/FunctionWithoutReturnStatement.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/FunctionWithoutReturnStatement.cs similarity index 86% rename from Interpreter.Lib/Semantic/Exceptions/FunctionWithoutReturnStatement.cs rename to Interpreter.Lib/IR/CheckSemantics/Exceptions/FunctionWithoutReturnStatement.cs index 286c1219..28222ae2 100644 --- a/Interpreter.Lib/Semantic/Exceptions/FunctionWithoutReturnStatement.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/FunctionWithoutReturnStatement.cs @@ -1,6 +1,6 @@ using Interpreter.Lib.FrontEnd.GetTokens.Impl; -namespace Interpreter.Lib.Semantic.Exceptions +namespace Interpreter.Lib.IR.CheckSemantics.Exceptions { public class FunctionWithoutReturnStatement : SemanticException { diff --git a/Interpreter.Lib/Semantic/Exceptions/IncompatibleTypesOfOperands.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/IncompatibleTypesOfOperands.cs similarity index 77% rename from Interpreter.Lib/Semantic/Exceptions/IncompatibleTypesOfOperands.cs rename to Interpreter.Lib/IR/CheckSemantics/Exceptions/IncompatibleTypesOfOperands.cs index 606bfd04..69c44336 100644 --- a/Interpreter.Lib/Semantic/Exceptions/IncompatibleTypesOfOperands.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/IncompatibleTypesOfOperands.cs @@ -1,7 +1,7 @@ using Interpreter.Lib.FrontEnd.GetTokens.Impl; -using Interpreter.Lib.Semantic.Types; +using Interpreter.Lib.IR.CheckSemantics.Types; -namespace Interpreter.Lib.Semantic.Exceptions +namespace Interpreter.Lib.IR.CheckSemantics.Exceptions { public class IncompatibleTypesOfOperands : SemanticException { diff --git a/Interpreter.Lib/Semantic/Exceptions/NotBooleanTestExpression.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/NotBooleanTestExpression.cs similarity index 76% rename from Interpreter.Lib/Semantic/Exceptions/NotBooleanTestExpression.cs rename to Interpreter.Lib/IR/CheckSemantics/Exceptions/NotBooleanTestExpression.cs index 175bc74e..d0678895 100644 --- a/Interpreter.Lib/Semantic/Exceptions/NotBooleanTestExpression.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/NotBooleanTestExpression.cs @@ -1,7 +1,7 @@ using Interpreter.Lib.FrontEnd.GetTokens.Impl; -using Interpreter.Lib.Semantic.Types; +using Interpreter.Lib.IR.CheckSemantics.Types; -namespace Interpreter.Lib.Semantic.Exceptions +namespace Interpreter.Lib.IR.CheckSemantics.Exceptions { public class NotBooleanTestExpression : SemanticException { diff --git a/Interpreter.Lib/Semantic/Exceptions/ObjectAccessException.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/ObjectAccessException.cs similarity index 75% rename from Interpreter.Lib/Semantic/Exceptions/ObjectAccessException.cs rename to Interpreter.Lib/IR/CheckSemantics/Exceptions/ObjectAccessException.cs index 81e55973..936eb02e 100644 --- a/Interpreter.Lib/Semantic/Exceptions/ObjectAccessException.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/ObjectAccessException.cs @@ -1,7 +1,7 @@ using Interpreter.Lib.FrontEnd.GetTokens.Impl; -using Interpreter.Lib.Semantic.Types; +using Interpreter.Lib.IR.CheckSemantics.Types; -namespace Interpreter.Lib.Semantic.Exceptions +namespace Interpreter.Lib.IR.CheckSemantics.Exceptions { public class ObjectAccessException : SemanticException { diff --git a/Interpreter.Lib/Semantic/Exceptions/OutsideOfLoop.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/OutsideOfLoop.cs similarity index 84% rename from Interpreter.Lib/Semantic/Exceptions/OutsideOfLoop.cs rename to Interpreter.Lib/IR/CheckSemantics/Exceptions/OutsideOfLoop.cs index 5eb1cdcd..52ce997c 100644 --- a/Interpreter.Lib/Semantic/Exceptions/OutsideOfLoop.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/OutsideOfLoop.cs @@ -1,6 +1,6 @@ using Interpreter.Lib.FrontEnd.GetTokens.Impl; -namespace Interpreter.Lib.Semantic.Exceptions +namespace Interpreter.Lib.IR.CheckSemantics.Exceptions { public class OutsideOfLoop : SemanticException { diff --git a/Interpreter.Lib/Semantic/Exceptions/ReturnOutsideFunction.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/ReturnOutsideFunction.cs similarity index 83% rename from Interpreter.Lib/Semantic/Exceptions/ReturnOutsideFunction.cs rename to Interpreter.Lib/IR/CheckSemantics/Exceptions/ReturnOutsideFunction.cs index e6d9ef00..d35c70d5 100644 --- a/Interpreter.Lib/Semantic/Exceptions/ReturnOutsideFunction.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/ReturnOutsideFunction.cs @@ -1,6 +1,6 @@ using Interpreter.Lib.FrontEnd.GetTokens.Impl; -namespace Interpreter.Lib.Semantic.Exceptions +namespace Interpreter.Lib.IR.CheckSemantics.Exceptions { public class ReturnOutsideFunction : SemanticException { diff --git a/Interpreter.Lib/Semantic/Exceptions/SemanticException.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/SemanticException.cs similarity index 75% rename from Interpreter.Lib/Semantic/Exceptions/SemanticException.cs rename to Interpreter.Lib/IR/CheckSemantics/Exceptions/SemanticException.cs index 34c94a87..03a422df 100644 --- a/Interpreter.Lib/Semantic/Exceptions/SemanticException.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/SemanticException.cs @@ -1,6 +1,6 @@ using System; -namespace Interpreter.Lib.Semantic.Exceptions +namespace Interpreter.Lib.IR.CheckSemantics.Exceptions { public abstract class SemanticException : Exception { diff --git a/Interpreter.Lib/Semantic/Exceptions/SymbolIsNotCallable.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/SymbolIsNotCallable.cs similarity index 83% rename from Interpreter.Lib/Semantic/Exceptions/SymbolIsNotCallable.cs rename to Interpreter.Lib/IR/CheckSemantics/Exceptions/SymbolIsNotCallable.cs index 4c805c74..d563cc13 100644 --- a/Interpreter.Lib/Semantic/Exceptions/SymbolIsNotCallable.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/SymbolIsNotCallable.cs @@ -1,6 +1,6 @@ using Interpreter.Lib.FrontEnd.GetTokens.Impl; -namespace Interpreter.Lib.Semantic.Exceptions +namespace Interpreter.Lib.IR.CheckSemantics.Exceptions { public class SymbolIsNotCallable: SemanticException { diff --git a/Interpreter.Lib/Semantic/Exceptions/UnknownIdentifierReference.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/UnknownIdentifierReference.cs similarity index 69% rename from Interpreter.Lib/Semantic/Exceptions/UnknownIdentifierReference.cs rename to Interpreter.Lib/IR/CheckSemantics/Exceptions/UnknownIdentifierReference.cs index a7d1e65a..178411c1 100644 --- a/Interpreter.Lib/Semantic/Exceptions/UnknownIdentifierReference.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/UnknownIdentifierReference.cs @@ -1,6 +1,6 @@ -using Interpreter.Lib.Semantic.Nodes.Expressions.PrimaryExpressions; +using Interpreter.Lib.IR.Ast.Nodes.Expressions.PrimaryExpressions; -namespace Interpreter.Lib.Semantic.Exceptions +namespace Interpreter.Lib.IR.CheckSemantics.Exceptions { public class UnknownIdentifierReference : SemanticException { diff --git a/Interpreter.Lib/Semantic/Exceptions/UnsupportedOperation.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/UnsupportedOperation.cs similarity index 76% rename from Interpreter.Lib/Semantic/Exceptions/UnsupportedOperation.cs rename to Interpreter.Lib/IR/CheckSemantics/Exceptions/UnsupportedOperation.cs index 06b959d7..bf1f31ea 100644 --- a/Interpreter.Lib/Semantic/Exceptions/UnsupportedOperation.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/UnsupportedOperation.cs @@ -1,7 +1,7 @@ using Interpreter.Lib.FrontEnd.GetTokens.Impl; -using Interpreter.Lib.Semantic.Types; +using Interpreter.Lib.IR.CheckSemantics.Types; -namespace Interpreter.Lib.Semantic.Exceptions +namespace Interpreter.Lib.IR.CheckSemantics.Exceptions { public class UnsupportedOperation : SemanticException { diff --git a/Interpreter.Lib/Semantic/Exceptions/WrongArrayLiteralDeclaration.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongArrayLiteralDeclaration.cs similarity index 76% rename from Interpreter.Lib/Semantic/Exceptions/WrongArrayLiteralDeclaration.cs rename to Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongArrayLiteralDeclaration.cs index 019a2fbf..b4a5d179 100644 --- a/Interpreter.Lib/Semantic/Exceptions/WrongArrayLiteralDeclaration.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongArrayLiteralDeclaration.cs @@ -1,7 +1,7 @@ using Interpreter.Lib.FrontEnd.GetTokens.Impl; -using Interpreter.Lib.Semantic.Types; +using Interpreter.Lib.IR.CheckSemantics.Types; -namespace Interpreter.Lib.Semantic.Exceptions +namespace Interpreter.Lib.IR.CheckSemantics.Exceptions { public class WrongArrayLiteralDeclaration : SemanticException { diff --git a/Interpreter.Lib/Semantic/Exceptions/WrongConditionalTypes.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongConditionalTypes.cs similarity index 79% rename from Interpreter.Lib/Semantic/Exceptions/WrongConditionalTypes.cs rename to Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongConditionalTypes.cs index a8c198b2..8bbd3f59 100644 --- a/Interpreter.Lib/Semantic/Exceptions/WrongConditionalTypes.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongConditionalTypes.cs @@ -1,7 +1,7 @@ using Interpreter.Lib.FrontEnd.GetTokens.Impl; -using Interpreter.Lib.Semantic.Types; +using Interpreter.Lib.IR.CheckSemantics.Types; -namespace Interpreter.Lib.Semantic.Exceptions +namespace Interpreter.Lib.IR.CheckSemantics.Exceptions { public class WrongConditionalTypes : SemanticException { diff --git a/Interpreter.Lib/Semantic/Exceptions/WrongNumberOfArguments.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongNumberOfArguments.cs similarity index 86% rename from Interpreter.Lib/Semantic/Exceptions/WrongNumberOfArguments.cs rename to Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongNumberOfArguments.cs index 4e3212a2..61ee9c85 100644 --- a/Interpreter.Lib/Semantic/Exceptions/WrongNumberOfArguments.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongNumberOfArguments.cs @@ -1,6 +1,6 @@ using Interpreter.Lib.FrontEnd.GetTokens.Impl; -namespace Interpreter.Lib.Semantic.Exceptions +namespace Interpreter.Lib.IR.CheckSemantics.Exceptions { public class WrongNumberOfArguments : SemanticException { diff --git a/Interpreter.Lib/Semantic/Exceptions/WrongReturnType.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongReturnType.cs similarity index 75% rename from Interpreter.Lib/Semantic/Exceptions/WrongReturnType.cs rename to Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongReturnType.cs index c69ef468..aa7034ed 100644 --- a/Interpreter.Lib/Semantic/Exceptions/WrongReturnType.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongReturnType.cs @@ -1,7 +1,7 @@ using Interpreter.Lib.FrontEnd.GetTokens.Impl; -using Interpreter.Lib.Semantic.Types; +using Interpreter.Lib.IR.CheckSemantics.Types; -namespace Interpreter.Lib.Semantic.Exceptions +namespace Interpreter.Lib.IR.CheckSemantics.Exceptions { public class WrongReturnType : SemanticException { diff --git a/Interpreter.Lib/Semantic/Exceptions/WrongTypeOfArgument.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongTypeOfArgument.cs similarity index 77% rename from Interpreter.Lib/Semantic/Exceptions/WrongTypeOfArgument.cs rename to Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongTypeOfArgument.cs index f2179284..bd571e29 100644 --- a/Interpreter.Lib/Semantic/Exceptions/WrongTypeOfArgument.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongTypeOfArgument.cs @@ -1,7 +1,7 @@ using Interpreter.Lib.FrontEnd.GetTokens.Impl; -using Interpreter.Lib.Semantic.Types; +using Interpreter.Lib.IR.CheckSemantics.Types; -namespace Interpreter.Lib.Semantic.Exceptions +namespace Interpreter.Lib.IR.CheckSemantics.Exceptions { public class WrongTypeOfArgument : SemanticException { diff --git a/Interpreter.Lib/Semantic/Types/Any.cs b/Interpreter.Lib/IR/CheckSemantics/Types/Any.cs similarity index 81% rename from Interpreter.Lib/Semantic/Types/Any.cs rename to Interpreter.Lib/IR/CheckSemantics/Types/Any.cs index a10eef4b..cefb8955 100644 --- a/Interpreter.Lib/Semantic/Types/Any.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Types/Any.cs @@ -1,4 +1,4 @@ -namespace Interpreter.Lib.Semantic.Types +namespace Interpreter.Lib.IR.CheckSemantics.Types { public class Any : Type { diff --git a/Interpreter.Lib/Semantic/Types/ArrayType.cs b/Interpreter.Lib/IR/CheckSemantics/Types/ArrayType.cs similarity index 89% rename from Interpreter.Lib/Semantic/Types/ArrayType.cs rename to Interpreter.Lib/IR/CheckSemantics/Types/ArrayType.cs index 5038a7ae..b3d8210a 100644 --- a/Interpreter.Lib/Semantic/Types/ArrayType.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Types/ArrayType.cs @@ -1,7 +1,7 @@ -using Interpreter.Lib.Semantic.Types.Visitors; +using Interpreter.Lib.IR.CheckSemantics.Types.Visitors; using Visitor.NET.Lib.Core; -namespace Interpreter.Lib.Semantic.Types +namespace Interpreter.Lib.IR.CheckSemantics.Types { public class ArrayType : Type { diff --git a/Interpreter.Lib/Semantic/Types/FunctionType.cs b/Interpreter.Lib/IR/CheckSemantics/Types/FunctionType.cs similarity index 94% rename from Interpreter.Lib/Semantic/Types/FunctionType.cs rename to Interpreter.Lib/IR/CheckSemantics/Types/FunctionType.cs index 669225c1..8989ce99 100644 --- a/Interpreter.Lib/Semantic/Types/FunctionType.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Types/FunctionType.cs @@ -2,10 +2,10 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using Interpreter.Lib.Semantic.Types.Visitors; +using Interpreter.Lib.IR.CheckSemantics.Types.Visitors; using Visitor.NET.Lib.Core; -namespace Interpreter.Lib.Semantic.Types +namespace Interpreter.Lib.IR.CheckSemantics.Types { public class FunctionType : Type { diff --git a/Interpreter.Lib/Semantic/Types/NullType.cs b/Interpreter.Lib/IR/CheckSemantics/Types/NullType.cs similarity index 86% rename from Interpreter.Lib/Semantic/Types/NullType.cs rename to Interpreter.Lib/IR/CheckSemantics/Types/NullType.cs index 2d3e3ce5..c5712b55 100644 --- a/Interpreter.Lib/Semantic/Types/NullType.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Types/NullType.cs @@ -1,4 +1,4 @@ -namespace Interpreter.Lib.Semantic.Types +namespace Interpreter.Lib.IR.CheckSemantics.Types { public class NullType : Type { diff --git a/Interpreter.Lib/Semantic/Types/NullableType.cs b/Interpreter.Lib/IR/CheckSemantics/Types/NullableType.cs similarity index 89% rename from Interpreter.Lib/Semantic/Types/NullableType.cs rename to Interpreter.Lib/IR/CheckSemantics/Types/NullableType.cs index 28d21f0b..89b1ad88 100644 --- a/Interpreter.Lib/Semantic/Types/NullableType.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Types/NullableType.cs @@ -1,7 +1,7 @@ -using Interpreter.Lib.Semantic.Types.Visitors; +using Interpreter.Lib.IR.CheckSemantics.Types.Visitors; using Visitor.NET.Lib.Core; -namespace Interpreter.Lib.Semantic.Types +namespace Interpreter.Lib.IR.CheckSemantics.Types { public class NullableType : Type { diff --git a/Interpreter.Lib/Semantic/Types/ObjectType.cs b/Interpreter.Lib/IR/CheckSemantics/Types/ObjectType.cs similarity index 95% rename from Interpreter.Lib/Semantic/Types/ObjectType.cs rename to Interpreter.Lib/IR/CheckSemantics/Types/ObjectType.cs index ff37c8aa..1f08bb81 100644 --- a/Interpreter.Lib/Semantic/Types/ObjectType.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Types/ObjectType.cs @@ -1,10 +1,10 @@ using System; using System.Collections.Generic; using System.Linq; -using Interpreter.Lib.Semantic.Types.Visitors; +using Interpreter.Lib.IR.CheckSemantics.Types.Visitors; using Visitor.NET.Lib.Core; -namespace Interpreter.Lib.Semantic.Types +namespace Interpreter.Lib.IR.CheckSemantics.Types { public class ObjectType : NullableType { diff --git a/Interpreter.Lib/Semantic/Types/Type.cs b/Interpreter.Lib/IR/CheckSemantics/Types/Type.cs similarity index 91% rename from Interpreter.Lib/Semantic/Types/Type.cs rename to Interpreter.Lib/IR/CheckSemantics/Types/Type.cs index da5924b2..74c10b5d 100644 --- a/Interpreter.Lib/Semantic/Types/Type.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Types/Type.cs @@ -1,7 +1,7 @@ -using Interpreter.Lib.Semantic.Types.Visitors; +using Interpreter.Lib.IR.CheckSemantics.Types.Visitors; using Visitor.NET.Lib.Core; -namespace Interpreter.Lib.Semantic.Types +namespace Interpreter.Lib.IR.CheckSemantics.Types { public class Type : IVisitable, diff --git a/Interpreter.Lib/Semantic/Utils/TypeUtils.cs b/Interpreter.Lib/IR/CheckSemantics/Types/TypeUtils.cs similarity index 94% rename from Interpreter.Lib/Semantic/Utils/TypeUtils.cs rename to Interpreter.Lib/IR/CheckSemantics/Types/TypeUtils.cs index 2d3f3874..75162cac 100644 --- a/Interpreter.Lib/Semantic/Utils/TypeUtils.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Types/TypeUtils.cs @@ -1,7 +1,6 @@ using System.Collections.Generic; -using Interpreter.Lib.Semantic.Types; -namespace Interpreter.Lib.Semantic.Utils +namespace Interpreter.Lib.IR.CheckSemantics.Types { public static class TypeUtils { diff --git a/Interpreter.Lib/Semantic/Types/Visitors/ObjectTypePrinter.cs b/Interpreter.Lib/IR/CheckSemantics/Types/Visitors/ObjectTypePrinter.cs similarity index 97% rename from Interpreter.Lib/Semantic/Types/Visitors/ObjectTypePrinter.cs rename to Interpreter.Lib/IR/CheckSemantics/Types/Visitors/ObjectTypePrinter.cs index 48f66105..5c55ebc1 100644 --- a/Interpreter.Lib/Semantic/Types/Visitors/ObjectTypePrinter.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Types/Visitors/ObjectTypePrinter.cs @@ -2,7 +2,7 @@ using System.Text; using Visitor.NET.Lib.Core; -namespace Interpreter.Lib.Semantic.Types.Visitors +namespace Interpreter.Lib.IR.CheckSemantics.Types.Visitors { public class ObjectTypePrinter : IVisitor, diff --git a/Interpreter.Lib/Semantic/Types/Visitors/ReferenceResolver.cs b/Interpreter.Lib/IR/CheckSemantics/Types/Visitors/ReferenceResolver.cs similarity index 97% rename from Interpreter.Lib/Semantic/Types/Visitors/ReferenceResolver.cs rename to Interpreter.Lib/IR/CheckSemantics/Types/Visitors/ReferenceResolver.cs index 6c21650e..7d50ba7e 100644 --- a/Interpreter.Lib/Semantic/Types/Visitors/ReferenceResolver.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Types/Visitors/ReferenceResolver.cs @@ -1,6 +1,6 @@ using Visitor.NET.Lib.Core; -namespace Interpreter.Lib.Semantic.Types.Visitors +namespace Interpreter.Lib.IR.CheckSemantics.Types.Visitors { public class ReferenceResolver : IVisitor, diff --git a/Interpreter.Lib/Semantic/SymbolTable.cs b/Interpreter.Lib/IR/CheckSemantics/Variables/SymbolTable.cs similarity index 89% rename from Interpreter.Lib/Semantic/SymbolTable.cs rename to Interpreter.Lib/IR/CheckSemantics/Variables/SymbolTable.cs index cac4dbb1..8b79e860 100644 --- a/Interpreter.Lib/Semantic/SymbolTable.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Variables/SymbolTable.cs @@ -1,8 +1,8 @@ using System.Collections.Generic; -using Interpreter.Lib.Semantic.Symbols; -using Type = Interpreter.Lib.Semantic.Types.Type; +using Interpreter.Lib.IR.CheckSemantics.Variables.Symbols; +using Type = Interpreter.Lib.IR.CheckSemantics.Types.Type; -namespace Interpreter.Lib.Semantic +namespace Interpreter.Lib.IR.CheckSemantics.Variables { public class SymbolTable { diff --git a/Interpreter.Lib/Semantic/Utils/SymbolTableUtils.cs b/Interpreter.Lib/IR/CheckSemantics/Variables/SymbolTableUtils.cs similarity index 84% rename from Interpreter.Lib/Semantic/Utils/SymbolTableUtils.cs rename to Interpreter.Lib/IR/CheckSemantics/Variables/SymbolTableUtils.cs index 63f1f77b..9a87f95c 100644 --- a/Interpreter.Lib/Semantic/Utils/SymbolTableUtils.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Variables/SymbolTableUtils.cs @@ -1,12 +1,12 @@ using System.Collections.Generic; using Interpreter.Lib.FrontEnd.GetTokens.Impl; -using Interpreter.Lib.Semantic.Nodes; -using Interpreter.Lib.Semantic.Nodes.Declarations; -using Interpreter.Lib.Semantic.Nodes.Statements; -using Interpreter.Lib.Semantic.Symbols; -using Interpreter.Lib.Semantic.Types; +using Interpreter.Lib.IR.Ast.Nodes; +using Interpreter.Lib.IR.Ast.Nodes.Declarations; +using Interpreter.Lib.IR.Ast.Nodes.Statements; +using Interpreter.Lib.IR.CheckSemantics.Types; +using Interpreter.Lib.IR.CheckSemantics.Variables.Symbols; -namespace Interpreter.Lib.Semantic.Utils +namespace Interpreter.Lib.IR.CheckSemantics.Variables { public static class SymbolTableUtils { diff --git a/Interpreter.Lib/Semantic/Symbols/FunctionSymbol.cs b/Interpreter.Lib/IR/CheckSemantics/Variables/Symbols/FunctionSymbol.cs similarity index 81% rename from Interpreter.Lib/Semantic/Symbols/FunctionSymbol.cs rename to Interpreter.Lib/IR/CheckSemantics/Variables/Symbols/FunctionSymbol.cs index 9dbe9e83..ad794443 100644 --- a/Interpreter.Lib/Semantic/Symbols/FunctionSymbol.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Variables/Symbols/FunctionSymbol.cs @@ -1,10 +1,10 @@ using System.Collections.Generic; using System.Text; -using Interpreter.Lib.Semantic.Nodes.Declarations; -using Interpreter.Lib.Semantic.Types; -using Interpreter.Lib.VM; +using Interpreter.Lib.BackEnd; +using Interpreter.Lib.IR.Ast.Nodes.Declarations; +using Interpreter.Lib.IR.CheckSemantics.Types; -namespace Interpreter.Lib.Semantic.Symbols +namespace Interpreter.Lib.IR.CheckSemantics.Variables.Symbols { public class FunctionSymbol : Symbol { diff --git a/Interpreter.Lib/Semantic/Symbols/ObjectSymbol.cs b/Interpreter.Lib/IR/CheckSemantics/Variables/Symbols/ObjectSymbol.cs similarity index 86% rename from Interpreter.Lib/Semantic/Symbols/ObjectSymbol.cs rename to Interpreter.Lib/IR/CheckSemantics/Variables/Symbols/ObjectSymbol.cs index 04dbd21b..a0646feb 100644 --- a/Interpreter.Lib/Semantic/Symbols/ObjectSymbol.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Variables/Symbols/ObjectSymbol.cs @@ -1,6 +1,6 @@ -using Interpreter.Lib.Semantic.Types; +using Interpreter.Lib.IR.CheckSemantics.Types; -namespace Interpreter.Lib.Semantic.Symbols +namespace Interpreter.Lib.IR.CheckSemantics.Variables.Symbols { public class ObjectSymbol : VariableSymbol { diff --git a/Interpreter.Lib/Semantic/Symbols/Symbol.cs b/Interpreter.Lib/IR/CheckSemantics/Variables/Symbols/Symbol.cs similarity index 79% rename from Interpreter.Lib/Semantic/Symbols/Symbol.cs rename to Interpreter.Lib/IR/CheckSemantics/Variables/Symbols/Symbol.cs index 3f696fbf..2fa06b36 100644 --- a/Interpreter.Lib/Semantic/Symbols/Symbol.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Variables/Symbols/Symbol.cs @@ -1,4 +1,4 @@ -namespace Interpreter.Lib.Semantic.Symbols +namespace Interpreter.Lib.IR.CheckSemantics.Variables.Symbols { public abstract class Symbol { diff --git a/Interpreter.Lib/Semantic/Symbols/VariableSymbol.cs b/Interpreter.Lib/IR/CheckSemantics/Variables/Symbols/VariableSymbol.cs similarity index 74% rename from Interpreter.Lib/Semantic/Symbols/VariableSymbol.cs rename to Interpreter.Lib/IR/CheckSemantics/Variables/Symbols/VariableSymbol.cs index 973ab198..98b4c42b 100644 --- a/Interpreter.Lib/Semantic/Symbols/VariableSymbol.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Variables/Symbols/VariableSymbol.cs @@ -1,6 +1,6 @@ -using Type = Interpreter.Lib.Semantic.Types.Type; +using Type = Interpreter.Lib.IR.CheckSemantics.Types.Type; -namespace Interpreter.Lib.Semantic.Symbols +namespace Interpreter.Lib.IR.CheckSemantics.Variables.Symbols { public class VariableSymbol : Symbol { diff --git a/Interpreter.Tests/Unit/AstNodeTests.cs b/Interpreter.Tests/Unit/AstNodeTests.cs index d7c18874..0f889967 100644 --- a/Interpreter.Tests/Unit/AstNodeTests.cs +++ b/Interpreter.Tests/Unit/AstNodeTests.cs @@ -1,9 +1,9 @@ using System.Collections.Generic; -using Interpreter.Lib.Semantic.Nodes; -using Interpreter.Lib.Semantic.Nodes.Declarations; -using Interpreter.Lib.Semantic.Nodes.Statements; -using Interpreter.Lib.Semantic.Symbols; -using Interpreter.Lib.Semantic.Types; +using Interpreter.Lib.IR.Ast.Nodes; +using Interpreter.Lib.IR.Ast.Nodes.Declarations; +using Interpreter.Lib.IR.Ast.Nodes.Statements; +using Interpreter.Lib.IR.CheckSemantics.Types; +using Interpreter.Lib.IR.CheckSemantics.Variables.Symbols; using Moq; using Xunit; diff --git a/Interpreter.Tests/Unit/ExpressionTests.cs b/Interpreter.Tests/Unit/ExpressionTests.cs index d921d847..2cf95d21 100644 --- a/Interpreter.Tests/Unit/ExpressionTests.cs +++ b/Interpreter.Tests/Unit/ExpressionTests.cs @@ -1,6 +1,6 @@ -using Interpreter.Lib.Semantic.Nodes.Expressions; -using Interpreter.Lib.Semantic.Nodes.Expressions.PrimaryExpressions; -using Interpreter.Lib.Semantic.Types; +using Interpreter.Lib.IR.Ast.Nodes.Expressions; +using Interpreter.Lib.IR.Ast.Nodes.Expressions.PrimaryExpressions; +using Interpreter.Lib.IR.CheckSemantics.Types; using Xunit; namespace Interpreter.Tests.Unit diff --git a/Interpreter.Tests/Unit/SymbolTableTests.cs b/Interpreter.Tests/Unit/SymbolTableTests.cs index 5e5fa004..3a441731 100644 --- a/Interpreter.Tests/Unit/SymbolTableTests.cs +++ b/Interpreter.Tests/Unit/SymbolTableTests.cs @@ -1,9 +1,9 @@ using System; using System.Collections.Generic; using System.Linq; -using Interpreter.Lib.Semantic; -using Interpreter.Lib.Semantic.Nodes; -using Interpreter.Lib.Semantic.Symbols; +using Interpreter.Lib.IR.Ast.Nodes; +using Interpreter.Lib.IR.CheckSemantics.Variables; +using Interpreter.Lib.IR.CheckSemantics.Variables.Symbols; using Moq; using Xunit; diff --git a/Interpreter.Tests/Unit/TypeTests.cs b/Interpreter.Tests/Unit/TypeTests.cs index 931a23a6..c18bfe66 100644 --- a/Interpreter.Tests/Unit/TypeTests.cs +++ b/Interpreter.Tests/Unit/TypeTests.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; -using Interpreter.Lib.Semantic.Types; -using Interpreter.Lib.Semantic.Utils; +using Interpreter.Lib.IR.CheckSemantics.Types; using Xunit; namespace Interpreter.Tests.Unit diff --git a/Interpreter/Services/Executor/Impl/Executor.cs b/Interpreter/Services/Executor/Impl/Executor.cs index 399f5c2f..53ac4d90 100644 --- a/Interpreter/Services/Executor/Impl/Executor.cs +++ b/Interpreter/Services/Executor/Impl/Executor.cs @@ -1,8 +1,8 @@ using System; +using Interpreter.Lib.BackEnd; using Interpreter.Lib.FrontEnd.GetTokens; using Interpreter.Lib.FrontEnd.TopDownParse; -using Interpreter.Lib.Semantic.Exceptions; -using Interpreter.Lib.VM; +using Interpreter.Lib.IR.CheckSemantics.Exceptions; using Interpreter.Services.Parsing; using Microsoft.Extensions.Options; diff --git a/Interpreter/Services/Parsing/IParsingService.cs b/Interpreter/Services/Parsing/IParsingService.cs index 75ad0138..312e5b70 100644 --- a/Interpreter/Services/Parsing/IParsingService.cs +++ b/Interpreter/Services/Parsing/IParsingService.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.Contracts; +using Interpreter.Lib.IR.Ast; namespace Interpreter.Services.Parsing { diff --git a/Interpreter/Services/Parsing/Impl/ParsingService.cs b/Interpreter/Services/Parsing/Impl/ParsingService.cs index 4135a464..0f105154 100644 --- a/Interpreter/Services/Parsing/Impl/ParsingService.cs +++ b/Interpreter/Services/Parsing/Impl/ParsingService.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.Contracts; +using Interpreter.Lib.IR.Ast; using Interpreter.Services.Providers; namespace Interpreter.Services.Parsing.Impl diff --git a/Interpreter/Services/Providers/Impl/ParserProvider/LoggingAbstractSyntaxTree.cs b/Interpreter/Services/Providers/Impl/ParserProvider/LoggingAbstractSyntaxTree.cs index 87065525..b6aa20d6 100644 --- a/Interpreter/Services/Providers/Impl/ParserProvider/LoggingAbstractSyntaxTree.cs +++ b/Interpreter/Services/Providers/Impl/ParserProvider/LoggingAbstractSyntaxTree.cs @@ -1,8 +1,8 @@ using System.Collections.Generic; using System.IO; using System.Linq; -using Interpreter.Lib.Contracts; -using Interpreter.Lib.IR.Instructions; +using Interpreter.Lib.BackEnd.Instructions; +using Interpreter.Lib.IR.Ast; namespace Interpreter.Services.Providers.Impl.ParserProvider { diff --git a/Interpreter/Services/Providers/Impl/ParserProvider/LoggingParser.cs b/Interpreter/Services/Providers/Impl/ParserProvider/LoggingParser.cs index 01b912e7..05615703 100644 --- a/Interpreter/Services/Providers/Impl/ParserProvider/LoggingParser.cs +++ b/Interpreter/Services/Providers/Impl/ParserProvider/LoggingParser.cs @@ -1,6 +1,6 @@ using System.IO; -using Interpreter.Lib.Contracts; using Interpreter.Lib.FrontEnd.TopDownParse; +using Interpreter.Lib.IR.Ast; namespace Interpreter.Services.Providers.Impl.ParserProvider { From 77ba1d479e6c8c487fdd63da63cd215db7741315 Mon Sep 17 00:00:00 2001 From: Stepami Date: Wed, 14 Sep 2022 16:57:36 +0300 Subject: [PATCH 24/56] solution rename --- CompilersCourseWork.sln => ExtendedJavaScriptSubset.sln | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename CompilersCourseWork.sln => ExtendedJavaScriptSubset.sln (100%) diff --git a/CompilersCourseWork.sln b/ExtendedJavaScriptSubset.sln similarity index 100% rename from CompilersCourseWork.sln rename to ExtendedJavaScriptSubset.sln From 7a5a2e4f8fbf89f5f3e4e2251411a6e857b3de37 Mon Sep 17 00:00:00 2001 From: Stepami Date: Wed, 14 Sep 2022 17:11:33 +0300 Subject: [PATCH 25/56] =?UTF-8?q?=D0=A1=D0=BF=D0=B5=D1=86=D0=B8=D1=84?= =?UTF-8?q?=D0=B8=D0=BA=D0=B0=D1=86=D0=B8=D1=8F=20=D0=BA=D0=B0=D1=82=D0=B5?= =?UTF-8?q?=D0=B3=D0=BE=D1=80=D0=B8=D0=B8=20=D1=82=D0=B5=D1=81=D1=82=D0=BE?= =?UTF-8?q?=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/develop.yml | 2 +- Interpreter.Tests/Properties/AssemblyInfo.cs | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 Interpreter.Tests/Properties/AssemblyInfo.cs diff --git a/.github/workflows/develop.yml b/.github/workflows/develop.yml index 3287e8e4..dab3d50d 100644 --- a/.github/workflows/develop.yml +++ b/.github/workflows/develop.yml @@ -29,7 +29,7 @@ jobs: - name: Build run: dotnet build --no-restore -c Release -v n - name: Test - run: dotnet test -c Release --no-build -v n /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura + run: dotnet test -c Release --no-build -v n /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura --filter="Category=Unit" - name: Code Coverage Summary Report For Merge Request if: github.event_name == 'pull_request' uses: 5monkeys/cobertura-action@master diff --git a/Interpreter.Tests/Properties/AssemblyInfo.cs b/Interpreter.Tests/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..0fe1ef3e --- /dev/null +++ b/Interpreter.Tests/Properties/AssemblyInfo.cs @@ -0,0 +1,2 @@ +using Xunit; +[assembly: AssemblyTrait("Category", "Unit")] \ No newline at end of file From 608c69ebff744d7ee514b9c2e56fa1f63a46aee0 Mon Sep 17 00:00:00 2001 From: Stepami Date: Wed, 14 Sep 2022 17:18:05 +0300 Subject: [PATCH 26/56] =?UTF-8?q?=D0=9D=D0=B5=D0=B1=D0=BE=D0=BB=D1=8C?= =?UTF-8?q?=D1=88=D0=BE=D0=B9=20=D1=80=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D0=B8=D0=BD=D0=B3=20=D0=B1=D1=8D=D0=BA=D0=B5=D0=BD=D0=B4?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Interpreter.Lib/BackEnd/Call.cs | 14 --------- Interpreter.Lib/BackEnd/FunctionInfo.cs | 25 ---------------- .../BackEnd/Instructions/AsString.cs | 1 + .../BackEnd/Instructions/BeginFunction.cs | 2 ++ .../BackEnd/Instructions/CallFunction.cs | 1 + .../BackEnd/Instructions/CreateArray.cs | 1 + .../BackEnd/Instructions/CreateObject.cs | 1 + .../BackEnd/Instructions/DotAssignment.cs | 1 + Interpreter.Lib/BackEnd/Instructions/Goto.cs | 2 ++ Interpreter.Lib/BackEnd/Instructions/Halt.cs | 2 ++ .../BackEnd/Instructions/IfNotGoto.cs | 1 + .../BackEnd/Instructions/IndexAssignment.cs | 1 + .../BackEnd/Instructions/Instruction.cs | 1 + Interpreter.Lib/BackEnd/Instructions/Print.cs | 1 + .../BackEnd/Instructions/PushParameter.cs | 1 + .../BackEnd/Instructions/RemoveFromArray.cs | 1 + .../BackEnd/Instructions/Return.cs | 1 + .../BackEnd/Instructions/Simple.cs | 1 + Interpreter.Lib/BackEnd/VM/Call.cs | 29 +++++++++++++++++++ Interpreter.Lib/BackEnd/{ => VM}/Frame.cs | 2 +- .../BackEnd/{ => VM}/VirtualMachine.cs | 2 +- Interpreter.Lib/BackEnd/Values/Constant.cs | 2 ++ Interpreter.Lib/BackEnd/Values/IValue.cs | 1 + Interpreter.Lib/BackEnd/Values/Name.cs | 2 ++ .../Variables/Symbols/FunctionSymbol.cs | 1 + .../Services/Executor/Impl/Executor.cs | 1 + 26 files changed, 57 insertions(+), 41 deletions(-) delete mode 100644 Interpreter.Lib/BackEnd/Call.cs delete mode 100644 Interpreter.Lib/BackEnd/FunctionInfo.cs create mode 100644 Interpreter.Lib/BackEnd/VM/Call.cs rename Interpreter.Lib/BackEnd/{ => VM}/Frame.cs (94%) rename Interpreter.Lib/BackEnd/{ => VM}/VirtualMachine.cs (94%) diff --git a/Interpreter.Lib/BackEnd/Call.cs b/Interpreter.Lib/BackEnd/Call.cs deleted file mode 100644 index 4338c9b3..00000000 --- a/Interpreter.Lib/BackEnd/Call.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System.Collections.Generic; -using System.Linq; - -namespace Interpreter.Lib.BackEnd -{ - public record Call( - int From, FunctionInfo To, - List<(string Id, object Value)> Parameters, - string Where = null) - { - public override string ToString() => - $"{From} => {To.Location}: {To.Id}({string.Join(", ", Parameters.Select(x => $"{x.Id}: {x.Value}"))})"; - } -} \ No newline at end of file diff --git a/Interpreter.Lib/BackEnd/FunctionInfo.cs b/Interpreter.Lib/BackEnd/FunctionInfo.cs deleted file mode 100644 index d497d187..00000000 --- a/Interpreter.Lib/BackEnd/FunctionInfo.cs +++ /dev/null @@ -1,25 +0,0 @@ -namespace Interpreter.Lib.BackEnd -{ - public class FunctionInfo - { - public string Id { get; } - - public int Location { get; set; } - - public string MethodOf { get; set; } - - public FunctionInfo(string id, int location = 0, string methodOf = null) - { - Id = id; - Location = location; - MethodOf = methodOf; - } - - public string CallId() => - MethodOf == null - ? Id - : $"{MethodOf}.{Id}"; - - public override string ToString() => $"({Location}, {CallId()})"; - } -} \ No newline at end of file diff --git a/Interpreter.Lib/BackEnd/Instructions/AsString.cs b/Interpreter.Lib/BackEnd/Instructions/AsString.cs index f33e971b..bfe3da84 100644 --- a/Interpreter.Lib/BackEnd/Instructions/AsString.cs +++ b/Interpreter.Lib/BackEnd/Instructions/AsString.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using Interpreter.Lib.BackEnd.Values; +using Interpreter.Lib.BackEnd.VM; using Newtonsoft.Json; using Newtonsoft.Json.Serialization; diff --git a/Interpreter.Lib/BackEnd/Instructions/BeginFunction.cs b/Interpreter.Lib/BackEnd/Instructions/BeginFunction.cs index 69da704b..9aeccb66 100644 --- a/Interpreter.Lib/BackEnd/Instructions/BeginFunction.cs +++ b/Interpreter.Lib/BackEnd/Instructions/BeginFunction.cs @@ -1,3 +1,5 @@ +using Interpreter.Lib.BackEnd.VM; + namespace Interpreter.Lib.BackEnd.Instructions { public class BeginFunction : Instruction diff --git a/Interpreter.Lib/BackEnd/Instructions/CallFunction.cs b/Interpreter.Lib/BackEnd/Instructions/CallFunction.cs index dd737278..a3a3127c 100644 --- a/Interpreter.Lib/BackEnd/Instructions/CallFunction.cs +++ b/Interpreter.Lib/BackEnd/Instructions/CallFunction.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using Interpreter.Lib.BackEnd.VM; namespace Interpreter.Lib.BackEnd.Instructions { diff --git a/Interpreter.Lib/BackEnd/Instructions/CreateArray.cs b/Interpreter.Lib/BackEnd/Instructions/CreateArray.cs index 7f506a93..3e30a690 100644 --- a/Interpreter.Lib/BackEnd/Instructions/CreateArray.cs +++ b/Interpreter.Lib/BackEnd/Instructions/CreateArray.cs @@ -1,4 +1,5 @@ using System.Linq; +using Interpreter.Lib.BackEnd.VM; namespace Interpreter.Lib.BackEnd.Instructions { diff --git a/Interpreter.Lib/BackEnd/Instructions/CreateObject.cs b/Interpreter.Lib/BackEnd/Instructions/CreateObject.cs index 65e05eeb..aeb8392a 100644 --- a/Interpreter.Lib/BackEnd/Instructions/CreateObject.cs +++ b/Interpreter.Lib/BackEnd/Instructions/CreateObject.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using Interpreter.Lib.BackEnd.VM; namespace Interpreter.Lib.BackEnd.Instructions { diff --git a/Interpreter.Lib/BackEnd/Instructions/DotAssignment.cs b/Interpreter.Lib/BackEnd/Instructions/DotAssignment.cs index 42121337..49e2115d 100644 --- a/Interpreter.Lib/BackEnd/Instructions/DotAssignment.cs +++ b/Interpreter.Lib/BackEnd/Instructions/DotAssignment.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using Interpreter.Lib.BackEnd.Values; +using Interpreter.Lib.BackEnd.VM; namespace Interpreter.Lib.BackEnd.Instructions { diff --git a/Interpreter.Lib/BackEnd/Instructions/Goto.cs b/Interpreter.Lib/BackEnd/Instructions/Goto.cs index 96e03b9a..d20e141f 100644 --- a/Interpreter.Lib/BackEnd/Instructions/Goto.cs +++ b/Interpreter.Lib/BackEnd/Instructions/Goto.cs @@ -1,3 +1,5 @@ +using Interpreter.Lib.BackEnd.VM; + namespace Interpreter.Lib.BackEnd.Instructions { public class Goto : Instruction diff --git a/Interpreter.Lib/BackEnd/Instructions/Halt.cs b/Interpreter.Lib/BackEnd/Instructions/Halt.cs index 614a7a2f..3aca0aa3 100644 --- a/Interpreter.Lib/BackEnd/Instructions/Halt.cs +++ b/Interpreter.Lib/BackEnd/Instructions/Halt.cs @@ -1,3 +1,5 @@ +using Interpreter.Lib.BackEnd.VM; + namespace Interpreter.Lib.BackEnd.Instructions { public class Halt : Instruction diff --git a/Interpreter.Lib/BackEnd/Instructions/IfNotGoto.cs b/Interpreter.Lib/BackEnd/Instructions/IfNotGoto.cs index 6f275799..234bccfd 100644 --- a/Interpreter.Lib/BackEnd/Instructions/IfNotGoto.cs +++ b/Interpreter.Lib/BackEnd/Instructions/IfNotGoto.cs @@ -1,5 +1,6 @@ using System; using Interpreter.Lib.BackEnd.Values; +using Interpreter.Lib.BackEnd.VM; namespace Interpreter.Lib.BackEnd.Instructions { diff --git a/Interpreter.Lib/BackEnd/Instructions/IndexAssignment.cs b/Interpreter.Lib/BackEnd/Instructions/IndexAssignment.cs index 3865d73e..c4bd3408 100644 --- a/Interpreter.Lib/BackEnd/Instructions/IndexAssignment.cs +++ b/Interpreter.Lib/BackEnd/Instructions/IndexAssignment.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using Interpreter.Lib.BackEnd.Values; +using Interpreter.Lib.BackEnd.VM; namespace Interpreter.Lib.BackEnd.Instructions { diff --git a/Interpreter.Lib/BackEnd/Instructions/Instruction.cs b/Interpreter.Lib/BackEnd/Instructions/Instruction.cs index 8c8443da..992803b7 100644 --- a/Interpreter.Lib/BackEnd/Instructions/Instruction.cs +++ b/Interpreter.Lib/BackEnd/Instructions/Instruction.cs @@ -1,4 +1,5 @@ using System; +using Interpreter.Lib.BackEnd.VM; namespace Interpreter.Lib.BackEnd.Instructions { diff --git a/Interpreter.Lib/BackEnd/Instructions/Print.cs b/Interpreter.Lib/BackEnd/Instructions/Print.cs index 1a05d832..30dae7b2 100644 --- a/Interpreter.Lib/BackEnd/Instructions/Print.cs +++ b/Interpreter.Lib/BackEnd/Instructions/Print.cs @@ -1,5 +1,6 @@ using System; using Interpreter.Lib.BackEnd.Values; +using Interpreter.Lib.BackEnd.VM; namespace Interpreter.Lib.BackEnd.Instructions { diff --git a/Interpreter.Lib/BackEnd/Instructions/PushParameter.cs b/Interpreter.Lib/BackEnd/Instructions/PushParameter.cs index 97358e4c..4dde6d8e 100644 --- a/Interpreter.Lib/BackEnd/Instructions/PushParameter.cs +++ b/Interpreter.Lib/BackEnd/Instructions/PushParameter.cs @@ -1,4 +1,5 @@ using Interpreter.Lib.BackEnd.Values; +using Interpreter.Lib.BackEnd.VM; namespace Interpreter.Lib.BackEnd.Instructions { diff --git a/Interpreter.Lib/BackEnd/Instructions/RemoveFromArray.cs b/Interpreter.Lib/BackEnd/Instructions/RemoveFromArray.cs index 11f65e17..aead4904 100644 --- a/Interpreter.Lib/BackEnd/Instructions/RemoveFromArray.cs +++ b/Interpreter.Lib/BackEnd/Instructions/RemoveFromArray.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using Interpreter.Lib.BackEnd.Values; +using Interpreter.Lib.BackEnd.VM; namespace Interpreter.Lib.BackEnd.Instructions { diff --git a/Interpreter.Lib/BackEnd/Instructions/Return.cs b/Interpreter.Lib/BackEnd/Instructions/Return.cs index b1355aaa..1948a6cc 100644 --- a/Interpreter.Lib/BackEnd/Instructions/Return.cs +++ b/Interpreter.Lib/BackEnd/Instructions/Return.cs @@ -1,6 +1,7 @@ using System.Collections; using System.Collections.Generic; using Interpreter.Lib.BackEnd.Values; +using Interpreter.Lib.BackEnd.VM; namespace Interpreter.Lib.BackEnd.Instructions { diff --git a/Interpreter.Lib/BackEnd/Instructions/Simple.cs b/Interpreter.Lib/BackEnd/Instructions/Simple.cs index 7ad6d5b4..084b56f7 100644 --- a/Interpreter.Lib/BackEnd/Instructions/Simple.cs +++ b/Interpreter.Lib/BackEnd/Instructions/Simple.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using Interpreter.Lib.BackEnd.Values; +using Interpreter.Lib.BackEnd.VM; namespace Interpreter.Lib.BackEnd.Instructions { diff --git a/Interpreter.Lib/BackEnd/VM/Call.cs b/Interpreter.Lib/BackEnd/VM/Call.cs new file mode 100644 index 00000000..001be86b --- /dev/null +++ b/Interpreter.Lib/BackEnd/VM/Call.cs @@ -0,0 +1,29 @@ +using System.Collections.Generic; +using System.Linq; + +namespace Interpreter.Lib.BackEnd.VM +{ + public record Call( + int From, FunctionInfo To, + List<(string Id, object Value)> Parameters, + string Where = null) + { + public override string ToString() => + $"{From} => {To.Location}: {To.Id}({string.Join(", ", Parameters.Select(x => $"{x.Id}: {x.Value}"))})"; + } + + public record FunctionInfo(string Id, int Location = 0, string MethodOf = null) + { + public int Location { get; set; } = Location; + + public string MethodOf { get; set; } = MethodOf; + + public string CallId() => + MethodOf == null + ? Id + : $"{MethodOf}.{Id}"; + + public override string ToString() => + $"({Location}, {CallId()})"; + } +} \ No newline at end of file diff --git a/Interpreter.Lib/BackEnd/Frame.cs b/Interpreter.Lib/BackEnd/VM/Frame.cs similarity index 94% rename from Interpreter.Lib/BackEnd/Frame.cs rename to Interpreter.Lib/BackEnd/VM/Frame.cs index 420c2164..3d91567b 100644 --- a/Interpreter.Lib/BackEnd/Frame.cs +++ b/Interpreter.Lib/BackEnd/VM/Frame.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace Interpreter.Lib.BackEnd +namespace Interpreter.Lib.BackEnd.VM { public class Frame { diff --git a/Interpreter.Lib/BackEnd/VirtualMachine.cs b/Interpreter.Lib/BackEnd/VM/VirtualMachine.cs similarity index 94% rename from Interpreter.Lib/BackEnd/VirtualMachine.cs rename to Interpreter.Lib/BackEnd/VM/VirtualMachine.cs index 5e8be74c..989de57f 100644 --- a/Interpreter.Lib/BackEnd/VirtualMachine.cs +++ b/Interpreter.Lib/BackEnd/VM/VirtualMachine.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using Interpreter.Lib.BackEnd.Instructions; -namespace Interpreter.Lib.BackEnd +namespace Interpreter.Lib.BackEnd.VM { public class VirtualMachine { diff --git a/Interpreter.Lib/BackEnd/Values/Constant.cs b/Interpreter.Lib/BackEnd/Values/Constant.cs index 70c87341..0b41b0e6 100644 --- a/Interpreter.Lib/BackEnd/Values/Constant.cs +++ b/Interpreter.Lib/BackEnd/Values/Constant.cs @@ -1,3 +1,5 @@ +using Interpreter.Lib.BackEnd.VM; + namespace Interpreter.Lib.BackEnd.Values { public class Constant : IValue diff --git a/Interpreter.Lib/BackEnd/Values/IValue.cs b/Interpreter.Lib/BackEnd/Values/IValue.cs index 06255e67..5775e4de 100644 --- a/Interpreter.Lib/BackEnd/Values/IValue.cs +++ b/Interpreter.Lib/BackEnd/Values/IValue.cs @@ -1,4 +1,5 @@ using System; +using Interpreter.Lib.BackEnd.VM; namespace Interpreter.Lib.BackEnd.Values { diff --git a/Interpreter.Lib/BackEnd/Values/Name.cs b/Interpreter.Lib/BackEnd/Values/Name.cs index 7c01b685..4e897875 100644 --- a/Interpreter.Lib/BackEnd/Values/Name.cs +++ b/Interpreter.Lib/BackEnd/Values/Name.cs @@ -1,3 +1,5 @@ +using Interpreter.Lib.BackEnd.VM; + namespace Interpreter.Lib.BackEnd.Values { public class Name : IValue diff --git a/Interpreter.Lib/IR/CheckSemantics/Variables/Symbols/FunctionSymbol.cs b/Interpreter.Lib/IR/CheckSemantics/Variables/Symbols/FunctionSymbol.cs index ad794443..f302ba84 100644 --- a/Interpreter.Lib/IR/CheckSemantics/Variables/Symbols/FunctionSymbol.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Variables/Symbols/FunctionSymbol.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Text; using Interpreter.Lib.BackEnd; +using Interpreter.Lib.BackEnd.VM; using Interpreter.Lib.IR.Ast.Nodes.Declarations; using Interpreter.Lib.IR.CheckSemantics.Types; diff --git a/Interpreter/Services/Executor/Impl/Executor.cs b/Interpreter/Services/Executor/Impl/Executor.cs index 53ac4d90..0996361a 100644 --- a/Interpreter/Services/Executor/Impl/Executor.cs +++ b/Interpreter/Services/Executor/Impl/Executor.cs @@ -1,5 +1,6 @@ using System; using Interpreter.Lib.BackEnd; +using Interpreter.Lib.BackEnd.VM; using Interpreter.Lib.FrontEnd.GetTokens; using Interpreter.Lib.FrontEnd.TopDownParse; using Interpreter.Lib.IR.CheckSemantics.Exceptions; From 85b4d6ce4976a7609bca030f285888df67a7301c Mon Sep 17 00:00:00 2001 From: Stepami Date: Wed, 14 Sep 2022 17:20:48 +0300 Subject: [PATCH 27/56] removed unused usings --- .../IR/CheckSemantics/Variables/Symbols/FunctionSymbol.cs | 1 - Interpreter/Services/Executor/Impl/Executor.cs | 1 - 2 files changed, 2 deletions(-) diff --git a/Interpreter.Lib/IR/CheckSemantics/Variables/Symbols/FunctionSymbol.cs b/Interpreter.Lib/IR/CheckSemantics/Variables/Symbols/FunctionSymbol.cs index f302ba84..34b90c57 100644 --- a/Interpreter.Lib/IR/CheckSemantics/Variables/Symbols/FunctionSymbol.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Variables/Symbols/FunctionSymbol.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using System.Text; -using Interpreter.Lib.BackEnd; using Interpreter.Lib.BackEnd.VM; using Interpreter.Lib.IR.Ast.Nodes.Declarations; using Interpreter.Lib.IR.CheckSemantics.Types; diff --git a/Interpreter/Services/Executor/Impl/Executor.cs b/Interpreter/Services/Executor/Impl/Executor.cs index 0996361a..3be768bf 100644 --- a/Interpreter/Services/Executor/Impl/Executor.cs +++ b/Interpreter/Services/Executor/Impl/Executor.cs @@ -1,5 +1,4 @@ using System; -using Interpreter.Lib.BackEnd; using Interpreter.Lib.BackEnd.VM; using Interpreter.Lib.FrontEnd.GetTokens; using Interpreter.Lib.FrontEnd.TopDownParse; From 0270e3d127c3a484514b9650cddffe3ae77a9cc8 Mon Sep 17 00:00:00 2001 From: Stepami Date: Wed, 14 Sep 2022 17:33:34 +0300 Subject: [PATCH 28/56] =?UTF-8?q?=D1=80=D0=B5=D1=84=D0=B0=D0=BA=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=B8=D0=BD=D0=B3=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BE?= =?UTF-8?q?=D0=BA=20=D1=81=D0=B5=D0=BC=D0=B0=D0=BD=D1=82=D0=B8=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IR/CheckSemantics/Exceptions/ArrayAccessException.cs | 6 ++---- .../IR/CheckSemantics/Exceptions/AssignmentToConst.cs | 6 +----- .../IR/CheckSemantics/Exceptions/CannotDefineType.cs | 4 +--- .../IR/CheckSemantics/Exceptions/ConstWithoutInitializer.cs | 5 ++--- .../CheckSemantics/Exceptions/DeclarationAlreadyExists.cs | 5 ++--- .../Exceptions/FunctionWithoutReturnStatement.cs | 6 +----- .../Exceptions/IncompatibleTypesOfOperands.cs | 6 +----- .../CheckSemantics/Exceptions/NotBooleanTestExpression.cs | 6 +----- .../IR/CheckSemantics/Exceptions/ObjectAccessException.cs | 4 +--- .../IR/CheckSemantics/Exceptions/OutsideOfLoop.cs | 6 +----- .../IR/CheckSemantics/Exceptions/ReturnOutsideFunction.cs | 6 +----- .../IR/CheckSemantics/Exceptions/SemanticException.cs | 6 +++--- .../IR/CheckSemantics/Exceptions/SymbolIsNotCallable.cs | 4 +--- .../CheckSemantics/Exceptions/UnknownIdentifierReference.cs | 6 +----- .../IR/CheckSemantics/Exceptions/UnsupportedOperation.cs | 6 +----- .../Exceptions/WrongArrayLiteralDeclaration.cs | 4 +--- .../IR/CheckSemantics/Exceptions/WrongConditionalTypes.cs | 6 +----- .../IR/CheckSemantics/Exceptions/WrongNumberOfArguments.cs | 6 +----- .../IR/CheckSemantics/Exceptions/WrongReturnType.cs | 6 +----- .../IR/CheckSemantics/Exceptions/WrongTypeOfArgument.cs | 6 +----- 20 files changed, 25 insertions(+), 85 deletions(-) diff --git a/Interpreter.Lib/IR/CheckSemantics/Exceptions/ArrayAccessException.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/ArrayAccessException.cs index f1956aa7..c4ee4eff 100644 --- a/Interpreter.Lib/IR/CheckSemantics/Exceptions/ArrayAccessException.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/ArrayAccessException.cs @@ -5,9 +5,7 @@ namespace Interpreter.Lib.IR.CheckSemantics.Exceptions { public class ArrayAccessException : SemanticException { - public ArrayAccessException(Segment segment, Type type) : - base($"{segment} Array element cannot be accessed with type {type} it must be of type number") - { - } + public ArrayAccessException(Segment segment, Type type) : + base(segment, $"Array element cannot be accessed with type {type} it must be of type number") { } } } \ No newline at end of file diff --git a/Interpreter.Lib/IR/CheckSemantics/Exceptions/AssignmentToConst.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/AssignmentToConst.cs index 6d3cdba0..6735bea0 100644 --- a/Interpreter.Lib/IR/CheckSemantics/Exceptions/AssignmentToConst.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/AssignmentToConst.cs @@ -5,10 +5,6 @@ namespace Interpreter.Lib.IR.CheckSemantics.Exceptions public class AssignmentToConst : SemanticException { public AssignmentToConst(IdentifierReference ident) : - base( - $"{ident.Segment} Cannot assign to const: {ident.Id}" - ) - { - } + base(ident.Segment,$"Cannot assign to const: {ident.Id}") { } } } \ No newline at end of file diff --git a/Interpreter.Lib/IR/CheckSemantics/Exceptions/CannotDefineType.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/CannotDefineType.cs index c00de25a..399ba97d 100644 --- a/Interpreter.Lib/IR/CheckSemantics/Exceptions/CannotDefineType.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/CannotDefineType.cs @@ -5,8 +5,6 @@ namespace Interpreter.Lib.IR.CheckSemantics.Exceptions public class CannotDefineType : SemanticException { public CannotDefineType(Segment segment) : - base($"{segment} Cannot define type") - { - } + base(segment, "Cannot define type") { } } } \ No newline at end of file diff --git a/Interpreter.Lib/IR/CheckSemantics/Exceptions/ConstWithoutInitializer.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/ConstWithoutInitializer.cs index ec10ce3b..b86ec5ef 100644 --- a/Interpreter.Lib/IR/CheckSemantics/Exceptions/ConstWithoutInitializer.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/ConstWithoutInitializer.cs @@ -4,8 +4,7 @@ namespace Interpreter.Lib.IR.CheckSemantics.Exceptions { public class ConstWithoutInitializer : SemanticException { - public ConstWithoutInitializer(IdentifierReference ident) : base($"{ident.Segment} Const without initializer: {ident.Id}") - { - } + public ConstWithoutInitializer(IdentifierReference ident) : + base(ident.Segment, $"Const without initializer: {ident.Id}") { } } } \ No newline at end of file diff --git a/Interpreter.Lib/IR/CheckSemantics/Exceptions/DeclarationAlreadyExists.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/DeclarationAlreadyExists.cs index a026b6b6..8819da8e 100644 --- a/Interpreter.Lib/IR/CheckSemantics/Exceptions/DeclarationAlreadyExists.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/DeclarationAlreadyExists.cs @@ -4,8 +4,7 @@ namespace Interpreter.Lib.IR.CheckSemantics.Exceptions { public class DeclarationAlreadyExists : SemanticException { - public DeclarationAlreadyExists(IdentifierReference ident) : base($"{ident.Segment} Declaration already exists: {ident.Id}") - { - } + public DeclarationAlreadyExists(IdentifierReference ident) : + base(ident.Segment, $"Declaration already exists: {ident.Id}") { } } } \ No newline at end of file diff --git a/Interpreter.Lib/IR/CheckSemantics/Exceptions/FunctionWithoutReturnStatement.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/FunctionWithoutReturnStatement.cs index 28222ae2..15f6bb17 100644 --- a/Interpreter.Lib/IR/CheckSemantics/Exceptions/FunctionWithoutReturnStatement.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/FunctionWithoutReturnStatement.cs @@ -5,10 +5,6 @@ namespace Interpreter.Lib.IR.CheckSemantics.Exceptions public class FunctionWithoutReturnStatement : SemanticException { public FunctionWithoutReturnStatement(Segment segment) : - base( - $"{segment} function with non-void return type must have a return statement" - ) - { - } + base(segment, "function with non-void return type must have a return statement") { } } } \ No newline at end of file diff --git a/Interpreter.Lib/IR/CheckSemantics/Exceptions/IncompatibleTypesOfOperands.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/IncompatibleTypesOfOperands.cs index 69c44336..3853ec86 100644 --- a/Interpreter.Lib/IR/CheckSemantics/Exceptions/IncompatibleTypesOfOperands.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/IncompatibleTypesOfOperands.cs @@ -6,10 +6,6 @@ namespace Interpreter.Lib.IR.CheckSemantics.Exceptions public class IncompatibleTypesOfOperands : SemanticException { public IncompatibleTypesOfOperands(Segment segment, Type left, Type right) : - base( - $"{segment} Incompatible types of operands: {left} and {right}" - ) - { - } + base(segment, $"Incompatible types of operands: {left} and {right}") { } } } \ No newline at end of file diff --git a/Interpreter.Lib/IR/CheckSemantics/Exceptions/NotBooleanTestExpression.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/NotBooleanTestExpression.cs index d0678895..eaa8740a 100644 --- a/Interpreter.Lib/IR/CheckSemantics/Exceptions/NotBooleanTestExpression.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/NotBooleanTestExpression.cs @@ -6,10 +6,6 @@ namespace Interpreter.Lib.IR.CheckSemantics.Exceptions public class NotBooleanTestExpression : SemanticException { public NotBooleanTestExpression(Segment segment, Type type) : - base( - $"{segment} Type of expression is {type} but expected boolean" - ) - { - } + base(segment, $"Type of expression is {type} but expected boolean") { } } } \ No newline at end of file diff --git a/Interpreter.Lib/IR/CheckSemantics/Exceptions/ObjectAccessException.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/ObjectAccessException.cs index 936eb02e..8a469c54 100644 --- a/Interpreter.Lib/IR/CheckSemantics/Exceptions/ObjectAccessException.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/ObjectAccessException.cs @@ -6,8 +6,6 @@ namespace Interpreter.Lib.IR.CheckSemantics.Exceptions public class ObjectAccessException : SemanticException { public ObjectAccessException(Segment segment, ObjectType objectType, string field) : - base($"{segment} Object type {objectType} has no field {field}") - { - } + base(segment, $"Object type {objectType} has no field {field}") { } } } \ No newline at end of file diff --git a/Interpreter.Lib/IR/CheckSemantics/Exceptions/OutsideOfLoop.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/OutsideOfLoop.cs index 52ce997c..59bd3cdc 100644 --- a/Interpreter.Lib/IR/CheckSemantics/Exceptions/OutsideOfLoop.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/OutsideOfLoop.cs @@ -5,10 +5,6 @@ namespace Interpreter.Lib.IR.CheckSemantics.Exceptions public class OutsideOfLoop : SemanticException { public OutsideOfLoop(Segment segment, string keyword) : - base( - $"{segment} \"{keyword}\" outside of loop" - ) - { - } + base(segment, $"\"{keyword}\" outside of loop") { } } } \ No newline at end of file diff --git a/Interpreter.Lib/IR/CheckSemantics/Exceptions/ReturnOutsideFunction.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/ReturnOutsideFunction.cs index d35c70d5..fbdeb290 100644 --- a/Interpreter.Lib/IR/CheckSemantics/Exceptions/ReturnOutsideFunction.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/ReturnOutsideFunction.cs @@ -5,10 +5,6 @@ namespace Interpreter.Lib.IR.CheckSemantics.Exceptions public class ReturnOutsideFunction : SemanticException { public ReturnOutsideFunction(Segment segment) : - base( - $"{segment} \"return\" outside function" - ) - { - } + base(segment, "\"return\" outside function") { } } } \ No newline at end of file diff --git a/Interpreter.Lib/IR/CheckSemantics/Exceptions/SemanticException.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/SemanticException.cs index 03a422df..fb7109a9 100644 --- a/Interpreter.Lib/IR/CheckSemantics/Exceptions/SemanticException.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/SemanticException.cs @@ -1,11 +1,11 @@ using System; +using Interpreter.Lib.FrontEnd.GetTokens.Impl; namespace Interpreter.Lib.IR.CheckSemantics.Exceptions { public abstract class SemanticException : Exception { - protected SemanticException(string message) : base(message) - { - } + protected SemanticException(Segment segment, string message) : + base($"{segment} {message}") { } } } \ No newline at end of file diff --git a/Interpreter.Lib/IR/CheckSemantics/Exceptions/SymbolIsNotCallable.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/SymbolIsNotCallable.cs index d563cc13..fefca0f4 100644 --- a/Interpreter.Lib/IR/CheckSemantics/Exceptions/SymbolIsNotCallable.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/SymbolIsNotCallable.cs @@ -5,8 +5,6 @@ namespace Interpreter.Lib.IR.CheckSemantics.Exceptions public class SymbolIsNotCallable: SemanticException { public SymbolIsNotCallable(string symbol, Segment segment) : - base($"{segment} Symbol is not callable: {symbol}") - { - } + base(segment, $"Symbol is not callable: {symbol}") { } } } \ No newline at end of file diff --git a/Interpreter.Lib/IR/CheckSemantics/Exceptions/UnknownIdentifierReference.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/UnknownIdentifierReference.cs index 178411c1..4aa9862a 100644 --- a/Interpreter.Lib/IR/CheckSemantics/Exceptions/UnknownIdentifierReference.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/UnknownIdentifierReference.cs @@ -5,10 +5,6 @@ namespace Interpreter.Lib.IR.CheckSemantics.Exceptions public class UnknownIdentifierReference : SemanticException { public UnknownIdentifierReference(IdentifierReference ident) : - base( - $"{ident.Segment} Unknown identifier reference: {ident.Id}" - ) - { - } + base(ident.Segment, $"Unknown identifier reference: {ident.Id}") { } } } \ No newline at end of file diff --git a/Interpreter.Lib/IR/CheckSemantics/Exceptions/UnsupportedOperation.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/UnsupportedOperation.cs index bf1f31ea..5e55f5f1 100644 --- a/Interpreter.Lib/IR/CheckSemantics/Exceptions/UnsupportedOperation.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/UnsupportedOperation.cs @@ -6,10 +6,6 @@ namespace Interpreter.Lib.IR.CheckSemantics.Exceptions public class UnsupportedOperation : SemanticException { public UnsupportedOperation(Segment segment, Type type, string @operator) : - base( - $"{segment} Type {type} does not support operation {@operator}" - ) - { - } + base(segment, $"Type {type} does not support operation {@operator}") { } } } \ No newline at end of file diff --git a/Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongArrayLiteralDeclaration.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongArrayLiteralDeclaration.cs index b4a5d179..e7612a1e 100644 --- a/Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongArrayLiteralDeclaration.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongArrayLiteralDeclaration.cs @@ -6,8 +6,6 @@ namespace Interpreter.Lib.IR.CheckSemantics.Exceptions public class WrongArrayLiteralDeclaration : SemanticException { public WrongArrayLiteralDeclaration(Segment segment, Type type) : - base($"{segment} Wrong array literal declaration: all array elements must be of type {type}") - { - } + base(segment, $"{segment} Wrong array literal declaration: all array elements must be of type {type}") { } } } \ No newline at end of file diff --git a/Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongConditionalTypes.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongConditionalTypes.cs index 8bbd3f59..e45ccb32 100644 --- a/Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongConditionalTypes.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongConditionalTypes.cs @@ -6,10 +6,6 @@ namespace Interpreter.Lib.IR.CheckSemantics.Exceptions public class WrongConditionalTypes : SemanticException { public WrongConditionalTypes(Segment cSegment, Type cType, Segment aSegment, Type aType) : - base( - $"Different types in conditional: {cSegment} consequent - {cType}, {aSegment} alternate {aType}" - ) - { - } + base(cSegment + aSegment, $"Different types in conditional: {cSegment} consequent - {cType}, {aSegment} alternate {aType}") { } } } \ No newline at end of file diff --git a/Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongNumberOfArguments.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongNumberOfArguments.cs index 61ee9c85..708b449d 100644 --- a/Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongNumberOfArguments.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongNumberOfArguments.cs @@ -5,10 +5,6 @@ namespace Interpreter.Lib.IR.CheckSemantics.Exceptions public class WrongNumberOfArguments : SemanticException { public WrongNumberOfArguments(Segment segment, int expected, int actual) : - base( - $"{segment} Wrong number of arguments: expected {expected}, actual {actual}" - ) - { - } + base(segment, $"Wrong number of arguments: expected {expected}, actual {actual}") { } } } \ No newline at end of file diff --git a/Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongReturnType.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongReturnType.cs index aa7034ed..e3bd5a80 100644 --- a/Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongReturnType.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongReturnType.cs @@ -6,10 +6,6 @@ namespace Interpreter.Lib.IR.CheckSemantics.Exceptions public class WrongReturnType : SemanticException { public WrongReturnType(Segment segment, Type expected, Type actual) : - base( - $"{segment} Wrong return type: expected {expected}, actual {actual}" - ) - { - } + base(segment, $"Wrong return type: expected {expected}, actual {actual}") { } } } \ No newline at end of file diff --git a/Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongTypeOfArgument.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongTypeOfArgument.cs index bd571e29..ee996f7c 100644 --- a/Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongTypeOfArgument.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongTypeOfArgument.cs @@ -6,10 +6,6 @@ namespace Interpreter.Lib.IR.CheckSemantics.Exceptions public class WrongTypeOfArgument : SemanticException { public WrongTypeOfArgument(Segment segment, Type expected, Type actual) : - base( - $"{segment} Wrong type of argument: expected {expected}, actual {actual}" - ) - { - } + base(segment,$"Wrong type of argument: expected {expected}, actual {actual}") { } } } \ No newline at end of file From bf62482d06e08026ff7d8ac78f0b6a99d584e76a Mon Sep 17 00:00:00 2001 From: Stepami Date: Wed, 14 Sep 2022 23:06:28 +0300 Subject: [PATCH 29/56] =?UTF-8?q?=D0=BF=D0=BE=D0=B2=D1=8B=D1=81=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=BF=D0=BE=D1=80=D0=BE=D0=B3=20coverage=20=D0=B4?= =?UTF-8?q?=D0=BE=2080%?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/develop.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/develop.yml b/.github/workflows/develop.yml index dab3d50d..65fd83f8 100644 --- a/.github/workflows/develop.yml +++ b/.github/workflows/develop.yml @@ -36,7 +36,7 @@ jobs: with: path: ./Interpreter.Tests/coverage.cobertura.xml repo_token: ${{ secrets.GITHUB_TOKEN }} - minimum_coverage: 20 + minimum_coverage: 80 fail_below_threshold: true show_class_names: true show_missing: true @@ -53,5 +53,5 @@ jobs: format: markdown hide_branch_rate: true hide_complexity: true - thresholds: '20 30' + thresholds: '80 100' From 35b9faf81371eabffeb74f1a09574faa18a9b730 Mon Sep 17 00:00:00 2001 From: Stepami Date: Thu, 15 Sep 2022 12:34:24 +0300 Subject: [PATCH 30/56] =?UTF-8?q?=D1=80=D0=B5=D1=84=D0=B0=D0=BA=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=B8=D0=BD=D0=B3=20=D0=BF=D0=B5=D1=87=D0=B0=D1=82?= =?UTF-8?q?=D0=B8=20=D0=B2=20=D0=B2=D0=B8=D1=80=D1=82=D1=83=D0=B0=D0=BB?= =?UTF-8?q?=D1=8C=D0=BD=D0=BE=D0=B9=20=D0=BC=D0=B0=D1=88=D0=B8=D0=BD=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Interpreter.Lib/BackEnd/Instructions/Print.cs | 3 +-- Interpreter.Lib/BackEnd/VM/VirtualMachine.cs | 15 +++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Interpreter.Lib/BackEnd/Instructions/Print.cs b/Interpreter.Lib/BackEnd/Instructions/Print.cs index 30dae7b2..38f27f05 100644 --- a/Interpreter.Lib/BackEnd/Instructions/Print.cs +++ b/Interpreter.Lib/BackEnd/Instructions/Print.cs @@ -1,4 +1,3 @@ -using System; using Interpreter.Lib.BackEnd.Values; using Interpreter.Lib.BackEnd.VM; @@ -15,7 +14,7 @@ public Print(int number, IValue value) : base(number) public override int Execute(VirtualMachine vm) { - Console.WriteLine(_value.Get(vm.Frames.Peek())); + vm.Writer.WriteLine(_value.Get(vm.Frames.Peek())); return Number + 1; } diff --git a/Interpreter.Lib/BackEnd/VM/VirtualMachine.cs b/Interpreter.Lib/BackEnd/VM/VirtualMachine.cs index 989de57f..741d6bdf 100644 --- a/Interpreter.Lib/BackEnd/VM/VirtualMachine.cs +++ b/Interpreter.Lib/BackEnd/VM/VirtualMachine.cs @@ -1,15 +1,18 @@ +using System; using System.Collections.Generic; +using System.IO; using Interpreter.Lib.BackEnd.Instructions; namespace Interpreter.Lib.BackEnd.VM { - public class VirtualMachine + public record VirtualMachine( + Stack CallStack, Stack Frames, + Stack<(string Id, object Value)> Arguments, + TextWriter Writer + ) { - public Stack CallStack { get; } = new(); - - public Stack Frames { get; } = new(); - - public Stack<(string Id, object Value)> Arguments { get; } = new(); + public VirtualMachine() : + this(new(), new(), new(), Console.Out) { } public void Run(List instructions) { From 04d1ff6dd79750ea016f3d40c2f2e1dc1461f9b3 Mon Sep 17 00:00:00 2001 From: Stepami Date: Thu, 15 Sep 2022 12:43:10 +0300 Subject: [PATCH 31/56] =?UTF-8?q?=D1=80=D0=B5=D0=BE=D1=80=D0=B3=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20=D0=BF=D0=B0=D0=BF?= =?UTF-8?q?=D0=BE=D0=BA=20=D1=84=D0=B8=D1=87=D0=B8=20GetTokens?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FrontEnd/GetTokens/{Impl => Data}/Structure.cs | 13 +++++-------- .../FrontEnd/GetTokens/{Impl => Data}/Token.cs | 4 ++-- .../{Impl => Data}/TokenTypes/EndOfProgramType.cs | 2 +- .../{Impl => Data}/TokenTypes/ErrorType.cs | 2 +- .../{Impl => Data}/TokenTypes/TokenType.cs | 2 +- .../TokenTypes/TokenTypeUtils.cs} | 6 ++---- .../{Impl => Data}/TokenTypes/WhiteSpaceType.cs | 2 +- Interpreter.Lib/FrontEnd/GetTokens/ILexer.cs | 2 +- Interpreter.Lib/FrontEnd/GetTokens/Impl/Lexer.cs | 4 +++- .../FrontEnd/GetTokens/LexerException.cs | 2 +- .../FrontEnd/TopDownParse/Impl/Parser.cs | 2 +- .../FrontEnd/TopDownParse/Impl/TokensStream.cs | 2 +- .../FrontEnd/TopDownParse/ParserException.cs | 2 +- .../IR/Ast/Nodes/AbstractSyntaxTreeNode.cs | 2 +- .../IR/Ast/Nodes/Declarations/LexicalDeclaration.cs | 2 +- .../Nodes/Expressions/PrimaryExpressions/Literal.cs | 2 +- .../Exceptions/ArrayAccessException.cs | 2 +- .../CheckSemantics/Exceptions/CannotDefineType.cs | 2 +- .../Exceptions/FunctionWithoutReturnStatement.cs | 2 +- .../Exceptions/IncompatibleTypesOfOperands.cs | 2 +- .../Exceptions/NotBooleanTestExpression.cs | 2 +- .../Exceptions/ObjectAccessException.cs | 2 +- .../IR/CheckSemantics/Exceptions/OutsideOfLoop.cs | 2 +- .../Exceptions/ReturnOutsideFunction.cs | 2 +- .../CheckSemantics/Exceptions/SemanticException.cs | 2 +- .../Exceptions/SymbolIsNotCallable.cs | 2 +- .../Exceptions/UnsupportedOperation.cs | 2 +- .../Exceptions/WrongArrayLiteralDeclaration.cs | 2 +- .../Exceptions/WrongConditionalTypes.cs | 2 +- .../Exceptions/WrongNumberOfArguments.cs | 2 +- .../IR/CheckSemantics/Exceptions/WrongReturnType.cs | 2 +- .../Exceptions/WrongTypeOfArgument.cs | 2 +- .../IR/CheckSemantics/Variables/SymbolTableUtils.cs | 2 +- Interpreter.Tests/Unit/ParserTests.cs | 1 + Interpreter/MappingProfiles/StructureProfile.cs | 4 ++-- Interpreter/MappingProfiles/TokenTypeProfile.cs | 2 +- .../Providers/Impl/LexerProvider/LexerProvider.cs | 1 + .../Providers/Impl/LexerProvider/LoggingLexer.cs | 2 +- 38 files changed, 47 insertions(+), 48 deletions(-) rename Interpreter.Lib/FrontEnd/GetTokens/{Impl => Data}/Structure.cs (83%) rename Interpreter.Lib/FrontEnd/GetTokens/{Impl => Data}/Token.cs (93%) rename Interpreter.Lib/FrontEnd/GetTokens/{Impl => Data}/TokenTypes/EndOfProgramType.cs (70%) rename Interpreter.Lib/FrontEnd/GetTokens/{Impl => Data}/TokenTypes/ErrorType.cs (69%) rename Interpreter.Lib/FrontEnd/GetTokens/{Impl => Data}/TokenTypes/TokenType.cs (87%) rename Interpreter.Lib/FrontEnd/GetTokens/{LexerUtils.cs => Data/TokenTypes/TokenTypeUtils.cs} (52%) rename Interpreter.Lib/FrontEnd/GetTokens/{Impl => Data}/TokenTypes/WhiteSpaceType.cs (76%) diff --git a/Interpreter.Lib/FrontEnd/GetTokens/Impl/Structure.cs b/Interpreter.Lib/FrontEnd/GetTokens/Data/Structure.cs similarity index 83% rename from Interpreter.Lib/FrontEnd/GetTokens/Impl/Structure.cs rename to Interpreter.Lib/FrontEnd/GetTokens/Data/Structure.cs index c66b6fe2..2fdbfd63 100644 --- a/Interpreter.Lib/FrontEnd/GetTokens/Impl/Structure.cs +++ b/Interpreter.Lib/FrontEnd/GetTokens/Data/Structure.cs @@ -3,9 +3,9 @@ using System.Linq; using System.Text; using System.Text.RegularExpressions; -using Interpreter.Lib.FrontEnd.GetTokens.Impl.TokenTypes; +using Interpreter.Lib.FrontEnd.GetTokens.Data.TokenTypes; -namespace Interpreter.Lib.FrontEnd.GetTokens.Impl +namespace Interpreter.Lib.FrontEnd.GetTokens.Data { public class Structure : IEnumerable { @@ -13,8 +13,8 @@ public Structure(List types) { types.AddRange(new List { - LexerUtils.End, - LexerUtils.Error + TokenTypeUtils.End, + TokenTypeUtils.Error }); types = types .OrderBy(t => t.Priority) @@ -38,10 +38,7 @@ public Structure(List types) public Regex Regex { get; } - public TokenType FindByTag(string tag) - { - return Types[tag]; - } + public TokenType FindByTag(string tag) => Types[tag]; public override string ToString() { diff --git a/Interpreter.Lib/FrontEnd/GetTokens/Impl/Token.cs b/Interpreter.Lib/FrontEnd/GetTokens/Data/Token.cs similarity index 93% rename from Interpreter.Lib/FrontEnd/GetTokens/Impl/Token.cs rename to Interpreter.Lib/FrontEnd/GetTokens/Data/Token.cs index 88879c85..3ff1d963 100644 --- a/Interpreter.Lib/FrontEnd/GetTokens/Impl/Token.cs +++ b/Interpreter.Lib/FrontEnd/GetTokens/Data/Token.cs @@ -1,8 +1,8 @@ using System.Collections.Generic; using System.Text.RegularExpressions; -using Interpreter.Lib.FrontEnd.GetTokens.Impl.TokenTypes; +using Interpreter.Lib.FrontEnd.GetTokens.Data.TokenTypes; -namespace Interpreter.Lib.FrontEnd.GetTokens.Impl +namespace Interpreter.Lib.FrontEnd.GetTokens.Data { public record Token(TokenType Type) { diff --git a/Interpreter.Lib/FrontEnd/GetTokens/Impl/TokenTypes/EndOfProgramType.cs b/Interpreter.Lib/FrontEnd/GetTokens/Data/TokenTypes/EndOfProgramType.cs similarity index 70% rename from Interpreter.Lib/FrontEnd/GetTokens/Impl/TokenTypes/EndOfProgramType.cs rename to Interpreter.Lib/FrontEnd/GetTokens/Data/TokenTypes/EndOfProgramType.cs index 8d1f1f21..ea457862 100644 --- a/Interpreter.Lib/FrontEnd/GetTokens/Impl/TokenTypes/EndOfProgramType.cs +++ b/Interpreter.Lib/FrontEnd/GetTokens/Data/TokenTypes/EndOfProgramType.cs @@ -1,4 +1,4 @@ -namespace Interpreter.Lib.FrontEnd.GetTokens.Impl.TokenTypes +namespace Interpreter.Lib.FrontEnd.GetTokens.Data.TokenTypes { internal record EndOfProgramType() : TokenType("EOP", "", int.MaxValue - 1) { diff --git a/Interpreter.Lib/FrontEnd/GetTokens/Impl/TokenTypes/ErrorType.cs b/Interpreter.Lib/FrontEnd/GetTokens/Data/TokenTypes/ErrorType.cs similarity index 69% rename from Interpreter.Lib/FrontEnd/GetTokens/Impl/TokenTypes/ErrorType.cs rename to Interpreter.Lib/FrontEnd/GetTokens/Data/TokenTypes/ErrorType.cs index b07f5957..199ab7c2 100644 --- a/Interpreter.Lib/FrontEnd/GetTokens/Impl/TokenTypes/ErrorType.cs +++ b/Interpreter.Lib/FrontEnd/GetTokens/Data/TokenTypes/ErrorType.cs @@ -1,4 +1,4 @@ -namespace Interpreter.Lib.FrontEnd.GetTokens.Impl.TokenTypes +namespace Interpreter.Lib.FrontEnd.GetTokens.Data.TokenTypes { internal record ErrorType() : TokenType("ERROR", @"\S+", int.MaxValue) { diff --git a/Interpreter.Lib/FrontEnd/GetTokens/Impl/TokenTypes/TokenType.cs b/Interpreter.Lib/FrontEnd/GetTokens/Data/TokenTypes/TokenType.cs similarity index 87% rename from Interpreter.Lib/FrontEnd/GetTokens/Impl/TokenTypes/TokenType.cs rename to Interpreter.Lib/FrontEnd/GetTokens/Data/TokenTypes/TokenType.cs index e10ce5c7..70337d00 100644 --- a/Interpreter.Lib/FrontEnd/GetTokens/Impl/TokenTypes/TokenType.cs +++ b/Interpreter.Lib/FrontEnd/GetTokens/Data/TokenTypes/TokenType.cs @@ -1,4 +1,4 @@ -namespace Interpreter.Lib.FrontEnd.GetTokens.Impl.TokenTypes +namespace Interpreter.Lib.FrontEnd.GetTokens.Data.TokenTypes { public record TokenType(string Tag, string Pattern, int Priority) { diff --git a/Interpreter.Lib/FrontEnd/GetTokens/LexerUtils.cs b/Interpreter.Lib/FrontEnd/GetTokens/Data/TokenTypes/TokenTypeUtils.cs similarity index 52% rename from Interpreter.Lib/FrontEnd/GetTokens/LexerUtils.cs rename to Interpreter.Lib/FrontEnd/GetTokens/Data/TokenTypes/TokenTypeUtils.cs index 6bec3b10..c14bfbec 100644 --- a/Interpreter.Lib/FrontEnd/GetTokens/LexerUtils.cs +++ b/Interpreter.Lib/FrontEnd/GetTokens/Data/TokenTypes/TokenTypeUtils.cs @@ -1,8 +1,6 @@ -using Interpreter.Lib.FrontEnd.GetTokens.Impl.TokenTypes; - -namespace Interpreter.Lib.FrontEnd.GetTokens +namespace Interpreter.Lib.FrontEnd.GetTokens.Data.TokenTypes { - public static class LexerUtils + public static class TokenTypeUtils { public static readonly TokenType End = new EndOfProgramType(); public static readonly TokenType Error = new ErrorType(); diff --git a/Interpreter.Lib/FrontEnd/GetTokens/Impl/TokenTypes/WhiteSpaceType.cs b/Interpreter.Lib/FrontEnd/GetTokens/Data/TokenTypes/WhiteSpaceType.cs similarity index 76% rename from Interpreter.Lib/FrontEnd/GetTokens/Impl/TokenTypes/WhiteSpaceType.cs rename to Interpreter.Lib/FrontEnd/GetTokens/Data/TokenTypes/WhiteSpaceType.cs index 5e7742bb..166fcc01 100644 --- a/Interpreter.Lib/FrontEnd/GetTokens/Impl/TokenTypes/WhiteSpaceType.cs +++ b/Interpreter.Lib/FrontEnd/GetTokens/Data/TokenTypes/WhiteSpaceType.cs @@ -1,4 +1,4 @@ -namespace Interpreter.Lib.FrontEnd.GetTokens.Impl.TokenTypes +namespace Interpreter.Lib.FrontEnd.GetTokens.Data.TokenTypes { public record WhiteSpaceType(string Tag = null, string Pattern = null, int Priority = 0) : TokenType(Tag, Pattern, Priority) diff --git a/Interpreter.Lib/FrontEnd/GetTokens/ILexer.cs b/Interpreter.Lib/FrontEnd/GetTokens/ILexer.cs index 8dc9095e..c087a637 100644 --- a/Interpreter.Lib/FrontEnd/GetTokens/ILexer.cs +++ b/Interpreter.Lib/FrontEnd/GetTokens/ILexer.cs @@ -1,5 +1,5 @@ using System.Collections.Generic; -using Interpreter.Lib.FrontEnd.GetTokens.Impl; +using Interpreter.Lib.FrontEnd.GetTokens.Data; namespace Interpreter.Lib.FrontEnd.GetTokens { diff --git a/Interpreter.Lib/FrontEnd/GetTokens/Impl/Lexer.cs b/Interpreter.Lib/FrontEnd/GetTokens/Impl/Lexer.cs index 1e26911b..2fb79d58 100644 --- a/Interpreter.Lib/FrontEnd/GetTokens/Impl/Lexer.cs +++ b/Interpreter.Lib/FrontEnd/GetTokens/Impl/Lexer.cs @@ -2,6 +2,8 @@ using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; +using Interpreter.Lib.FrontEnd.GetTokens.Data; +using Interpreter.Lib.FrontEnd.GetTokens.Data.TokenTypes; namespace Interpreter.Lib.FrontEnd.GetTokens.Impl { @@ -54,7 +56,7 @@ public IEnumerator GetEnumerator() } } - yield return new Token(LexerUtils.End); + yield return new Token(TokenTypeUtils.End); } IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); diff --git a/Interpreter.Lib/FrontEnd/GetTokens/LexerException.cs b/Interpreter.Lib/FrontEnd/GetTokens/LexerException.cs index 030393b7..b511176c 100644 --- a/Interpreter.Lib/FrontEnd/GetTokens/LexerException.cs +++ b/Interpreter.Lib/FrontEnd/GetTokens/LexerException.cs @@ -1,5 +1,5 @@ using System; -using Interpreter.Lib.FrontEnd.GetTokens.Impl; +using Interpreter.Lib.FrontEnd.GetTokens.Data; namespace Interpreter.Lib.FrontEnd.GetTokens { diff --git a/Interpreter.Lib/FrontEnd/TopDownParse/Impl/Parser.cs b/Interpreter.Lib/FrontEnd/TopDownParse/Impl/Parser.cs index 11c72988..708a9927 100644 --- a/Interpreter.Lib/FrontEnd/TopDownParse/Impl/Parser.cs +++ b/Interpreter.Lib/FrontEnd/TopDownParse/Impl/Parser.cs @@ -2,7 +2,7 @@ using System.Linq; using System.Text.RegularExpressions; using Interpreter.Lib.FrontEnd.GetTokens; -using Interpreter.Lib.FrontEnd.GetTokens.Impl; +using Interpreter.Lib.FrontEnd.GetTokens.Data; using Interpreter.Lib.IR.Ast; using Interpreter.Lib.IR.Ast.Impl; using Interpreter.Lib.IR.Ast.Nodes; diff --git a/Interpreter.Lib/FrontEnd/TopDownParse/Impl/TokensStream.cs b/Interpreter.Lib/FrontEnd/TopDownParse/Impl/TokensStream.cs index 3ec74551..1cde5d97 100644 --- a/Interpreter.Lib/FrontEnd/TopDownParse/Impl/TokensStream.cs +++ b/Interpreter.Lib/FrontEnd/TopDownParse/Impl/TokensStream.cs @@ -1,6 +1,6 @@ using System.Collections; using System.Collections.Generic; -using Interpreter.Lib.FrontEnd.GetTokens.Impl; +using Interpreter.Lib.FrontEnd.GetTokens.Data; namespace Interpreter.Lib.FrontEnd.TopDownParse.Impl { diff --git a/Interpreter.Lib/FrontEnd/TopDownParse/ParserException.cs b/Interpreter.Lib/FrontEnd/TopDownParse/ParserException.cs index 67f88fee..609d5a1a 100644 --- a/Interpreter.Lib/FrontEnd/TopDownParse/ParserException.cs +++ b/Interpreter.Lib/FrontEnd/TopDownParse/ParserException.cs @@ -1,5 +1,5 @@ using System; -using Interpreter.Lib.FrontEnd.GetTokens.Impl; +using Interpreter.Lib.FrontEnd.GetTokens.Data; namespace Interpreter.Lib.FrontEnd.TopDownParse { diff --git a/Interpreter.Lib/IR/Ast/Nodes/AbstractSyntaxTreeNode.cs b/Interpreter.Lib/IR/Ast/Nodes/AbstractSyntaxTreeNode.cs index 32d7b5d5..0095a5b5 100644 --- a/Interpreter.Lib/IR/Ast/Nodes/AbstractSyntaxTreeNode.cs +++ b/Interpreter.Lib/IR/Ast/Nodes/AbstractSyntaxTreeNode.cs @@ -1,7 +1,7 @@ using System.Collections; using System.Collections.Generic; using Interpreter.Lib.BackEnd.Instructions; -using Interpreter.Lib.FrontEnd.GetTokens.Impl; +using Interpreter.Lib.FrontEnd.GetTokens.Data; using Interpreter.Lib.IR.Ast.Nodes.Declarations; using Interpreter.Lib.IR.CheckSemantics.Types; using Interpreter.Lib.IR.CheckSemantics.Variables; diff --git a/Interpreter.Lib/IR/Ast/Nodes/Declarations/LexicalDeclaration.cs b/Interpreter.Lib/IR/Ast/Nodes/Declarations/LexicalDeclaration.cs index 407155da..4cb9b7e4 100644 --- a/Interpreter.Lib/IR/Ast/Nodes/Declarations/LexicalDeclaration.cs +++ b/Interpreter.Lib/IR/Ast/Nodes/Declarations/LexicalDeclaration.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using System.Linq; using Interpreter.Lib.BackEnd.Instructions; -using Interpreter.Lib.FrontEnd.GetTokens.Impl; +using Interpreter.Lib.FrontEnd.GetTokens.Data; using Interpreter.Lib.IR.Ast.Nodes.Expressions; using Interpreter.Lib.IR.Ast.Nodes.Expressions.PrimaryExpressions; using Interpreter.Lib.IR.CheckSemantics.Types; diff --git a/Interpreter.Lib/IR/Ast/Nodes/Expressions/PrimaryExpressions/Literal.cs b/Interpreter.Lib/IR/Ast/Nodes/Expressions/PrimaryExpressions/Literal.cs index 037aa829..7eacc3bd 100644 --- a/Interpreter.Lib/IR/Ast/Nodes/Expressions/PrimaryExpressions/Literal.cs +++ b/Interpreter.Lib/IR/Ast/Nodes/Expressions/PrimaryExpressions/Literal.cs @@ -1,5 +1,5 @@ using Interpreter.Lib.BackEnd.Values; -using Interpreter.Lib.FrontEnd.GetTokens.Impl; +using Interpreter.Lib.FrontEnd.GetTokens.Data; using Type = Interpreter.Lib.IR.CheckSemantics.Types.Type; namespace Interpreter.Lib.IR.Ast.Nodes.Expressions.PrimaryExpressions diff --git a/Interpreter.Lib/IR/CheckSemantics/Exceptions/ArrayAccessException.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/ArrayAccessException.cs index c4ee4eff..d3e08b3e 100644 --- a/Interpreter.Lib/IR/CheckSemantics/Exceptions/ArrayAccessException.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/ArrayAccessException.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.FrontEnd.GetTokens.Impl; +using Interpreter.Lib.FrontEnd.GetTokens.Data; using Interpreter.Lib.IR.CheckSemantics.Types; namespace Interpreter.Lib.IR.CheckSemantics.Exceptions diff --git a/Interpreter.Lib/IR/CheckSemantics/Exceptions/CannotDefineType.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/CannotDefineType.cs index 399ba97d..0881f2dd 100644 --- a/Interpreter.Lib/IR/CheckSemantics/Exceptions/CannotDefineType.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/CannotDefineType.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.FrontEnd.GetTokens.Impl; +using Interpreter.Lib.FrontEnd.GetTokens.Data; namespace Interpreter.Lib.IR.CheckSemantics.Exceptions { diff --git a/Interpreter.Lib/IR/CheckSemantics/Exceptions/FunctionWithoutReturnStatement.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/FunctionWithoutReturnStatement.cs index 15f6bb17..7d1ffd9b 100644 --- a/Interpreter.Lib/IR/CheckSemantics/Exceptions/FunctionWithoutReturnStatement.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/FunctionWithoutReturnStatement.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.FrontEnd.GetTokens.Impl; +using Interpreter.Lib.FrontEnd.GetTokens.Data; namespace Interpreter.Lib.IR.CheckSemantics.Exceptions { diff --git a/Interpreter.Lib/IR/CheckSemantics/Exceptions/IncompatibleTypesOfOperands.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/IncompatibleTypesOfOperands.cs index 3853ec86..248be0fc 100644 --- a/Interpreter.Lib/IR/CheckSemantics/Exceptions/IncompatibleTypesOfOperands.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/IncompatibleTypesOfOperands.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.FrontEnd.GetTokens.Impl; +using Interpreter.Lib.FrontEnd.GetTokens.Data; using Interpreter.Lib.IR.CheckSemantics.Types; namespace Interpreter.Lib.IR.CheckSemantics.Exceptions diff --git a/Interpreter.Lib/IR/CheckSemantics/Exceptions/NotBooleanTestExpression.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/NotBooleanTestExpression.cs index eaa8740a..84d8e6f2 100644 --- a/Interpreter.Lib/IR/CheckSemantics/Exceptions/NotBooleanTestExpression.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/NotBooleanTestExpression.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.FrontEnd.GetTokens.Impl; +using Interpreter.Lib.FrontEnd.GetTokens.Data; using Interpreter.Lib.IR.CheckSemantics.Types; namespace Interpreter.Lib.IR.CheckSemantics.Exceptions diff --git a/Interpreter.Lib/IR/CheckSemantics/Exceptions/ObjectAccessException.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/ObjectAccessException.cs index 8a469c54..65c74162 100644 --- a/Interpreter.Lib/IR/CheckSemantics/Exceptions/ObjectAccessException.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/ObjectAccessException.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.FrontEnd.GetTokens.Impl; +using Interpreter.Lib.FrontEnd.GetTokens.Data; using Interpreter.Lib.IR.CheckSemantics.Types; namespace Interpreter.Lib.IR.CheckSemantics.Exceptions diff --git a/Interpreter.Lib/IR/CheckSemantics/Exceptions/OutsideOfLoop.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/OutsideOfLoop.cs index 59bd3cdc..3db001af 100644 --- a/Interpreter.Lib/IR/CheckSemantics/Exceptions/OutsideOfLoop.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/OutsideOfLoop.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.FrontEnd.GetTokens.Impl; +using Interpreter.Lib.FrontEnd.GetTokens.Data; namespace Interpreter.Lib.IR.CheckSemantics.Exceptions { diff --git a/Interpreter.Lib/IR/CheckSemantics/Exceptions/ReturnOutsideFunction.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/ReturnOutsideFunction.cs index fbdeb290..20d67a72 100644 --- a/Interpreter.Lib/IR/CheckSemantics/Exceptions/ReturnOutsideFunction.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/ReturnOutsideFunction.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.FrontEnd.GetTokens.Impl; +using Interpreter.Lib.FrontEnd.GetTokens.Data; namespace Interpreter.Lib.IR.CheckSemantics.Exceptions { diff --git a/Interpreter.Lib/IR/CheckSemantics/Exceptions/SemanticException.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/SemanticException.cs index fb7109a9..fa21ca96 100644 --- a/Interpreter.Lib/IR/CheckSemantics/Exceptions/SemanticException.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/SemanticException.cs @@ -1,5 +1,5 @@ using System; -using Interpreter.Lib.FrontEnd.GetTokens.Impl; +using Interpreter.Lib.FrontEnd.GetTokens.Data; namespace Interpreter.Lib.IR.CheckSemantics.Exceptions { diff --git a/Interpreter.Lib/IR/CheckSemantics/Exceptions/SymbolIsNotCallable.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/SymbolIsNotCallable.cs index fefca0f4..2fae5f0d 100644 --- a/Interpreter.Lib/IR/CheckSemantics/Exceptions/SymbolIsNotCallable.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/SymbolIsNotCallable.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.FrontEnd.GetTokens.Impl; +using Interpreter.Lib.FrontEnd.GetTokens.Data; namespace Interpreter.Lib.IR.CheckSemantics.Exceptions { diff --git a/Interpreter.Lib/IR/CheckSemantics/Exceptions/UnsupportedOperation.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/UnsupportedOperation.cs index 5e55f5f1..a875e1f6 100644 --- a/Interpreter.Lib/IR/CheckSemantics/Exceptions/UnsupportedOperation.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/UnsupportedOperation.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.FrontEnd.GetTokens.Impl; +using Interpreter.Lib.FrontEnd.GetTokens.Data; using Interpreter.Lib.IR.CheckSemantics.Types; namespace Interpreter.Lib.IR.CheckSemantics.Exceptions diff --git a/Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongArrayLiteralDeclaration.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongArrayLiteralDeclaration.cs index e7612a1e..4386f41e 100644 --- a/Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongArrayLiteralDeclaration.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongArrayLiteralDeclaration.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.FrontEnd.GetTokens.Impl; +using Interpreter.Lib.FrontEnd.GetTokens.Data; using Interpreter.Lib.IR.CheckSemantics.Types; namespace Interpreter.Lib.IR.CheckSemantics.Exceptions diff --git a/Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongConditionalTypes.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongConditionalTypes.cs index e45ccb32..6ea3a806 100644 --- a/Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongConditionalTypes.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongConditionalTypes.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.FrontEnd.GetTokens.Impl; +using Interpreter.Lib.FrontEnd.GetTokens.Data; using Interpreter.Lib.IR.CheckSemantics.Types; namespace Interpreter.Lib.IR.CheckSemantics.Exceptions diff --git a/Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongNumberOfArguments.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongNumberOfArguments.cs index 708b449d..490991a9 100644 --- a/Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongNumberOfArguments.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongNumberOfArguments.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.FrontEnd.GetTokens.Impl; +using Interpreter.Lib.FrontEnd.GetTokens.Data; namespace Interpreter.Lib.IR.CheckSemantics.Exceptions { diff --git a/Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongReturnType.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongReturnType.cs index e3bd5a80..617516b5 100644 --- a/Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongReturnType.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongReturnType.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.FrontEnd.GetTokens.Impl; +using Interpreter.Lib.FrontEnd.GetTokens.Data; using Interpreter.Lib.IR.CheckSemantics.Types; namespace Interpreter.Lib.IR.CheckSemantics.Exceptions diff --git a/Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongTypeOfArgument.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongTypeOfArgument.cs index ee996f7c..da00ce69 100644 --- a/Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongTypeOfArgument.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/WrongTypeOfArgument.cs @@ -1,4 +1,4 @@ -using Interpreter.Lib.FrontEnd.GetTokens.Impl; +using Interpreter.Lib.FrontEnd.GetTokens.Data; using Interpreter.Lib.IR.CheckSemantics.Types; namespace Interpreter.Lib.IR.CheckSemantics.Exceptions diff --git a/Interpreter.Lib/IR/CheckSemantics/Variables/SymbolTableUtils.cs b/Interpreter.Lib/IR/CheckSemantics/Variables/SymbolTableUtils.cs index 9a87f95c..448ba64f 100644 --- a/Interpreter.Lib/IR/CheckSemantics/Variables/SymbolTableUtils.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Variables/SymbolTableUtils.cs @@ -1,5 +1,5 @@ using System.Collections.Generic; -using Interpreter.Lib.FrontEnd.GetTokens.Impl; +using Interpreter.Lib.FrontEnd.GetTokens.Data; using Interpreter.Lib.IR.Ast.Nodes; using Interpreter.Lib.IR.Ast.Nodes.Declarations; using Interpreter.Lib.IR.Ast.Nodes.Statements; diff --git a/Interpreter.Tests/Unit/ParserTests.cs b/Interpreter.Tests/Unit/ParserTests.cs index 4da8cf9b..98074353 100644 --- a/Interpreter.Tests/Unit/ParserTests.cs +++ b/Interpreter.Tests/Unit/ParserTests.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using AutoMapper; +using Interpreter.Lib.FrontEnd.GetTokens.Data; using Interpreter.Lib.FrontEnd.GetTokens.Impl; using Interpreter.Lib.FrontEnd.TopDownParse; using Interpreter.Lib.FrontEnd.TopDownParse.Impl; diff --git a/Interpreter/MappingProfiles/StructureProfile.cs b/Interpreter/MappingProfiles/StructureProfile.cs index 97d32ec2..817f534c 100644 --- a/Interpreter/MappingProfiles/StructureProfile.cs +++ b/Interpreter/MappingProfiles/StructureProfile.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using AutoMapper; -using Interpreter.Lib.FrontEnd.GetTokens.Impl; -using Interpreter.Lib.FrontEnd.GetTokens.Impl.TokenTypes; +using Interpreter.Lib.FrontEnd.GetTokens.Data; +using Interpreter.Lib.FrontEnd.GetTokens.Data.TokenTypes; using Interpreter.Models; namespace Interpreter.MappingProfiles diff --git a/Interpreter/MappingProfiles/TokenTypeProfile.cs b/Interpreter/MappingProfiles/TokenTypeProfile.cs index d96961e2..bc7022a9 100644 --- a/Interpreter/MappingProfiles/TokenTypeProfile.cs +++ b/Interpreter/MappingProfiles/TokenTypeProfile.cs @@ -1,5 +1,5 @@ using AutoMapper; -using Interpreter.Lib.FrontEnd.GetTokens.Impl.TokenTypes; +using Interpreter.Lib.FrontEnd.GetTokens.Data.TokenTypes; using Interpreter.Models; namespace Interpreter.MappingProfiles diff --git a/Interpreter/Services/Providers/Impl/LexerProvider/LexerProvider.cs b/Interpreter/Services/Providers/Impl/LexerProvider/LexerProvider.cs index 95d235e9..ddfc7ddf 100644 --- a/Interpreter/Services/Providers/Impl/LexerProvider/LexerProvider.cs +++ b/Interpreter/Services/Providers/Impl/LexerProvider/LexerProvider.cs @@ -1,5 +1,6 @@ using AutoMapper; using Interpreter.Lib.FrontEnd.GetTokens; +using Interpreter.Lib.FrontEnd.GetTokens.Data; using Interpreter.Lib.FrontEnd.GetTokens.Impl; using Interpreter.Models; using Microsoft.Extensions.Options; diff --git a/Interpreter/Services/Providers/Impl/LexerProvider/LoggingLexer.cs b/Interpreter/Services/Providers/Impl/LexerProvider/LoggingLexer.cs index f31bc63e..472ef503 100644 --- a/Interpreter/Services/Providers/Impl/LexerProvider/LoggingLexer.cs +++ b/Interpreter/Services/Providers/Impl/LexerProvider/LoggingLexer.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using System.IO; using Interpreter.Lib.FrontEnd.GetTokens; -using Interpreter.Lib.FrontEnd.GetTokens.Impl; +using Interpreter.Lib.FrontEnd.GetTokens.Data; namespace Interpreter.Services.Providers.Impl.LexerProvider { From 81750d86a7a725bd2eb712092f8b289b7eba08f5 Mon Sep 17 00:00:00 2001 From: Stepami Date: Thu, 15 Sep 2022 12:48:50 +0300 Subject: [PATCH 32/56] =?UTF-8?q?=D1=80=D0=B5=D0=BE=D1=80=D0=B3=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20=D0=B1=D1=8D=D0=BA?= =?UTF-8?q?=D0=B5=D0=BD=D0=B4=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BackEnd/Instructions/AsString.cs | 1 - .../BackEnd/Instructions/BeginFunction.cs | 2 - .../BackEnd/Instructions/CallFunction.cs | 1 - .../BackEnd/Instructions/CreateArray.cs | 1 - .../BackEnd/Instructions/CreateObject.cs | 1 - .../BackEnd/Instructions/DotAssignment.cs | 1 - Interpreter.Lib/BackEnd/Instructions/Goto.cs | 2 - Interpreter.Lib/BackEnd/Instructions/Halt.cs | 2 - .../BackEnd/Instructions/IfNotGoto.cs | 1 - .../BackEnd/Instructions/IndexAssignment.cs | 1 - .../BackEnd/Instructions/Instruction.cs | 1 - Interpreter.Lib/BackEnd/Instructions/Print.cs | 1 - .../BackEnd/Instructions/PushParameter.cs | 1 - .../BackEnd/Instructions/RemoveFromArray.cs | 1 - .../BackEnd/Instructions/Return.cs | 1 - .../BackEnd/Instructions/Simple.cs | 1 - Interpreter.Lib/BackEnd/VM/Call.cs | 29 ------- Interpreter.Lib/BackEnd/VM/Frame.cs | 26 ------- Interpreter.Lib/BackEnd/VM/VirtualMachine.cs | 30 -------- Interpreter.Lib/BackEnd/Values/Constant.cs | 2 - Interpreter.Lib/BackEnd/Values/IValue.cs | 1 - Interpreter.Lib/BackEnd/Values/Name.cs | 2 - Interpreter.Lib/BackEnd/VirtualMachine.cs | 77 +++++++++++++++++++ .../Variables/Symbols/FunctionSymbol.cs | 2 +- .../Services/Executor/Impl/Executor.cs | 2 +- 25 files changed, 79 insertions(+), 111 deletions(-) delete mode 100644 Interpreter.Lib/BackEnd/VM/Call.cs delete mode 100644 Interpreter.Lib/BackEnd/VM/Frame.cs delete mode 100644 Interpreter.Lib/BackEnd/VM/VirtualMachine.cs create mode 100644 Interpreter.Lib/BackEnd/VirtualMachine.cs diff --git a/Interpreter.Lib/BackEnd/Instructions/AsString.cs b/Interpreter.Lib/BackEnd/Instructions/AsString.cs index bfe3da84..f33e971b 100644 --- a/Interpreter.Lib/BackEnd/Instructions/AsString.cs +++ b/Interpreter.Lib/BackEnd/Instructions/AsString.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using Interpreter.Lib.BackEnd.Values; -using Interpreter.Lib.BackEnd.VM; using Newtonsoft.Json; using Newtonsoft.Json.Serialization; diff --git a/Interpreter.Lib/BackEnd/Instructions/BeginFunction.cs b/Interpreter.Lib/BackEnd/Instructions/BeginFunction.cs index 9aeccb66..69da704b 100644 --- a/Interpreter.Lib/BackEnd/Instructions/BeginFunction.cs +++ b/Interpreter.Lib/BackEnd/Instructions/BeginFunction.cs @@ -1,5 +1,3 @@ -using Interpreter.Lib.BackEnd.VM; - namespace Interpreter.Lib.BackEnd.Instructions { public class BeginFunction : Instruction diff --git a/Interpreter.Lib/BackEnd/Instructions/CallFunction.cs b/Interpreter.Lib/BackEnd/Instructions/CallFunction.cs index a3a3127c..dd737278 100644 --- a/Interpreter.Lib/BackEnd/Instructions/CallFunction.cs +++ b/Interpreter.Lib/BackEnd/Instructions/CallFunction.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using Interpreter.Lib.BackEnd.VM; namespace Interpreter.Lib.BackEnd.Instructions { diff --git a/Interpreter.Lib/BackEnd/Instructions/CreateArray.cs b/Interpreter.Lib/BackEnd/Instructions/CreateArray.cs index 3e30a690..7f506a93 100644 --- a/Interpreter.Lib/BackEnd/Instructions/CreateArray.cs +++ b/Interpreter.Lib/BackEnd/Instructions/CreateArray.cs @@ -1,5 +1,4 @@ using System.Linq; -using Interpreter.Lib.BackEnd.VM; namespace Interpreter.Lib.BackEnd.Instructions { diff --git a/Interpreter.Lib/BackEnd/Instructions/CreateObject.cs b/Interpreter.Lib/BackEnd/Instructions/CreateObject.cs index aeb8392a..65e05eeb 100644 --- a/Interpreter.Lib/BackEnd/Instructions/CreateObject.cs +++ b/Interpreter.Lib/BackEnd/Instructions/CreateObject.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using Interpreter.Lib.BackEnd.VM; namespace Interpreter.Lib.BackEnd.Instructions { diff --git a/Interpreter.Lib/BackEnd/Instructions/DotAssignment.cs b/Interpreter.Lib/BackEnd/Instructions/DotAssignment.cs index 49e2115d..42121337 100644 --- a/Interpreter.Lib/BackEnd/Instructions/DotAssignment.cs +++ b/Interpreter.Lib/BackEnd/Instructions/DotAssignment.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using Interpreter.Lib.BackEnd.Values; -using Interpreter.Lib.BackEnd.VM; namespace Interpreter.Lib.BackEnd.Instructions { diff --git a/Interpreter.Lib/BackEnd/Instructions/Goto.cs b/Interpreter.Lib/BackEnd/Instructions/Goto.cs index d20e141f..96e03b9a 100644 --- a/Interpreter.Lib/BackEnd/Instructions/Goto.cs +++ b/Interpreter.Lib/BackEnd/Instructions/Goto.cs @@ -1,5 +1,3 @@ -using Interpreter.Lib.BackEnd.VM; - namespace Interpreter.Lib.BackEnd.Instructions { public class Goto : Instruction diff --git a/Interpreter.Lib/BackEnd/Instructions/Halt.cs b/Interpreter.Lib/BackEnd/Instructions/Halt.cs index 3aca0aa3..614a7a2f 100644 --- a/Interpreter.Lib/BackEnd/Instructions/Halt.cs +++ b/Interpreter.Lib/BackEnd/Instructions/Halt.cs @@ -1,5 +1,3 @@ -using Interpreter.Lib.BackEnd.VM; - namespace Interpreter.Lib.BackEnd.Instructions { public class Halt : Instruction diff --git a/Interpreter.Lib/BackEnd/Instructions/IfNotGoto.cs b/Interpreter.Lib/BackEnd/Instructions/IfNotGoto.cs index 234bccfd..6f275799 100644 --- a/Interpreter.Lib/BackEnd/Instructions/IfNotGoto.cs +++ b/Interpreter.Lib/BackEnd/Instructions/IfNotGoto.cs @@ -1,6 +1,5 @@ using System; using Interpreter.Lib.BackEnd.Values; -using Interpreter.Lib.BackEnd.VM; namespace Interpreter.Lib.BackEnd.Instructions { diff --git a/Interpreter.Lib/BackEnd/Instructions/IndexAssignment.cs b/Interpreter.Lib/BackEnd/Instructions/IndexAssignment.cs index c4bd3408..3865d73e 100644 --- a/Interpreter.Lib/BackEnd/Instructions/IndexAssignment.cs +++ b/Interpreter.Lib/BackEnd/Instructions/IndexAssignment.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using Interpreter.Lib.BackEnd.Values; -using Interpreter.Lib.BackEnd.VM; namespace Interpreter.Lib.BackEnd.Instructions { diff --git a/Interpreter.Lib/BackEnd/Instructions/Instruction.cs b/Interpreter.Lib/BackEnd/Instructions/Instruction.cs index 992803b7..8c8443da 100644 --- a/Interpreter.Lib/BackEnd/Instructions/Instruction.cs +++ b/Interpreter.Lib/BackEnd/Instructions/Instruction.cs @@ -1,5 +1,4 @@ using System; -using Interpreter.Lib.BackEnd.VM; namespace Interpreter.Lib.BackEnd.Instructions { diff --git a/Interpreter.Lib/BackEnd/Instructions/Print.cs b/Interpreter.Lib/BackEnd/Instructions/Print.cs index 38f27f05..934a44dd 100644 --- a/Interpreter.Lib/BackEnd/Instructions/Print.cs +++ b/Interpreter.Lib/BackEnd/Instructions/Print.cs @@ -1,5 +1,4 @@ using Interpreter.Lib.BackEnd.Values; -using Interpreter.Lib.BackEnd.VM; namespace Interpreter.Lib.BackEnd.Instructions { diff --git a/Interpreter.Lib/BackEnd/Instructions/PushParameter.cs b/Interpreter.Lib/BackEnd/Instructions/PushParameter.cs index 4dde6d8e..97358e4c 100644 --- a/Interpreter.Lib/BackEnd/Instructions/PushParameter.cs +++ b/Interpreter.Lib/BackEnd/Instructions/PushParameter.cs @@ -1,5 +1,4 @@ using Interpreter.Lib.BackEnd.Values; -using Interpreter.Lib.BackEnd.VM; namespace Interpreter.Lib.BackEnd.Instructions { diff --git a/Interpreter.Lib/BackEnd/Instructions/RemoveFromArray.cs b/Interpreter.Lib/BackEnd/Instructions/RemoveFromArray.cs index aead4904..11f65e17 100644 --- a/Interpreter.Lib/BackEnd/Instructions/RemoveFromArray.cs +++ b/Interpreter.Lib/BackEnd/Instructions/RemoveFromArray.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using Interpreter.Lib.BackEnd.Values; -using Interpreter.Lib.BackEnd.VM; namespace Interpreter.Lib.BackEnd.Instructions { diff --git a/Interpreter.Lib/BackEnd/Instructions/Return.cs b/Interpreter.Lib/BackEnd/Instructions/Return.cs index 1948a6cc..b1355aaa 100644 --- a/Interpreter.Lib/BackEnd/Instructions/Return.cs +++ b/Interpreter.Lib/BackEnd/Instructions/Return.cs @@ -1,7 +1,6 @@ using System.Collections; using System.Collections.Generic; using Interpreter.Lib.BackEnd.Values; -using Interpreter.Lib.BackEnd.VM; namespace Interpreter.Lib.BackEnd.Instructions { diff --git a/Interpreter.Lib/BackEnd/Instructions/Simple.cs b/Interpreter.Lib/BackEnd/Instructions/Simple.cs index 084b56f7..7ad6d5b4 100644 --- a/Interpreter.Lib/BackEnd/Instructions/Simple.cs +++ b/Interpreter.Lib/BackEnd/Instructions/Simple.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using Interpreter.Lib.BackEnd.Values; -using Interpreter.Lib.BackEnd.VM; namespace Interpreter.Lib.BackEnd.Instructions { diff --git a/Interpreter.Lib/BackEnd/VM/Call.cs b/Interpreter.Lib/BackEnd/VM/Call.cs deleted file mode 100644 index 001be86b..00000000 --- a/Interpreter.Lib/BackEnd/VM/Call.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System.Collections.Generic; -using System.Linq; - -namespace Interpreter.Lib.BackEnd.VM -{ - public record Call( - int From, FunctionInfo To, - List<(string Id, object Value)> Parameters, - string Where = null) - { - public override string ToString() => - $"{From} => {To.Location}: {To.Id}({string.Join(", ", Parameters.Select(x => $"{x.Id}: {x.Value}"))})"; - } - - public record FunctionInfo(string Id, int Location = 0, string MethodOf = null) - { - public int Location { get; set; } = Location; - - public string MethodOf { get; set; } = MethodOf; - - public string CallId() => - MethodOf == null - ? Id - : $"{MethodOf}.{Id}"; - - public override string ToString() => - $"({Location}, {CallId()})"; - } -} \ No newline at end of file diff --git a/Interpreter.Lib/BackEnd/VM/Frame.cs b/Interpreter.Lib/BackEnd/VM/Frame.cs deleted file mode 100644 index 3d91567b..00000000 --- a/Interpreter.Lib/BackEnd/VM/Frame.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Collections.Generic; - -namespace Interpreter.Lib.BackEnd.VM -{ - public class Frame - { - private readonly Dictionary _variables = new(); - private readonly Frame _parentFrame; - - public int ReturnAddress { get; } - - public Frame(int returnAddress = 0, Frame parentFrame = null) - { - ReturnAddress = returnAddress; - _parentFrame = parentFrame; - } - - public object this[string id] - { - get => _variables.ContainsKey(id) - ? _variables[id] - : _parentFrame?[id]; - set => _variables[id] = value; - } - } -} \ No newline at end of file diff --git a/Interpreter.Lib/BackEnd/VM/VirtualMachine.cs b/Interpreter.Lib/BackEnd/VM/VirtualMachine.cs deleted file mode 100644 index 741d6bdf..00000000 --- a/Interpreter.Lib/BackEnd/VM/VirtualMachine.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using Interpreter.Lib.BackEnd.Instructions; - -namespace Interpreter.Lib.BackEnd.VM -{ - public record VirtualMachine( - Stack CallStack, Stack Frames, - Stack<(string Id, object Value)> Arguments, - TextWriter Writer - ) - { - public VirtualMachine() : - this(new(), new(), new(), Console.Out) { } - - public void Run(List instructions) - { - Frames.Push(new Frame()); - - var address = 0; - while (!instructions[address].End()) - { - var instruction = instructions[address]; - var jump = instruction.Execute(this); - address = jump; - } - } - } -} \ No newline at end of file diff --git a/Interpreter.Lib/BackEnd/Values/Constant.cs b/Interpreter.Lib/BackEnd/Values/Constant.cs index 0b41b0e6..70c87341 100644 --- a/Interpreter.Lib/BackEnd/Values/Constant.cs +++ b/Interpreter.Lib/BackEnd/Values/Constant.cs @@ -1,5 +1,3 @@ -using Interpreter.Lib.BackEnd.VM; - namespace Interpreter.Lib.BackEnd.Values { public class Constant : IValue diff --git a/Interpreter.Lib/BackEnd/Values/IValue.cs b/Interpreter.Lib/BackEnd/Values/IValue.cs index 5775e4de..06255e67 100644 --- a/Interpreter.Lib/BackEnd/Values/IValue.cs +++ b/Interpreter.Lib/BackEnd/Values/IValue.cs @@ -1,5 +1,4 @@ using System; -using Interpreter.Lib.BackEnd.VM; namespace Interpreter.Lib.BackEnd.Values { diff --git a/Interpreter.Lib/BackEnd/Values/Name.cs b/Interpreter.Lib/BackEnd/Values/Name.cs index 4e897875..7c01b685 100644 --- a/Interpreter.Lib/BackEnd/Values/Name.cs +++ b/Interpreter.Lib/BackEnd/Values/Name.cs @@ -1,5 +1,3 @@ -using Interpreter.Lib.BackEnd.VM; - namespace Interpreter.Lib.BackEnd.Values { public class Name : IValue diff --git a/Interpreter.Lib/BackEnd/VirtualMachine.cs b/Interpreter.Lib/BackEnd/VirtualMachine.cs new file mode 100644 index 00000000..52822d39 --- /dev/null +++ b/Interpreter.Lib/BackEnd/VirtualMachine.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Interpreter.Lib.BackEnd.Instructions; + +namespace Interpreter.Lib.BackEnd +{ + public record VirtualMachine( + Stack CallStack, Stack Frames, + Stack<(string Id, object Value)> Arguments, + TextWriter Writer + ) + { + public VirtualMachine() : + this(new(), new(), new(), Console.Out) { } + + public void Run(List instructions) + { + Frames.Push(new Frame()); + + var address = 0; + while (!instructions[address].End()) + { + var instruction = instructions[address]; + var jump = instruction.Execute(this); + address = jump; + } + } + } + + public record Call( + int From, FunctionInfo To, + List<(string Id, object Value)> Parameters, + string Where = null) + { + public override string ToString() => + $"{From} => {To.Location}: {To.Id}({string.Join(", ", Parameters.Select(x => $"{x.Id}: {x.Value}"))})"; + } + + public record FunctionInfo(string Id, int Location = 0, string MethodOf = null) + { + public int Location { get; set; } = Location; + + public string MethodOf { get; set; } = MethodOf; + + public string CallId() => + MethodOf == null + ? Id + : $"{MethodOf}.{Id}"; + + public override string ToString() => + $"({Location}, {CallId()})"; + } + + public class Frame + { + private readonly Dictionary _variables = new(); + private readonly Frame _parentFrame; + + public int ReturnAddress { get; } + + public Frame(int returnAddress = 0, Frame parentFrame = null) + { + ReturnAddress = returnAddress; + _parentFrame = parentFrame; + } + + public object this[string id] + { + get => _variables.ContainsKey(id) + ? _variables[id] + : _parentFrame?[id]; + set => _variables[id] = value; + } + } +} \ No newline at end of file diff --git a/Interpreter.Lib/IR/CheckSemantics/Variables/Symbols/FunctionSymbol.cs b/Interpreter.Lib/IR/CheckSemantics/Variables/Symbols/FunctionSymbol.cs index 34b90c57..ad794443 100644 --- a/Interpreter.Lib/IR/CheckSemantics/Variables/Symbols/FunctionSymbol.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Variables/Symbols/FunctionSymbol.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; using System.Text; -using Interpreter.Lib.BackEnd.VM; +using Interpreter.Lib.BackEnd; using Interpreter.Lib.IR.Ast.Nodes.Declarations; using Interpreter.Lib.IR.CheckSemantics.Types; diff --git a/Interpreter/Services/Executor/Impl/Executor.cs b/Interpreter/Services/Executor/Impl/Executor.cs index 3be768bf..53ac4d90 100644 --- a/Interpreter/Services/Executor/Impl/Executor.cs +++ b/Interpreter/Services/Executor/Impl/Executor.cs @@ -1,5 +1,5 @@ using System; -using Interpreter.Lib.BackEnd.VM; +using Interpreter.Lib.BackEnd; using Interpreter.Lib.FrontEnd.GetTokens; using Interpreter.Lib.FrontEnd.TopDownParse; using Interpreter.Lib.IR.CheckSemantics.Exceptions; From 5045e3a7630bbe62b4dd3e218f442c71710b459c Mon Sep 17 00:00:00 2001 From: Stepami Date: Thu, 15 Sep 2022 12:58:43 +0300 Subject: [PATCH 33/56] =?UTF-8?q?=D1=80=D0=B5=D1=84=D0=B0=D0=BA=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=B8=D0=BD=D0=B3=20=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=B8=20=D1=81=D0=B8=D0=BC=D0=B2=D0=BE=D0=BB=D0=BE=D0=B2=20?= =?UTF-8?q?=D0=B8=20=D0=B8=D1=81=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D0=B5=D0=BC=20=D0=BA=D0=BE=D0=B2=D0=B0=D1=80?= =?UTF-8?q?=D0=B8=D0=B0=D0=BD=D1=82=D0=BD=D1=8B=D1=85=20=D0=B2=D0=BE=D1=85?= =?UTF-8?q?=D0=B2=D1=80=D0=B0=D1=89=D0=B0=D0=B5=D0=BC=D1=8B=D1=85=20=D1=82?= =?UTF-8?q?=D0=B8=D0=BF=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Interpreter.Lib/FrontEnd/TopDownParse/Impl/Parser.cs | 12 +++--------- .../IR/Ast/Nodes/Expressions/AssignmentExpression.cs | 10 +++------- .../Expressions/ComplexLiterals/ObjectLiteral.cs | 11 ++++------- .../IR/CheckSemantics/Variables/SymbolTableUtils.cs | 5 +---- .../Variables/Symbols/FunctionSymbol.cs | 5 +++-- .../CheckSemantics/Variables/Symbols/ObjectSymbol.cs | 12 ++++++++---- .../IR/CheckSemantics/Variables/Symbols/Symbol.cs | 10 ++++++---- .../Variables/Symbols/VariableSymbol.cs | 7 ++----- 8 files changed, 30 insertions(+), 42 deletions(-) diff --git a/Interpreter.Lib/FrontEnd/TopDownParse/Impl/Parser.cs b/Interpreter.Lib/FrontEnd/TopDownParse/Impl/Parser.cs index 708a9927..54db4d63 100644 --- a/Interpreter.Lib/FrontEnd/TopDownParse/Impl/Parser.cs +++ b/Interpreter.Lib/FrontEnd/TopDownParse/Impl/Parser.cs @@ -354,10 +354,7 @@ private FunctionDeclaration FunctionDeclaration(SymbolTable table) var arg = Expect("Ident").Value; Expect("Colon"); var type = TypeValue(table); - args.Add(new VariableSymbol(arg) - { - Type = type - }); + args.Add(new VariableSymbol(arg, type)); } while (CurrentIs("Comma")) @@ -366,10 +363,7 @@ private FunctionDeclaration FunctionDeclaration(SymbolTable table) var arg = Expect("Ident").Value; Expect("Colon"); var type = TypeValue(table); - args.Add(new VariableSymbol(arg) - { - Type = type - }); + args.Add(new VariableSymbol(arg, type)); } Expect("RightParen"); @@ -788,7 +782,7 @@ private ObjectLiteral ObjectLiteral(SymbolTable table) var name = Expect("Ident").Value; Expect("Colon"); var type = TypeValue(newTable); - args.Add(new VariableSymbol(name) {Type = type}); + args.Add(new VariableSymbol(name, type)); if (!CurrentIs("RightParen")) { Expect("Comma"); diff --git a/Interpreter.Lib/IR/Ast/Nodes/Expressions/AssignmentExpression.cs b/Interpreter.Lib/IR/Ast/Nodes/Expressions/AssignmentExpression.cs index 214b25da..e872c5ca 100644 --- a/Interpreter.Lib/IR/Ast/Nodes/Expressions/AssignmentExpression.cs +++ b/Interpreter.Lib/IR/Ast/Nodes/Expressions/AssignmentExpression.cs @@ -63,20 +63,16 @@ internal override Type NodeCheck() var typeOfSymbol = _destinationType != null && type.Equals(TypeUtils.JavaScriptTypes.Undefined) ? _destinationType : type; - if (typeOfSymbol is ObjectType) + if (typeOfSymbol is ObjectType objectTypeOfSymbol) { - SymbolTable.AddSymbol(new ObjectSymbol(id, declaration.Const(), _source.SymbolTable, typeOfSymbol) + SymbolTable.AddSymbol(new ObjectSymbol(id, objectTypeOfSymbol, declaration.Const(), _source.SymbolTable) { - Type = typeOfSymbol, Table = _source.SymbolTable }); } else { - SymbolTable.AddSymbol(new VariableSymbol(id, declaration.Const()) - { - Type = typeOfSymbol - }); + SymbolTable.AddSymbol(new VariableSymbol(id, typeOfSymbol, declaration.Const())); } } else diff --git a/Interpreter.Lib/IR/Ast/Nodes/Expressions/ComplexLiterals/ObjectLiteral.cs b/Interpreter.Lib/IR/Ast/Nodes/Expressions/ComplexLiterals/ObjectLiteral.cs index 6a58e1bc..8ce598a1 100644 --- a/Interpreter.Lib/IR/Ast/Nodes/Expressions/ComplexLiterals/ObjectLiteral.cs +++ b/Interpreter.Lib/IR/Ast/Nodes/Expressions/ComplexLiterals/ObjectLiteral.cs @@ -30,9 +30,9 @@ internal override Type NodeCheck() { var propType = prop.Expression.NodeCheck(); propertyTypes.Add(new PropertyType(prop.Id.Id, propType)); - prop.Id.SymbolTable.AddSymbol(propType is ObjectType - ? new ObjectSymbol(prop.Id.Id) {Type = propType, Table = prop.Expression.SymbolTable} - : new VariableSymbol(prop.Id.Id) {Type = propType} + prop.Id.SymbolTable.AddSymbol(propType is ObjectType objectType + ? new ObjectSymbol(prop.Id.Id, objectType) {Table = prop.Expression.SymbolTable} + : new VariableSymbol(prop.Id.Id, propType) ); }); _methods.ForEach(m => @@ -41,10 +41,7 @@ internal override Type NodeCheck() propertyTypes.Add(new PropertyType(symbol.Id, symbol.Type)); }); var type = new ObjectType(propertyTypes); - SymbolTable.AddSymbol(new VariableSymbol("this", true) - { - Type = type - }); + SymbolTable.AddSymbol(new VariableSymbol("this", type, true)); return type; } diff --git a/Interpreter.Lib/IR/CheckSemantics/Variables/SymbolTableUtils.cs b/Interpreter.Lib/IR/CheckSemantics/Variables/SymbolTableUtils.cs index 448ba64f..97e42065 100644 --- a/Interpreter.Lib/IR/CheckSemantics/Variables/SymbolTableUtils.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Variables/SymbolTableUtils.cs @@ -24,10 +24,7 @@ public static SymbolTable GetStandardLibrary() "print", new List { - new VariableSymbol("str") - { - Type = TypeUtils.JavaScriptTypes.String - } + new VariableSymbol("str", TypeUtils.JavaScriptTypes.String) }, new FunctionType(TypeUtils.JavaScriptTypes.Void, new[] {TypeUtils.JavaScriptTypes.String}) ); diff --git a/Interpreter.Lib/IR/CheckSemantics/Variables/Symbols/FunctionSymbol.cs b/Interpreter.Lib/IR/CheckSemantics/Variables/Symbols/FunctionSymbol.cs index ad794443..1cc2f38c 100644 --- a/Interpreter.Lib/IR/CheckSemantics/Variables/Symbols/FunctionSymbol.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Variables/Symbols/FunctionSymbol.cs @@ -8,7 +8,7 @@ namespace Interpreter.Lib.IR.CheckSemantics.Variables.Symbols { public class FunctionSymbol : Symbol { - public FunctionType Type { get; } + public override FunctionType Type { get; } public List Parameters { get; } @@ -16,7 +16,8 @@ public class FunctionSymbol : Symbol public FunctionInfo CallInfo { get; } - public FunctionSymbol(string id, IEnumerable parameters, FunctionType type) : base(id) + public FunctionSymbol(string id, IEnumerable parameters, FunctionType type) : + base(id, type) { Parameters = new List(parameters); CallInfo = new FunctionInfo(id); diff --git a/Interpreter.Lib/IR/CheckSemantics/Variables/Symbols/ObjectSymbol.cs b/Interpreter.Lib/IR/CheckSemantics/Variables/Symbols/ObjectSymbol.cs index a0646feb..5f3906d3 100644 --- a/Interpreter.Lib/IR/CheckSemantics/Variables/Symbols/ObjectSymbol.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Variables/Symbols/ObjectSymbol.cs @@ -4,9 +4,15 @@ namespace Interpreter.Lib.IR.CheckSemantics.Variables.Symbols { public class ObjectSymbol : VariableSymbol { - public ObjectSymbol(string id, bool readOnly = false, SymbolTable table = null, Type type = null) : base(id, readOnly) + public override ObjectType Type { get; } + + public SymbolTable Table { get; init; } + + public ObjectSymbol(string id, ObjectType objectType, bool readOnly = false, SymbolTable table = null) : + base(id, objectType, readOnly) { - if (table != null && type is ObjectType objectType) + Type = objectType; + if (table != null) { foreach (var key in objectType.Keys) { @@ -18,7 +24,5 @@ public ObjectSymbol(string id, bool readOnly = false, SymbolTable table = null, } } } - - public SymbolTable Table { get; init; } } } \ No newline at end of file diff --git a/Interpreter.Lib/IR/CheckSemantics/Variables/Symbols/Symbol.cs b/Interpreter.Lib/IR/CheckSemantics/Variables/Symbols/Symbol.cs index 2fa06b36..8a14e05a 100644 --- a/Interpreter.Lib/IR/CheckSemantics/Variables/Symbols/Symbol.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Variables/Symbols/Symbol.cs @@ -1,13 +1,15 @@ +using Interpreter.Lib.IR.CheckSemantics.Types; + namespace Interpreter.Lib.IR.CheckSemantics.Variables.Symbols { public abstract class Symbol { // ReSharper disable once VirtualMemberNeverOverridden.Global public virtual string Id { get; } + + public virtual Type Type { get; } - protected Symbol(string id) - { - Id = id; - } + protected Symbol(string id, Type type) => + (Id, Type) = (id, type); } } \ No newline at end of file diff --git a/Interpreter.Lib/IR/CheckSemantics/Variables/Symbols/VariableSymbol.cs b/Interpreter.Lib/IR/CheckSemantics/Variables/Symbols/VariableSymbol.cs index 98b4c42b..37e29f0e 100644 --- a/Interpreter.Lib/IR/CheckSemantics/Variables/Symbols/VariableSymbol.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Variables/Symbols/VariableSymbol.cs @@ -4,14 +4,11 @@ namespace Interpreter.Lib.IR.CheckSemantics.Variables.Symbols { public class VariableSymbol : Symbol { - public Type Type { get; init; } - public bool ReadOnly { get; } - public VariableSymbol(string id, bool readOnly = false) : base(id) - { + public VariableSymbol(string id, Type type, bool readOnly = false) : + base(id, type) => ReadOnly = readOnly; - } public override string ToString() => $"{(ReadOnly ? "const " : "")}{Id}: {Type}"; } From da45269f6bb2bb8448fc3411da16dbf3eee8544d Mon Sep 17 00:00:00 2001 From: Stepami Date: Thu, 15 Sep 2022 13:19:58 +0300 Subject: [PATCH 34/56] lexer tests --- .../FrontEnd/GetTokens/Data/Token.cs | 4 +++ Interpreter.Tests/Stubs/MapperStub.cs | 18 ++++++++++++ .../TestData/LexerSuccessData.cs | 17 +++++++++++ Interpreter.Tests/Unit/FrontEnd/LexerTests.cs | 28 +++++++++++++++++++ Interpreter.Tests/Unit/ParserTests.cs | 12 ++------ 5 files changed, 69 insertions(+), 10 deletions(-) create mode 100644 Interpreter.Tests/Stubs/MapperStub.cs create mode 100644 Interpreter.Tests/TestData/LexerSuccessData.cs create mode 100644 Interpreter.Tests/Unit/FrontEnd/LexerTests.cs diff --git a/Interpreter.Lib/FrontEnd/GetTokens/Data/Token.cs b/Interpreter.Lib/FrontEnd/GetTokens/Data/Token.cs index 3ff1d963..51fabb34 100644 --- a/Interpreter.Lib/FrontEnd/GetTokens/Data/Token.cs +++ b/Interpreter.Lib/FrontEnd/GetTokens/Data/Token.cs @@ -1,9 +1,11 @@ using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Text.RegularExpressions; using Interpreter.Lib.FrontEnd.GetTokens.Data.TokenTypes; namespace Interpreter.Lib.FrontEnd.GetTokens.Data { + [ExcludeFromCodeCoverage] public record Token(TokenType Type) { public Segment Segment { get; } @@ -23,6 +25,7 @@ public override string ToString() } } + [ExcludeFromCodeCoverage] public record Segment(Coordinates Start, Coordinates End) { public override string ToString() => $"{Start}-{End}"; @@ -31,6 +34,7 @@ public record Segment(Coordinates Start, Coordinates End) new(left.Start, right.End); } + [ExcludeFromCodeCoverage] public record Coordinates(int Line, int Column) { public Coordinates(int absolutePos, IReadOnlyList system) : diff --git a/Interpreter.Tests/Stubs/MapperStub.cs b/Interpreter.Tests/Stubs/MapperStub.cs new file mode 100644 index 00000000..1a1cdb9c --- /dev/null +++ b/Interpreter.Tests/Stubs/MapperStub.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using AutoMapper; +using Interpreter.MappingProfiles; + +namespace Interpreter.Tests.Stubs +{ + public class MapperStub : Mapper + { + public MapperStub() : base(new MapperConfiguration( + x => x.AddProfiles(new List + { + new TokenTypeProfile(), + new StructureProfile() + }) + )) { } + } +} \ No newline at end of file diff --git a/Interpreter.Tests/TestData/LexerSuccessData.cs b/Interpreter.Tests/TestData/LexerSuccessData.cs new file mode 100644 index 00000000..926d4c37 --- /dev/null +++ b/Interpreter.Tests/TestData/LexerSuccessData.cs @@ -0,0 +1,17 @@ +using System.Collections; +using System.Collections.Generic; + +namespace Interpreter.Tests.TestData +{ + public class LexerSuccessData : IEnumerable + { + public IEnumerator GetEnumerator() + { + yield return new object[] { "a + b - c return while do" }; + yield return new object[] { "=> abc null true false" }; + yield return new object[] { "{ . } , ( ) [] =?:" }; + } + + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + } +} \ No newline at end of file diff --git a/Interpreter.Tests/Unit/FrontEnd/LexerTests.cs b/Interpreter.Tests/Unit/FrontEnd/LexerTests.cs new file mode 100644 index 00000000..1f8fdac1 --- /dev/null +++ b/Interpreter.Tests/Unit/FrontEnd/LexerTests.cs @@ -0,0 +1,28 @@ +using Interpreter.Lib.FrontEnd.GetTokens.Data; +using Interpreter.Lib.FrontEnd.GetTokens.Impl; +using Interpreter.Models; +using Interpreter.Tests.Stubs; +using Interpreter.Tests.TestData; +using Xunit; + +namespace Interpreter.Tests.Unit.FrontEnd +{ + public class LexerTests + { + private readonly Lexer _lexer; + + public LexerTests() + { + var mapper = new MapperStub(); + _lexer = new Lexer(mapper.Map(new())); + } + + [Theory] + [ClassData(typeof(LexerSuccessData))] + public void LexerDoesNotThrowTest(string text) + { + var ex = Record.Exception(() => _lexer.GetTokens(text)); + Assert.Null(ex); + } + } +} \ No newline at end of file diff --git a/Interpreter.Tests/Unit/ParserTests.cs b/Interpreter.Tests/Unit/ParserTests.cs index 98074353..12033624 100644 --- a/Interpreter.Tests/Unit/ParserTests.cs +++ b/Interpreter.Tests/Unit/ParserTests.cs @@ -1,11 +1,9 @@ -using System.Collections.Generic; -using AutoMapper; using Interpreter.Lib.FrontEnd.GetTokens.Data; using Interpreter.Lib.FrontEnd.GetTokens.Impl; using Interpreter.Lib.FrontEnd.TopDownParse; using Interpreter.Lib.FrontEnd.TopDownParse.Impl; -using Interpreter.MappingProfiles; using Interpreter.Models; +using Interpreter.Tests.Stubs; using Interpreter.Tests.TestData; using Xunit; @@ -17,13 +15,7 @@ public class ParserTests public ParserTests() { - IMapper mapper = new Mapper(new MapperConfiguration( - x => x.AddProfiles(new List - { - new TokenTypeProfile(), - new StructureProfile() - }) - )); + var mapper = new MapperStub(); _parser = new Parser(new Lexer( mapper.Map(new()) From ef086a942a08b55304348f3583c181a52b527dd5 Mon Sep 17 00:00:00 2001 From: Stepami Date: Thu, 15 Sep 2022 13:24:59 +0300 Subject: [PATCH 35/56] fix tests --- Interpreter.Tests/Unit/AstNodeTests.cs | 4 ++-- Interpreter.Tests/Unit/SymbolTableTests.cs | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Interpreter.Tests/Unit/AstNodeTests.cs b/Interpreter.Tests/Unit/AstNodeTests.cs index 0f889967..92ff8f0c 100644 --- a/Interpreter.Tests/Unit/AstNodeTests.cs +++ b/Interpreter.Tests/Unit/AstNodeTests.cs @@ -15,7 +15,7 @@ public class AstNodeTests public void PrecedenceTest() { var fType = new Mock(new Mock("").Object, new List()); - var funcSymbol = new Mock("f", new List(), fType.Object); + var funcSymbol = new FunctionSymbol("f", new List(), fType.Object); var lexicalDecl = new LexicalDeclaration(false); var stmtItemList = new List @@ -23,7 +23,7 @@ public void PrecedenceTest() lexicalDecl }; // ReSharper disable once UnusedVariable - var func = new FunctionDeclaration(funcSymbol.Object, new BlockStatement(stmtItemList)); + var func = new FunctionDeclaration(funcSymbol, new BlockStatement(stmtItemList)); Assert.True(lexicalDecl.ChildOf()); } diff --git a/Interpreter.Tests/Unit/SymbolTableTests.cs b/Interpreter.Tests/Unit/SymbolTableTests.cs index 3a441731..f1b1d917 100644 --- a/Interpreter.Tests/Unit/SymbolTableTests.cs +++ b/Interpreter.Tests/Unit/SymbolTableTests.cs @@ -6,6 +6,7 @@ using Interpreter.Lib.IR.CheckSemantics.Variables.Symbols; using Moq; using Xunit; +using Type = Interpreter.Lib.IR.CheckSemantics.Types.Type; namespace Interpreter.Tests.Unit { @@ -15,9 +16,11 @@ public class SymbolTableTests public void FindSymbolTest() { const string id = "ident"; + var type = new Mock(id); - var symbol = new Mock(id); + var symbol = new Mock(id, type.Object); symbol.Setup(s => s.Id).Returns(id); + symbol.Setup(s => s.Type).Returns(type.Object); var outerScope = new SymbolTable(); var innerScope = new SymbolTable(); @@ -45,9 +48,11 @@ public void FlatteningScopeTest() script.ToList().ForEach(node => node.SymbolTable = table); const string id = "ident"; + var type = new Mock(id); - var symbol = new Mock(id); + var symbol = new Mock(id, type.Object); symbol.Setup(s => s.Id).Returns(id); + symbol.Setup(s => s.Type).Returns(type.Object); script.SymbolTable.AddSymbol(symbol.Object); From 66f81f37b86265eb8332428bf6449eaa6b3a60e9 Mon Sep 17 00:00:00 2001 From: Stepami Date: Thu, 15 Sep 2022 13:38:44 +0300 Subject: [PATCH 36/56] more lexer tests --- .../FrontEnd/GetTokens/Impl/Lexer.cs | 17 ++++++++------ .../{LexerSuccessData.cs => LexerData.cs} | 12 ++++++++++ Interpreter.Tests/Unit/FrontEnd/LexerTests.cs | 23 ++++++++++++++++--- 3 files changed, 42 insertions(+), 10 deletions(-) rename Interpreter.Tests/TestData/{LexerSuccessData.cs => LexerData.cs} (58%) diff --git a/Interpreter.Lib/FrontEnd/GetTokens/Impl/Lexer.cs b/Interpreter.Lib/FrontEnd/GetTokens/Impl/Lexer.cs index 2fb79d58..3f0ce8d3 100644 --- a/Interpreter.Lib/FrontEnd/GetTokens/Impl/Lexer.cs +++ b/Interpreter.Lib/FrontEnd/GetTokens/Impl/Lexer.cs @@ -22,13 +22,16 @@ public List GetTokens(string text) _text = text; _lines.Clear(); - var lineMatches = - new Regex(@"(?\n)").Matches(text[^1] == '\n' - ? text - : new string(text.Append('\n').ToArray())); - foreach (Match match in lineMatches) - _lines.Add(match.Groups["NEWLINE"].Index); - + if (!string.IsNullOrEmpty(text)) + { + var lineMatches = + new Regex(@"(?\n)").Matches(text[^1] == '\n' + ? text + : new string(text.Append('\n').ToArray())); + foreach (Match match in lineMatches) + _lines.Add(match.Groups["NEWLINE"].Index); + } + return this.Where(t => !t.Type.WhiteSpace()).ToList(); } diff --git a/Interpreter.Tests/TestData/LexerSuccessData.cs b/Interpreter.Tests/TestData/LexerData.cs similarity index 58% rename from Interpreter.Tests/TestData/LexerSuccessData.cs rename to Interpreter.Tests/TestData/LexerData.cs index 926d4c37..b597294c 100644 --- a/Interpreter.Tests/TestData/LexerSuccessData.cs +++ b/Interpreter.Tests/TestData/LexerData.cs @@ -14,4 +14,16 @@ public IEnumerator GetEnumerator() IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } + + public class LexerFailData : IEnumerable + { + public IEnumerator GetEnumerator() + { + yield return new object[] { "a + v $$$" }; + yield return new object[] { "kkk &" }; + yield return new object[] { "|| |" }; + } + + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + } } \ No newline at end of file diff --git a/Interpreter.Tests/Unit/FrontEnd/LexerTests.cs b/Interpreter.Tests/Unit/FrontEnd/LexerTests.cs index 1f8fdac1..f65651b6 100644 --- a/Interpreter.Tests/Unit/FrontEnd/LexerTests.cs +++ b/Interpreter.Tests/Unit/FrontEnd/LexerTests.cs @@ -1,3 +1,5 @@ +using System.Linq; +using Interpreter.Lib.FrontEnd.GetTokens; using Interpreter.Lib.FrontEnd.GetTokens.Data; using Interpreter.Lib.FrontEnd.GetTokens.Impl; using Interpreter.Models; @@ -19,10 +21,25 @@ public LexerTests() [Theory] [ClassData(typeof(LexerSuccessData))] - public void LexerDoesNotThrowTest(string text) + public void LexerDoesNotThrowTest(string text) => + Assert.Null(Record.Exception(() => _lexer.GetTokens(text))); + + [Theory] + [ClassData(typeof(LexerFailData))] + public void LexerThrowsErrorTest(string text) => + Assert.Throws(() => _lexer.GetTokens(text)); + + [Fact] + public void LexerToStringCorrectTest() { - var ex = Record.Exception(() => _lexer.GetTokens(text)); - Assert.Null(ex); + const string text = "8"; + var tokens = _lexer.GetTokens(text); + Assert.Contains("EOP", _lexer.ToString()); + Assert.Equal("IntegerLiteral (1, 1)-(1, 2): 8", tokens.First().ToString()); } + + [Fact] + public void EmptyTextTest() => + Assert.NotEmpty(_lexer.GetTokens("")); } } \ No newline at end of file From fd7d472ec9fc0090600d280e421372f80d75f62b Mon Sep 17 00:00:00 2001 From: Stepami Date: Thu, 15 Sep 2022 13:56:31 +0300 Subject: [PATCH 37/56] StructureTests.cs --- Interpreter.Tests/Stubs/MapperStub.cs | 1 - .../Unit/FrontEnd/StructureTests.cs | 31 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 Interpreter.Tests/Unit/FrontEnd/StructureTests.cs diff --git a/Interpreter.Tests/Stubs/MapperStub.cs b/Interpreter.Tests/Stubs/MapperStub.cs index 1a1cdb9c..ae5b8e1c 100644 --- a/Interpreter.Tests/Stubs/MapperStub.cs +++ b/Interpreter.Tests/Stubs/MapperStub.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using AutoMapper; using Interpreter.MappingProfiles; diff --git a/Interpreter.Tests/Unit/FrontEnd/StructureTests.cs b/Interpreter.Tests/Unit/FrontEnd/StructureTests.cs new file mode 100644 index 00000000..2640a492 --- /dev/null +++ b/Interpreter.Tests/Unit/FrontEnd/StructureTests.cs @@ -0,0 +1,31 @@ +using System.Collections.Generic; +using Interpreter.Lib.FrontEnd.GetTokens.Data; +using Interpreter.Lib.FrontEnd.GetTokens.Data.TokenTypes; +using Xunit; + +namespace Interpreter.Tests.Unit.FrontEnd; + +public class StructureTests +{ + [Fact] + public void StructureToStringCorrectTest() + { + var tokenTypes = new List + { + new ("MyToken", "[m|M][y|Y]", 2), + new ("OneToSeven", "[1-7]", 1) + }; + var structure = new Structure(tokenTypes); + + var expectedText = string.Join('\n', + new List + { + "OneToSeven [1-7]", + "MyToken [m|M][y|Y]", + "EOP ", + "ERROR \\S+" + } + ); + Assert.Equal(expectedText,structure.ToString()); + } +} \ No newline at end of file From ad7e2f72bb7ee70f87d66a0cc3677d6a4ebb8353 Mon Sep 17 00:00:00 2001 From: Stepami Date: Thu, 15 Sep 2022 13:57:21 +0300 Subject: [PATCH 38/56] =?UTF-8?q?=D1=80=D0=B5=D0=BE=D1=80=D0=B3=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20=D0=BF=D0=B0=D0=BF?= =?UTF-8?q?=D0=BE=D0=BA=20=D0=B2=20=D1=82=D0=B5=D1=81=D1=82=D0=B0=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Interpreter.Tests/Unit/{ => FrontEnd}/ParserTests.cs | 2 +- Interpreter.Tests/Unit/{ => IR}/AstNodeTests.cs | 2 +- Interpreter.Tests/Unit/{ => IR}/ExpressionTests.cs | 2 +- Interpreter.Tests/Unit/{ => IR}/SymbolTableTests.cs | 2 +- Interpreter.Tests/Unit/{ => IR}/TypeTests.cs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) rename Interpreter.Tests/Unit/{ => FrontEnd}/ParserTests.cs (95%) rename Interpreter.Tests/Unit/{ => IR}/AstNodeTests.cs (96%) rename Interpreter.Tests/Unit/{ => IR}/ExpressionTests.cs (94%) rename Interpreter.Tests/Unit/{ => IR}/SymbolTableTests.cs (98%) rename Interpreter.Tests/Unit/{ => IR}/TypeTests.cs (99%) diff --git a/Interpreter.Tests/Unit/ParserTests.cs b/Interpreter.Tests/Unit/FrontEnd/ParserTests.cs similarity index 95% rename from Interpreter.Tests/Unit/ParserTests.cs rename to Interpreter.Tests/Unit/FrontEnd/ParserTests.cs index 12033624..13601e51 100644 --- a/Interpreter.Tests/Unit/ParserTests.cs +++ b/Interpreter.Tests/Unit/FrontEnd/ParserTests.cs @@ -7,7 +7,7 @@ using Interpreter.Tests.TestData; using Xunit; -namespace Interpreter.Tests.Unit +namespace Interpreter.Tests.Unit.FrontEnd { public class ParserTests { diff --git a/Interpreter.Tests/Unit/AstNodeTests.cs b/Interpreter.Tests/Unit/IR/AstNodeTests.cs similarity index 96% rename from Interpreter.Tests/Unit/AstNodeTests.cs rename to Interpreter.Tests/Unit/IR/AstNodeTests.cs index 92ff8f0c..be05ddcc 100644 --- a/Interpreter.Tests/Unit/AstNodeTests.cs +++ b/Interpreter.Tests/Unit/IR/AstNodeTests.cs @@ -7,7 +7,7 @@ using Moq; using Xunit; -namespace Interpreter.Tests.Unit +namespace Interpreter.Tests.Unit.IR { public class AstNodeTests { diff --git a/Interpreter.Tests/Unit/ExpressionTests.cs b/Interpreter.Tests/Unit/IR/ExpressionTests.cs similarity index 94% rename from Interpreter.Tests/Unit/ExpressionTests.cs rename to Interpreter.Tests/Unit/IR/ExpressionTests.cs index 2cf95d21..2fa0ad48 100644 --- a/Interpreter.Tests/Unit/ExpressionTests.cs +++ b/Interpreter.Tests/Unit/IR/ExpressionTests.cs @@ -3,7 +3,7 @@ using Interpreter.Lib.IR.CheckSemantics.Types; using Xunit; -namespace Interpreter.Tests.Unit +namespace Interpreter.Tests.Unit.IR { public class ExpressionTests { diff --git a/Interpreter.Tests/Unit/SymbolTableTests.cs b/Interpreter.Tests/Unit/IR/SymbolTableTests.cs similarity index 98% rename from Interpreter.Tests/Unit/SymbolTableTests.cs rename to Interpreter.Tests/Unit/IR/SymbolTableTests.cs index f1b1d917..0a07cb35 100644 --- a/Interpreter.Tests/Unit/SymbolTableTests.cs +++ b/Interpreter.Tests/Unit/IR/SymbolTableTests.cs @@ -8,7 +8,7 @@ using Xunit; using Type = Interpreter.Lib.IR.CheckSemantics.Types.Type; -namespace Interpreter.Tests.Unit +namespace Interpreter.Tests.Unit.IR { public class SymbolTableTests { diff --git a/Interpreter.Tests/Unit/TypeTests.cs b/Interpreter.Tests/Unit/IR/TypeTests.cs similarity index 99% rename from Interpreter.Tests/Unit/TypeTests.cs rename to Interpreter.Tests/Unit/IR/TypeTests.cs index c18bfe66..592c6aa1 100644 --- a/Interpreter.Tests/Unit/TypeTests.cs +++ b/Interpreter.Tests/Unit/IR/TypeTests.cs @@ -2,7 +2,7 @@ using Interpreter.Lib.IR.CheckSemantics.Types; using Xunit; -namespace Interpreter.Tests.Unit +namespace Interpreter.Tests.Unit.IR { public class TypeTests { From 8ed2163cfaff101cf695499fb3d2e99b020ddbab Mon Sep 17 00:00:00 2001 From: Stepami Date: Thu, 15 Sep 2022 14:12:32 +0300 Subject: [PATCH 39/56] vm tests --- .../Unit/BackEnd/VirtualMachineTests.cs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Interpreter.Tests/Unit/BackEnd/VirtualMachineTests.cs diff --git a/Interpreter.Tests/Unit/BackEnd/VirtualMachineTests.cs b/Interpreter.Tests/Unit/BackEnd/VirtualMachineTests.cs new file mode 100644 index 00000000..3174ec9b --- /dev/null +++ b/Interpreter.Tests/Unit/BackEnd/VirtualMachineTests.cs @@ -0,0 +1,29 @@ +#nullable enable +using System.Collections.Generic; +using System.IO; +using Interpreter.Lib.BackEnd; +using Interpreter.Lib.BackEnd.Instructions; +using Interpreter.Lib.BackEnd.Values; +using Moq; +using Xunit; + +namespace Interpreter.Tests.Unit.BackEnd; + +public class VirtualMachineTests +{ + [Fact] + public void CorrectPrintToOutTest() + { + var writer = new Mock(); + writer.Setup(x => x.WriteLine(It.IsAny())) + .Verifiable(); + + var vm = new VirtualMachine(new(), new Stack(new[] { new Frame() }), new(), writer.Object); + var print = new Print(0, new Constant(223, "223")); + + print.Execute(vm); + writer.Verify(x => x.WriteLine( + It.Is(v => v!.Equals(223)) + ), Times.Once()); + } +} \ No newline at end of file From f1232446878d09967d3d4396c0d5692bfa4f8162 Mon Sep 17 00:00:00 2001 From: Stepami Date: Thu, 15 Sep 2022 14:26:40 +0300 Subject: [PATCH 40/56] more vm tests --- Interpreter.Lib/BackEnd/VirtualMachine.cs | 2 ++ .../Unit/BackEnd/VirtualMachineTests.cs | 27 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/Interpreter.Lib/BackEnd/VirtualMachine.cs b/Interpreter.Lib/BackEnd/VirtualMachine.cs index 52822d39..b5ba207c 100644 --- a/Interpreter.Lib/BackEnd/VirtualMachine.cs +++ b/Interpreter.Lib/BackEnd/VirtualMachine.cs @@ -26,6 +26,8 @@ public void Run(List instructions) var jump = instruction.Execute(this); address = jump; } + + instructions[address].Execute(this); } } diff --git a/Interpreter.Tests/Unit/BackEnd/VirtualMachineTests.cs b/Interpreter.Tests/Unit/BackEnd/VirtualMachineTests.cs index 3174ec9b..7565c037 100644 --- a/Interpreter.Tests/Unit/BackEnd/VirtualMachineTests.cs +++ b/Interpreter.Tests/Unit/BackEnd/VirtualMachineTests.cs @@ -1,4 +1,5 @@ #nullable enable +using System; using System.Collections.Generic; using System.IO; using Interpreter.Lib.BackEnd; @@ -26,4 +27,30 @@ public void CorrectPrintToOutTest() It.Is(v => v!.Equals(223)) ), Times.Once()); } + + [Fact] + public void ProgramWithoutHaltWillNotRunTest() + { + var vm = new VirtualMachine(); + var program = new List(); + Assert.Throws(() => vm.Run(program)); + + program.Add(new Halt(0)); + Assert.Null(Record.Exception(() => vm.Run(program))); + } + + [Fact] + public void VirtualMachineFramesClearedAfterExecutionTest() + { + var vm = new VirtualMachine(); + var program = new List() + { + new Simple("a", (new Constant(1, "1"), new Constant(2, "2")), "+", 0), + new AsString("b", new Name("a"), 1), + new Halt(2) + }; + + vm.Run(program); + Assert.Empty(vm.Frames); + } } \ No newline at end of file From 7fe49a2b917ce9bc0bda9856e8bbfe80ccbc02c0 Mon Sep 17 00:00:00 2001 From: Stepami Date: Thu, 15 Sep 2022 14:32:11 +0300 Subject: [PATCH 41/56] vm tests refactoring --- .../Unit/BackEnd/VirtualMachineTests.cs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Interpreter.Tests/Unit/BackEnd/VirtualMachineTests.cs b/Interpreter.Tests/Unit/BackEnd/VirtualMachineTests.cs index 7565c037..51877abc 100644 --- a/Interpreter.Tests/Unit/BackEnd/VirtualMachineTests.cs +++ b/Interpreter.Tests/Unit/BackEnd/VirtualMachineTests.cs @@ -12,6 +12,13 @@ namespace Interpreter.Tests.Unit.BackEnd; public class VirtualMachineTests { + private readonly VirtualMachine _vm; + + public VirtualMachineTests() + { + _vm = new(new(), new(), new(), TextWriter.Null); + } + [Fact] public void CorrectPrintToOutTest() { @@ -31,18 +38,16 @@ public void CorrectPrintToOutTest() [Fact] public void ProgramWithoutHaltWillNotRunTest() { - var vm = new VirtualMachine(); var program = new List(); - Assert.Throws(() => vm.Run(program)); + Assert.Throws(() => _vm.Run(program)); program.Add(new Halt(0)); - Assert.Null(Record.Exception(() => vm.Run(program))); + Assert.Null(Record.Exception(() => _vm.Run(program))); } [Fact] public void VirtualMachineFramesClearedAfterExecutionTest() { - var vm = new VirtualMachine(); var program = new List() { new Simple("a", (new Constant(1, "1"), new Constant(2, "2")), "+", 0), @@ -50,7 +55,7 @@ public void VirtualMachineFramesClearedAfterExecutionTest() new Halt(2) }; - vm.Run(program); - Assert.Empty(vm.Frames); + _vm.Run(program); + Assert.Empty(_vm.Frames); } } \ No newline at end of file From 75fad812cb0dfbd651d3bc3c8df96116d28cbd0a Mon Sep 17 00:00:00 2001 From: Stepami Date: Thu, 15 Sep 2022 15:07:59 +0300 Subject: [PATCH 42/56] factorial unit test --- .../Unit/BackEnd/VirtualMachineTests.cs | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/Interpreter.Tests/Unit/BackEnd/VirtualMachineTests.cs b/Interpreter.Tests/Unit/BackEnd/VirtualMachineTests.cs index 51877abc..ea950829 100644 --- a/Interpreter.Tests/Unit/BackEnd/VirtualMachineTests.cs +++ b/Interpreter.Tests/Unit/BackEnd/VirtualMachineTests.cs @@ -58,4 +58,40 @@ public void VirtualMachineFramesClearedAfterExecutionTest() _vm.Run(program); Assert.Empty(_vm.Frames); } + + [Fact] + public void VirtualMachineHandlesRecursion() + { + var halt = new Mock(12); + halt.Setup(x => x.Execute(It.IsAny())) + .Returns(-3).Verifiable(); + halt.Setup(x => x.End()).Returns(true); + var factorial = new FunctionInfo("fact", 1); + var program = new List + { + new Goto(10, 0), + new BeginFunction(1, factorial), + new Simple("_t2", (new Name("n"), new Constant(2, "2")), "<", 2), + new IfNotGoto(new Name("_t2"), 5, 3), + new Return(1, 4, new Name("n")), + new Simple("_t5", (new Name("n"), new Constant(1, "1")), "-", 5), + new PushParameter(6, "n", new Name("_t5")), + new CallFunction(factorial, 7, 1, "f"), + new Simple("_t8", (new Name("n"), new Name("f")), "*", 8), + new Return(1, 9, new Name("_t8")), + new PushParameter(10, "n", new Constant(6, "6")), + new CallFunction(factorial, 11, 1, "fa6"), + halt.Object + }; + + _vm.Run(program); + Assert.Empty(_vm.CallStack); + Assert.Empty(_vm.Arguments); + halt.Verify(x => x.Execute( + It.Is( + vm => Convert.ToInt32(vm.Frames.Peek()["fa6"]) == 720 + ) + ), Times.Once()); + _vm.Frames.Pop(); + } } \ No newline at end of file From b8f72270a9f77f5b3d1ec4c94f229c09bf844c1a Mon Sep 17 00:00:00 2001 From: Stepami Date: Thu, 15 Sep 2022 15:25:55 +0300 Subject: [PATCH 43/56] Instruction.cs refactoring --- .../BackEnd/Instructions/Instruction.cs | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/Interpreter.Lib/BackEnd/Instructions/Instruction.cs b/Interpreter.Lib/BackEnd/Instructions/Instruction.cs index 8c8443da..06bf49ef 100644 --- a/Interpreter.Lib/BackEnd/Instructions/Instruction.cs +++ b/Interpreter.Lib/BackEnd/Instructions/Instruction.cs @@ -2,33 +2,21 @@ namespace Interpreter.Lib.BackEnd.Instructions { - public abstract class Instruction : IComparable, IEquatable + public abstract class Instruction : IComparable { public int Number { get; } - public bool Leader { get; set; } - - protected Instruction(int number) - { + protected Instruction(int number) => Number = number; - } public virtual int Jump() => Number + 1; - public bool Branch() => Jump() != Number + 1; - public virtual bool End() => false; public abstract int Execute(VirtualMachine vm); public int CompareTo(Instruction other) => Number.CompareTo(other.Number); - public bool Equals(Instruction other) => other != null && Number.Equals(other.Number); - - public override bool Equals(object obj) => Equals(obj as Instruction); - - public override int GetHashCode() => Number; - protected abstract string ToStringRepresentation(); public override string ToString() => $"{Number}: {ToStringRepresentation()}"; From ae6e02a7e3b431343fdd5225ccdbab8130682270 Mon Sep 17 00:00:00 2001 From: Stepami Date: Thu, 15 Sep 2022 15:36:11 +0300 Subject: [PATCH 44/56] coverage --- .../BackEnd/Instructions/AsString.cs | 2 + .../Unit/BackEnd/FunctionInfoTests.cs | 14 ++ Interpreter.Tests/Unit/BackEnd/ValuesTests.cs | 26 ++++ .../Unit/BackEnd/VirtualMachineTests.cs | 145 +++++++++--------- .../Unit/FrontEnd/StructureTests.cs | 41 ++--- 5 files changed, 136 insertions(+), 92 deletions(-) create mode 100644 Interpreter.Tests/Unit/BackEnd/FunctionInfoTests.cs create mode 100644 Interpreter.Tests/Unit/BackEnd/ValuesTests.cs diff --git a/Interpreter.Lib/BackEnd/Instructions/AsString.cs b/Interpreter.Lib/BackEnd/Instructions/AsString.cs index f33e971b..d8c9eb54 100644 --- a/Interpreter.Lib/BackEnd/Instructions/AsString.cs +++ b/Interpreter.Lib/BackEnd/Instructions/AsString.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using Interpreter.Lib.BackEnd.Values; using Newtonsoft.Json; using Newtonsoft.Json.Serialization; @@ -36,6 +37,7 @@ public override int Execute(VirtualMachine vm) protected override string ToStringRepresentation() => $"{Left} = {right.right} as string"; + [ExcludeFromCodeCoverage] private class DoubleValueConverter : JsonConverter { public override bool CanRead => false; diff --git a/Interpreter.Tests/Unit/BackEnd/FunctionInfoTests.cs b/Interpreter.Tests/Unit/BackEnd/FunctionInfoTests.cs new file mode 100644 index 00000000..bc236e7a --- /dev/null +++ b/Interpreter.Tests/Unit/BackEnd/FunctionInfoTests.cs @@ -0,0 +1,14 @@ +using Interpreter.Lib.BackEnd; +using Xunit; + +namespace Interpreter.Tests.Unit.BackEnd +{ + public class FunctionInfoTests + { + [Theory] + [InlineData("func", null, "func")] + [InlineData("func", "obj", "obj.func")] + public void CallIdCorrectTest(string id, string methodOf, string expected) => + Assert.Equal(expected, new FunctionInfo(id, 0, methodOf).CallId()); + } +} \ No newline at end of file diff --git a/Interpreter.Tests/Unit/BackEnd/ValuesTests.cs b/Interpreter.Tests/Unit/BackEnd/ValuesTests.cs new file mode 100644 index 00000000..9201b0f4 --- /dev/null +++ b/Interpreter.Tests/Unit/BackEnd/ValuesTests.cs @@ -0,0 +1,26 @@ +using Interpreter.Lib.BackEnd.Values; +using Xunit; + +namespace Interpreter.Tests.Unit.BackEnd +{ + public class ValuesTests + { + [Fact] + public void ConstantNotEqualToNameTest() + { + var name = new Name("a"); + var constant = new Constant("a", "a"); + Assert.False(name.Equals(constant)); + Assert.False(constant.Equals(name)); + } + + [Fact] + public void ValueToStringCorrect() + { + var name = new Name("bbb"); + var constant = new Constant(1, "1.0"); + Assert.Equal("bbb", name.ToString()); + Assert.Equal("1.0", constant.ToString()); + } + } +} \ No newline at end of file diff --git a/Interpreter.Tests/Unit/BackEnd/VirtualMachineTests.cs b/Interpreter.Tests/Unit/BackEnd/VirtualMachineTests.cs index ea950829..b161992e 100644 --- a/Interpreter.Tests/Unit/BackEnd/VirtualMachineTests.cs +++ b/Interpreter.Tests/Unit/BackEnd/VirtualMachineTests.cs @@ -8,90 +8,91 @@ using Moq; using Xunit; -namespace Interpreter.Tests.Unit.BackEnd; - -public class VirtualMachineTests +namespace Interpreter.Tests.Unit.BackEnd { - private readonly VirtualMachine _vm; - - public VirtualMachineTests() + public class VirtualMachineTests { - _vm = new(new(), new(), new(), TextWriter.Null); - } + private readonly VirtualMachine _vm; + + public VirtualMachineTests() + { + _vm = new(new(), new(), new(), TextWriter.Null); + } - [Fact] - public void CorrectPrintToOutTest() - { - var writer = new Mock(); - writer.Setup(x => x.WriteLine(It.IsAny())) - .Verifiable(); + [Fact] + public void CorrectPrintToOutTest() + { + var writer = new Mock(); + writer.Setup(x => x.WriteLine(It.IsAny())) + .Verifiable(); - var vm = new VirtualMachine(new(), new Stack(new[] { new Frame() }), new(), writer.Object); - var print = new Print(0, new Constant(223, "223")); + var vm = new VirtualMachine(new(), new Stack(new[] { new Frame() }), new(), writer.Object); + var print = new Print(0, new Constant(223, "223")); - print.Execute(vm); - writer.Verify(x => x.WriteLine( - It.Is(v => v!.Equals(223)) - ), Times.Once()); - } + print.Execute(vm); + writer.Verify(x => x.WriteLine( + It.Is(v => v!.Equals(223)) + ), Times.Once()); + } - [Fact] - public void ProgramWithoutHaltWillNotRunTest() - { - var program = new List(); - Assert.Throws(() => _vm.Run(program)); + [Fact] + public void ProgramWithoutHaltWillNotRunTest() + { + var program = new List(); + Assert.Throws(() => _vm.Run(program)); - program.Add(new Halt(0)); - Assert.Null(Record.Exception(() => _vm.Run(program))); - } + program.Add(new Halt(0)); + Assert.Null(Record.Exception(() => _vm.Run(program))); + } - [Fact] - public void VirtualMachineFramesClearedAfterExecutionTest() - { - var program = new List() + [Fact] + public void VirtualMachineFramesClearedAfterExecutionTest() { - new Simple("a", (new Constant(1, "1"), new Constant(2, "2")), "+", 0), - new AsString("b", new Name("a"), 1), - new Halt(2) - }; + var program = new List() + { + new Simple("a", (new Constant(1, "1"), new Constant(2, "2")), "+", 0), + new AsString("b", new Name("a"), 1), + new Halt(2) + }; - _vm.Run(program); - Assert.Empty(_vm.Frames); - } + _vm.Run(program); + Assert.Empty(_vm.Frames); + } - [Fact] - public void VirtualMachineHandlesRecursion() - { - var halt = new Mock(12); - halt.Setup(x => x.Execute(It.IsAny())) - .Returns(-3).Verifiable(); - halt.Setup(x => x.End()).Returns(true); - var factorial = new FunctionInfo("fact", 1); - var program = new List + [Fact] + public void VirtualMachineHandlesRecursion() { - new Goto(10, 0), - new BeginFunction(1, factorial), - new Simple("_t2", (new Name("n"), new Constant(2, "2")), "<", 2), - new IfNotGoto(new Name("_t2"), 5, 3), - new Return(1, 4, new Name("n")), - new Simple("_t5", (new Name("n"), new Constant(1, "1")), "-", 5), - new PushParameter(6, "n", new Name("_t5")), - new CallFunction(factorial, 7, 1, "f"), - new Simple("_t8", (new Name("n"), new Name("f")), "*", 8), - new Return(1, 9, new Name("_t8")), - new PushParameter(10, "n", new Constant(6, "6")), - new CallFunction(factorial, 11, 1, "fa6"), - halt.Object - }; + var halt = new Mock(12); + halt.Setup(x => x.Execute(It.IsAny())) + .Returns(-3).Verifiable(); + halt.Setup(x => x.End()).Returns(true); + var factorial = new FunctionInfo("fact", 1); + var program = new List + { + new Goto(10, 0), + new BeginFunction(1, factorial), + new Simple("_t2", (new Name("n"), new Constant(2, "2")), "<", 2), + new IfNotGoto(new Name("_t2"), 5, 3), + new Return(1, 4, new Name("n")), + new Simple("_t5", (new Name("n"), new Constant(1, "1")), "-", 5), + new PushParameter(6, "n", new Name("_t5")), + new CallFunction(factorial, 7, 1, "f"), + new Simple("_t8", (new Name("n"), new Name("f")), "*", 8), + new Return(1, 9, new Name("_t8")), + new PushParameter(10, "n", new Constant(6, "6")), + new CallFunction(factorial, 11, 1, "fa6"), + halt.Object + }; - _vm.Run(program); - Assert.Empty(_vm.CallStack); - Assert.Empty(_vm.Arguments); - halt.Verify(x => x.Execute( - It.Is( - vm => Convert.ToInt32(vm.Frames.Peek()["fa6"]) == 720 - ) - ), Times.Once()); - _vm.Frames.Pop(); + _vm.Run(program); + Assert.Empty(_vm.CallStack); + Assert.Empty(_vm.Arguments); + halt.Verify(x => x.Execute( + It.Is( + vm => Convert.ToInt32(vm.Frames.Peek()["fa6"]) == 720 + ) + ), Times.Once()); + _vm.Frames.Pop(); + } } } \ No newline at end of file diff --git a/Interpreter.Tests/Unit/FrontEnd/StructureTests.cs b/Interpreter.Tests/Unit/FrontEnd/StructureTests.cs index 2640a492..0d85d0e8 100644 --- a/Interpreter.Tests/Unit/FrontEnd/StructureTests.cs +++ b/Interpreter.Tests/Unit/FrontEnd/StructureTests.cs @@ -3,29 +3,30 @@ using Interpreter.Lib.FrontEnd.GetTokens.Data.TokenTypes; using Xunit; -namespace Interpreter.Tests.Unit.FrontEnd; - -public class StructureTests +namespace Interpreter.Tests.Unit.FrontEnd { - [Fact] - public void StructureToStringCorrectTest() + public class StructureTests { - var tokenTypes = new List + [Fact] + public void StructureToStringCorrectTest() { - new ("MyToken", "[m|M][y|Y]", 2), - new ("OneToSeven", "[1-7]", 1) - }; - var structure = new Structure(tokenTypes); - - var expectedText = string.Join('\n', - new List + var tokenTypes = new List { - "OneToSeven [1-7]", - "MyToken [m|M][y|Y]", - "EOP ", - "ERROR \\S+" - } - ); - Assert.Equal(expectedText,structure.ToString()); + new ("MyToken", "[m|M][y|Y]", 2), + new ("OneToSeven", "[1-7]", 1) + }; + var structure = new Structure(tokenTypes); + + var expectedText = string.Join('\n', + new List + { + "OneToSeven [1-7]", + "MyToken [m|M][y|Y]", + "EOP ", + "ERROR \\S+" + } + ); + Assert.Equal(expectedText,structure.ToString()); + } } } \ No newline at end of file From 85b79705a9c4ece8f136d8ce165acc460d154145 Mon Sep 17 00:00:00 2001 From: Stepami Date: Thu, 15 Sep 2022 15:40:11 +0300 Subject: [PATCH 45/56] values tests --- Interpreter.Tests/Unit/BackEnd/ValuesTests.cs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Interpreter.Tests/Unit/BackEnd/ValuesTests.cs b/Interpreter.Tests/Unit/BackEnd/ValuesTests.cs index 9201b0f4..7404c103 100644 --- a/Interpreter.Tests/Unit/BackEnd/ValuesTests.cs +++ b/Interpreter.Tests/Unit/BackEnd/ValuesTests.cs @@ -10,6 +10,7 @@ public void ConstantNotEqualToNameTest() { var name = new Name("a"); var constant = new Constant("a", "a"); + Assert.False(name.Equals(constant)); Assert.False(constant.Equals(name)); } @@ -19,8 +20,27 @@ public void ValueToStringCorrect() { var name = new Name("bbb"); var constant = new Constant(1, "1.0"); + Assert.Equal("bbb", name.ToString()); Assert.Equal("1.0", constant.ToString()); } + + [Fact] + public void NameEqualsCorrect() + { + var name1 = new Name("name"); + var name2 = new Name("name"); + + Assert.True(name1.Equals(name2)); + } + + [Fact] + public void ConstantEqualsCorrect() + { + var constant1 = new Constant(1, "1"); + var constant2 = new Constant(1, "1.0"); + + Assert.True(constant1.Equals(constant2)); + } } } \ No newline at end of file From 88bae1342728777c7975cd5d935ba45523049dcd Mon Sep 17 00:00:00 2001 From: Stepami Date: Thu, 15 Sep 2022 16:11:02 +0300 Subject: [PATCH 46/56] coverage --- Interpreter.Tests/MockExtensions.cs | 17 ++++++++ .../Unit/BackEnd/VirtualMachineTests.cs | 40 +++++++++++++++++-- 2 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 Interpreter.Tests/MockExtensions.cs diff --git a/Interpreter.Tests/MockExtensions.cs b/Interpreter.Tests/MockExtensions.cs new file mode 100644 index 00000000..e14a1ecb --- /dev/null +++ b/Interpreter.Tests/MockExtensions.cs @@ -0,0 +1,17 @@ +using Interpreter.Lib.BackEnd; +using Interpreter.Lib.BackEnd.Instructions; +using Moq; + +namespace Interpreter.Tests +{ + public static class MockExtensions + { + public static Mock Trackable(this Mock halt) + { + halt.Setup(x => x.Execute(It.IsAny())) + .Returns(-3).Verifiable(); + halt.Setup(x => x.End()).Returns(true); + return halt; + } + } +} \ No newline at end of file diff --git a/Interpreter.Tests/Unit/BackEnd/VirtualMachineTests.cs b/Interpreter.Tests/Unit/BackEnd/VirtualMachineTests.cs index b161992e..a81599df 100644 --- a/Interpreter.Tests/Unit/BackEnd/VirtualMachineTests.cs +++ b/Interpreter.Tests/Unit/BackEnd/VirtualMachineTests.cs @@ -62,10 +62,7 @@ public void VirtualMachineFramesClearedAfterExecutionTest() [Fact] public void VirtualMachineHandlesRecursion() { - var halt = new Mock(12); - halt.Setup(x => x.Execute(It.IsAny())) - .Returns(-3).Verifiable(); - halt.Setup(x => x.End()).Returns(true); + var halt = new Mock(12).Trackable(); var factorial = new FunctionInfo("fact", 1); var program = new List { @@ -94,5 +91,40 @@ public void VirtualMachineHandlesRecursion() ), Times.Once()); _vm.Frames.Pop(); } + + [Fact] + public void CreateArrayReservesCertainSpaceTest() + { + var vm = new VirtualMachine(); + vm.Frames.Push(new Frame()); + var createArray = new CreateArray(0, "arr", 6); + createArray.Execute(vm); + Assert.Equal(6, ((List) vm.Frames.Peek()["arr"]).Count); + + var indexAssignment = new IndexAssignment("arr", (new Constant(0, "0"), new Constant(0, "0")), 1); + indexAssignment.Execute(vm); + Assert.Equal(0, ((List) vm.Frames.Peek()["arr"])[0]); + } + + [Fact] + public void ObjectCreationTest() + { + var halt = new Mock(2).Trackable(); + var program = new List + { + new CreateObject(0, "obj"), + new DotAssignment("obj", (new Constant("prop", "prop"), new Constant(null, "null")), 1), + halt.Object + }; + + _vm.Run(program); + halt.Verify(x => x.Execute( + It.Is( + // ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract + vm => ((Dictionary)vm.Frames.Peek()["obj"])["prop"] == null + ) + ), Times.Once()); + _vm.Frames.Pop(); + } } } \ No newline at end of file From 742a5bcd5b8226641ce9f499832c9e43b9841ef1 Mon Sep 17 00:00:00 2001 From: Stepami Date: Thu, 15 Sep 2022 16:14:19 +0300 Subject: [PATCH 47/56] coverage --- Interpreter.Tests/Unit/BackEnd/VirtualMachineTests.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Interpreter.Tests/Unit/BackEnd/VirtualMachineTests.cs b/Interpreter.Tests/Unit/BackEnd/VirtualMachineTests.cs index a81599df..1574d08d 100644 --- a/Interpreter.Tests/Unit/BackEnd/VirtualMachineTests.cs +++ b/Interpreter.Tests/Unit/BackEnd/VirtualMachineTests.cs @@ -97,6 +97,7 @@ public void CreateArrayReservesCertainSpaceTest() { var vm = new VirtualMachine(); vm.Frames.Push(new Frame()); + var createArray = new CreateArray(0, "arr", 6); createArray.Execute(vm); Assert.Equal(6, ((List) vm.Frames.Peek()["arr"]).Count); @@ -104,6 +105,10 @@ public void CreateArrayReservesCertainSpaceTest() var indexAssignment = new IndexAssignment("arr", (new Constant(0, "0"), new Constant(0, "0")), 1); indexAssignment.Execute(vm); Assert.Equal(0, ((List) vm.Frames.Peek()["arr"])[0]); + + var removeFromArray = new RemoveFromArray(2, "arr", new Constant(5, "5")); + removeFromArray.Execute(vm); + Assert.Equal(5, ((List) vm.Frames.Peek()["arr"]).Count); } [Fact] From 9c554a55245363bc50d9aba593db20ea41a90fca Mon Sep 17 00:00:00 2001 From: Stepami Date: Thu, 15 Sep 2022 16:18:51 +0300 Subject: [PATCH 48/56] coverage --- .../FrontEnd/GetTokens/Data/Structure.cs | 16 +++++++++------- Interpreter.Lib/FrontEnd/GetTokens/Impl/Lexer.cs | 2 ++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Interpreter.Lib/FrontEnd/GetTokens/Data/Structure.cs b/Interpreter.Lib/FrontEnd/GetTokens/Data/Structure.cs index 2fdbfd63..2d451106 100644 --- a/Interpreter.Lib/FrontEnd/GetTokens/Data/Structure.cs +++ b/Interpreter.Lib/FrontEnd/GetTokens/Data/Structure.cs @@ -1,5 +1,6 @@ using System.Collections; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Text; using System.Text.RegularExpressions; @@ -38,18 +39,19 @@ public Structure(List types) public Regex Regex { get; } - public TokenType FindByTag(string tag) => Types[tag]; + public TokenType FindByTag(string tag) => + Types[tag]; - public override string ToString() - { - return new StringBuilder() + public override string ToString() => + new StringBuilder() .AppendJoin('\n', Types.Select(x => $"{x.Key} {x.Value.Pattern}") ).ToString(); - } - - public IEnumerator GetEnumerator() => Types.Values.GetEnumerator(); + public IEnumerator GetEnumerator() => + Types.Values.GetEnumerator(); + + [ExcludeFromCodeCoverage] IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } } \ No newline at end of file diff --git a/Interpreter.Lib/FrontEnd/GetTokens/Impl/Lexer.cs b/Interpreter.Lib/FrontEnd/GetTokens/Impl/Lexer.cs index 3f0ce8d3..6418f218 100644 --- a/Interpreter.Lib/FrontEnd/GetTokens/Impl/Lexer.cs +++ b/Interpreter.Lib/FrontEnd/GetTokens/Impl/Lexer.cs @@ -1,5 +1,6 @@ using System.Collections; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Text.RegularExpressions; using Interpreter.Lib.FrontEnd.GetTokens.Data; @@ -62,6 +63,7 @@ public IEnumerator GetEnumerator() yield return new Token(TokenTypeUtils.End); } + [ExcludeFromCodeCoverage] IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); public override string ToString() => From a7784a8c16f6b23cb9199032861c4cc8d3854d15 Mon Sep 17 00:00:00 2001 From: Stepami Date: Thu, 15 Sep 2022 22:53:53 +0300 Subject: [PATCH 49/56] fix Readme.md --- Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index fdd28629..d8a22514 100644 --- a/Readme.md +++ b/Readme.md @@ -14,7 +14,7 @@ _Minimum allowed line rate is `20%`_ За основу был взят стандарт [ECMA-262](https://www.ecma-international.org/publications-and-standards/standards/ecma-262/) -[Лексическая структура](Interpreter/tokenTypes.json) +[Лексическая структура](Interpreter/TokenTypes.cs) [Грамматика](Interpreter/grammar.txt) From 925c58a02638b4dbf8ca8d4255203cae5ed3fca2 Mon Sep 17 00:00:00 2001 From: Stepami Date: Thu, 15 Sep 2022 22:54:06 +0300 Subject: [PATCH 50/56] rename file --- .../TestData/{ParserSuccessTestData.cs => ParserData.cs} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Interpreter.Tests/TestData/{ParserSuccessTestData.cs => ParserData.cs} (100%) diff --git a/Interpreter.Tests/TestData/ParserSuccessTestData.cs b/Interpreter.Tests/TestData/ParserData.cs similarity index 100% rename from Interpreter.Tests/TestData/ParserSuccessTestData.cs rename to Interpreter.Tests/TestData/ParserData.cs From da1709a87d6c5fd5b4f57f8ee1ee7edff42b9a59 Mon Sep 17 00:00:00 2001 From: Stepami Date: Thu, 15 Sep 2022 23:12:45 +0300 Subject: [PATCH 51/56] Instructions tests --- .../TestData/InstructionsData.cs | 107 ++++++++++++++++++ .../Unit/BackEnd/InstructionsTests.cs | 14 +++ 2 files changed, 121 insertions(+) create mode 100644 Interpreter.Tests/TestData/InstructionsData.cs create mode 100644 Interpreter.Tests/Unit/BackEnd/InstructionsTests.cs diff --git a/Interpreter.Tests/TestData/InstructionsData.cs b/Interpreter.Tests/TestData/InstructionsData.cs new file mode 100644 index 00000000..02e3e607 --- /dev/null +++ b/Interpreter.Tests/TestData/InstructionsData.cs @@ -0,0 +1,107 @@ +using System.Collections; +using System.Collections.Generic; +using Interpreter.Lib.BackEnd; +using Interpreter.Lib.BackEnd.Instructions; +using Interpreter.Lib.BackEnd.Values; + +namespace Interpreter.Tests.TestData +{ + public class InstructionsData : IEnumerable + { + public IEnumerator GetEnumerator() + { + yield return new object[] + { + new AsString("str", new Name("num"), 0), + "0: str = num as string" + }; + yield return new object[] + { + new BeginFunction(1, new FunctionInfo("func", 1)), + "1: BeginFunction func" + }; + yield return new object[] + { + new CallFunction(new FunctionInfo("func"), 2, 0), + "2: Call (0, func), 0" + }; + yield return new object[] + { + new CallFunction(new FunctionInfo("func"), 2, 0, "ret"), + "2: ret = Call (0, func), 0" + }; + yield return new object[] + { + new CreateArray(3, "arr", 5), + "3: array arr = [5]" + }; + yield return new object[] + { + new CreateObject(4, "obj"), + "4: object obj = {}" + }; + yield return new object[] + { + new DotAssignment("obj", (new Constant("prop", "prop"), new Constant(3, "3")), 5), + "5: obj.prop = 3" + }; + yield return new object[] + { + new Goto(10, 6), + "6: Goto 10" + }; + yield return new object[] + { + new Halt(7), + "7: End" + }; + yield return new object[] + { + new IfNotGoto(new Name("test"), 17, 8), + "8: IfNot test Goto 17" + }; + yield return new object[] + { + new IndexAssignment("arr", (new Constant(1, "1"), new Constant(1, "1")), 9), + "9: arr[1] = 1" + }; + yield return new object[] + { + new Print(10, new Name("str")), + "10: Print str" + }; + yield return new object[] + { + new PushParameter(11, "param", new Name("value")), + "11: PushParameter param = value" + }; + yield return new object[] + { + new RemoveFromArray(12, "arr", new Constant(0, "0")), + "12: RemoveFrom arr at 0" + }; + yield return new object[] + { + new Return(3, 13), + "13: Return" + }; + yield return new object[] + { + new Return(3, 13, new Name("result")), + "13: Return result" + }; + yield return new object[] + { + new Simple("a", (new Name("b"), new Name("c")), "+", 14), + "14: a = b + c" + }; + yield return new object[] + { + new Simple("b", (null, new Name("c")), "-", 14), + "14: b = -c" + }; + } + + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + } +} \ No newline at end of file diff --git a/Interpreter.Tests/Unit/BackEnd/InstructionsTests.cs b/Interpreter.Tests/Unit/BackEnd/InstructionsTests.cs new file mode 100644 index 00000000..b289554a --- /dev/null +++ b/Interpreter.Tests/Unit/BackEnd/InstructionsTests.cs @@ -0,0 +1,14 @@ +using Interpreter.Lib.BackEnd.Instructions; +using Interpreter.Tests.TestData; +using Xunit; + +namespace Interpreter.Tests.Unit.BackEnd +{ + public class InstructionsTests + { + [Theory] + [ClassData(typeof(InstructionsData))] + public void ToStringCorrectTest(Instruction instruction, string expected) => + Assert.Equal(expected, instruction.ToString()); + } +} \ No newline at end of file From db3c387df1e7de5b7188b900d7226a2a7c5705dc Mon Sep 17 00:00:00 2001 From: Stepami Date: Thu, 15 Sep 2022 23:21:18 +0300 Subject: [PATCH 52/56] test suffix --- Interpreter.Tests/Unit/BackEnd/ValuesTests.cs | 6 +++--- Interpreter.Tests/Unit/BackEnd/VirtualMachineTests.cs | 2 +- Interpreter.Tests/Unit/FrontEnd/StructureTests.cs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Interpreter.Tests/Unit/BackEnd/ValuesTests.cs b/Interpreter.Tests/Unit/BackEnd/ValuesTests.cs index 7404c103..b5535349 100644 --- a/Interpreter.Tests/Unit/BackEnd/ValuesTests.cs +++ b/Interpreter.Tests/Unit/BackEnd/ValuesTests.cs @@ -16,7 +16,7 @@ public void ConstantNotEqualToNameTest() } [Fact] - public void ValueToStringCorrect() + public void ValueToStringCorrectTest() { var name = new Name("bbb"); var constant = new Constant(1, "1.0"); @@ -26,7 +26,7 @@ public void ValueToStringCorrect() } [Fact] - public void NameEqualsCorrect() + public void NameEqualsCorrectTest() { var name1 = new Name("name"); var name2 = new Name("name"); @@ -35,7 +35,7 @@ public void NameEqualsCorrect() } [Fact] - public void ConstantEqualsCorrect() + public void ConstantEqualsCorrectTest() { var constant1 = new Constant(1, "1"); var constant2 = new Constant(1, "1.0"); diff --git a/Interpreter.Tests/Unit/BackEnd/VirtualMachineTests.cs b/Interpreter.Tests/Unit/BackEnd/VirtualMachineTests.cs index 1574d08d..52794a4a 100644 --- a/Interpreter.Tests/Unit/BackEnd/VirtualMachineTests.cs +++ b/Interpreter.Tests/Unit/BackEnd/VirtualMachineTests.cs @@ -60,7 +60,7 @@ public void VirtualMachineFramesClearedAfterExecutionTest() } [Fact] - public void VirtualMachineHandlesRecursion() + public void VirtualMachineHandlesRecursionTest() { var halt = new Mock(12).Trackable(); var factorial = new FunctionInfo("fact", 1); diff --git a/Interpreter.Tests/Unit/FrontEnd/StructureTests.cs b/Interpreter.Tests/Unit/FrontEnd/StructureTests.cs index 0d85d0e8..645a8438 100644 --- a/Interpreter.Tests/Unit/FrontEnd/StructureTests.cs +++ b/Interpreter.Tests/Unit/FrontEnd/StructureTests.cs @@ -8,7 +8,7 @@ namespace Interpreter.Tests.Unit.FrontEnd public class StructureTests { [Fact] - public void StructureToStringCorrectTest() + public void ToStringCorrectTest() { var tokenTypes = new List { From 89bcad58efe6d1bf67912e0533db4ed6eb27ac83 Mon Sep 17 00:00:00 2001 From: Stepami Date: Thu, 15 Sep 2022 23:27:24 +0300 Subject: [PATCH 53/56] coverage --- Interpreter.Tests/Unit/BackEnd/CallTests.cs | 22 ++++++++++++++++ .../Unit/BackEnd/InstructionsTests.cs | 26 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 Interpreter.Tests/Unit/BackEnd/CallTests.cs diff --git a/Interpreter.Tests/Unit/BackEnd/CallTests.cs b/Interpreter.Tests/Unit/BackEnd/CallTests.cs new file mode 100644 index 00000000..c07c6a21 --- /dev/null +++ b/Interpreter.Tests/Unit/BackEnd/CallTests.cs @@ -0,0 +1,22 @@ +using System.Collections.Generic; +using Interpreter.Lib.BackEnd; +using Xunit; + +namespace Interpreter.Tests.Unit.BackEnd +{ + public class CallTests + { + [Fact] + public void ToStringCorrect() + { + var call = new Call(9, new FunctionInfo("func"), + new List<(string Id, object Value)> + { + ("arg", 1) + } + ); + const string expected = "9 => 0: func(arg: 1)"; + Assert.Equal(expected, call.ToString()); + } + } +} \ No newline at end of file diff --git a/Interpreter.Tests/Unit/BackEnd/InstructionsTests.cs b/Interpreter.Tests/Unit/BackEnd/InstructionsTests.cs index b289554a..919e4b82 100644 --- a/Interpreter.Tests/Unit/BackEnd/InstructionsTests.cs +++ b/Interpreter.Tests/Unit/BackEnd/InstructionsTests.cs @@ -1,5 +1,6 @@ using Interpreter.Lib.BackEnd.Instructions; using Interpreter.Tests.TestData; +using Moq; using Xunit; namespace Interpreter.Tests.Unit.BackEnd @@ -10,5 +11,30 @@ public class InstructionsTests [ClassData(typeof(InstructionsData))] public void ToStringCorrectTest(Instruction instruction, string expected) => Assert.Equal(expected, instruction.ToString()); + + [Fact] + public void ComparisonDependsOnAddressTest() + { + var instruction1 = new Mock(1).Object; + var instruction2 = new Mock(2).Object; + + Assert.Equal(1, instruction2.CompareTo(instruction1)); + } + + [Fact] + public void GotoJumpChangedTest() + { + var @goto = new Goto(0, 1); + @goto.SetJump(5); + Assert.Equal(5, @goto.Jump()); + } + + [Fact] + public void ReturnCallersAddedTest() + { + var @return = new Return(7, 19); + @return.AddCaller(@return.FunctionStart - 2); + Assert.NotEmpty(@return); + } } } \ No newline at end of file From b39aeb4d40df92dce389f77f1058e7840ca7d92a Mon Sep 17 00:00:00 2001 From: Stepami Date: Thu, 15 Sep 2022 23:29:23 +0300 Subject: [PATCH 54/56] removed unused --- .../BackEnd/Instructions/Simple.cs | 28 +------------------ 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/Interpreter.Lib/BackEnd/Instructions/Simple.cs b/Interpreter.Lib/BackEnd/Instructions/Simple.cs index 7ad6d5b4..d587132b 100644 --- a/Interpreter.Lib/BackEnd/Instructions/Simple.cs +++ b/Interpreter.Lib/BackEnd/Instructions/Simple.cs @@ -10,7 +10,7 @@ public class Simple : Instruction public string Left { get; set; } protected (IValue left, IValue right) right; - protected string @operator; + protected readonly string @operator; public Simple( string left, @@ -86,32 +86,6 @@ public override int Execute(VirtualMachine vm) return Jump(); } - public void ReduceToAssignment() - { - right = ToStringRepresentation().Split('=')[1].Trim() switch - { - var s - when s.EndsWith("+ 0") || s.EndsWith("- 0") || - s.EndsWith("* 1") || s.EndsWith("/ 1") => (null, right.left), - var s - when s.StartsWith("0 +") || s.StartsWith("1 *") => (null, right.right), - _ => throw new NotImplementedException() - }; - @operator = ""; - } - - public void ReduceToZero() - { - right = ToStringRepresentation().Split('=')[1].Trim() switch - { - "-0" => (null, new Constant(0, "0")), - var s - when s.EndsWith("* 0") || s.StartsWith("0 *") => (null, new Constant(0, "0")), - _ => throw new NotImplementedException() - }; - @operator = ""; - } - protected override string ToStringRepresentation() => right.left == null ? $"{Left} = {@operator}{right.right}" From aaa2c6cd7fe481272e598a7dd9e0cc480c486edb Mon Sep 17 00:00:00 2001 From: Stepami Date: Fri, 16 Sep 2022 00:12:42 +0300 Subject: [PATCH 55/56] exception guidelines https://docs.microsoft.com/en-us/dotnet/csharp/fundamentals/exceptions/creating-and-throwing-exceptions#defining-exception-classes --- Interpreter.Lib/FrontEnd/GetTokens/LexerException.cs | 11 ++++++++--- .../FrontEnd/TopDownParse/ParserException.cs | 7 +++++++ .../IR/CheckSemantics/Exceptions/SemanticException.cs | 7 +++++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Interpreter.Lib/FrontEnd/GetTokens/LexerException.cs b/Interpreter.Lib/FrontEnd/GetTokens/LexerException.cs index b511176c..0c5fd9af 100644 --- a/Interpreter.Lib/FrontEnd/GetTokens/LexerException.cs +++ b/Interpreter.Lib/FrontEnd/GetTokens/LexerException.cs @@ -3,11 +3,16 @@ namespace Interpreter.Lib.FrontEnd.GetTokens { + [Serializable] public class LexerException : Exception { + protected LexerException() { } + + protected LexerException(string message) : base(message) { } + + protected LexerException(string message, Exception inner) : base(message, inner) { } + public LexerException(Token token) : - base($"Unknown token {token}") - { - } + base($"Unknown token {token}") { } } } \ No newline at end of file diff --git a/Interpreter.Lib/FrontEnd/TopDownParse/ParserException.cs b/Interpreter.Lib/FrontEnd/TopDownParse/ParserException.cs index 609d5a1a..c2b13b3e 100644 --- a/Interpreter.Lib/FrontEnd/TopDownParse/ParserException.cs +++ b/Interpreter.Lib/FrontEnd/TopDownParse/ParserException.cs @@ -3,8 +3,15 @@ namespace Interpreter.Lib.FrontEnd.TopDownParse { + [Serializable] public class ParserException : Exception { + protected ParserException() { } + + protected ParserException(string message) : base(message) { } + + protected ParserException(string message, Exception inner) : base(message, inner) { } + public ParserException(Segment segment, string expected, Token actual) : base($"Wrong syntax: {segment} expected {expected}; actual = ({actual.Type.Tag}, {actual.Value})") { diff --git a/Interpreter.Lib/IR/CheckSemantics/Exceptions/SemanticException.cs b/Interpreter.Lib/IR/CheckSemantics/Exceptions/SemanticException.cs index fa21ca96..36d9b978 100644 --- a/Interpreter.Lib/IR/CheckSemantics/Exceptions/SemanticException.cs +++ b/Interpreter.Lib/IR/CheckSemantics/Exceptions/SemanticException.cs @@ -3,8 +3,15 @@ namespace Interpreter.Lib.IR.CheckSemantics.Exceptions { + [Serializable] public abstract class SemanticException : Exception { + protected SemanticException() { } + + protected SemanticException(string message) : base(message) { } + + protected SemanticException(string message, Exception inner) : base(message, inner) { } + protected SemanticException(Segment segment, string message) : base($"{segment} {message}") { } } From f5c850c5ee31971631107f322d2e17468ad5518a Mon Sep 17 00:00:00 2001 From: Stepami Date: Fri, 16 Sep 2022 00:20:02 +0300 Subject: [PATCH 56/56] infrastructure coverage --- .../FrontEnd/GetTokens/LexerException.cs | 2 +- .../FrontEnd/TopDownParse/ParserException.cs | 2 +- .../Stubs/SemanticExceptionStub.cs | 6 ++ .../Unit/Infrastructure/ExecutorTests.cs | 97 +++++++++++++++++++ .../Infrastructure/ParsingServiceTests.cs | 34 +++++++ .../Unit/Infrastructure/ProvidersTests.cs | 60 ++++++++++++ Interpreter/CommandLineSettings.cs | 9 +- Interpreter/Models/StructureModel.cs | 2 + Interpreter/Models/TokenTypeModel.cs | 1 + Interpreter/Program.cs | 2 + 10 files changed, 209 insertions(+), 6 deletions(-) create mode 100644 Interpreter.Tests/Stubs/SemanticExceptionStub.cs create mode 100644 Interpreter.Tests/Unit/Infrastructure/ExecutorTests.cs create mode 100644 Interpreter.Tests/Unit/Infrastructure/ParsingServiceTests.cs create mode 100644 Interpreter.Tests/Unit/Infrastructure/ProvidersTests.cs diff --git a/Interpreter.Lib/FrontEnd/GetTokens/LexerException.cs b/Interpreter.Lib/FrontEnd/GetTokens/LexerException.cs index 0c5fd9af..60e007ac 100644 --- a/Interpreter.Lib/FrontEnd/GetTokens/LexerException.cs +++ b/Interpreter.Lib/FrontEnd/GetTokens/LexerException.cs @@ -6,7 +6,7 @@ namespace Interpreter.Lib.FrontEnd.GetTokens [Serializable] public class LexerException : Exception { - protected LexerException() { } + public LexerException() { } protected LexerException(string message) : base(message) { } diff --git a/Interpreter.Lib/FrontEnd/TopDownParse/ParserException.cs b/Interpreter.Lib/FrontEnd/TopDownParse/ParserException.cs index c2b13b3e..74924931 100644 --- a/Interpreter.Lib/FrontEnd/TopDownParse/ParserException.cs +++ b/Interpreter.Lib/FrontEnd/TopDownParse/ParserException.cs @@ -6,7 +6,7 @@ namespace Interpreter.Lib.FrontEnd.TopDownParse [Serializable] public class ParserException : Exception { - protected ParserException() { } + public ParserException() { } protected ParserException(string message) : base(message) { } diff --git a/Interpreter.Tests/Stubs/SemanticExceptionStub.cs b/Interpreter.Tests/Stubs/SemanticExceptionStub.cs new file mode 100644 index 00000000..84e616a1 --- /dev/null +++ b/Interpreter.Tests/Stubs/SemanticExceptionStub.cs @@ -0,0 +1,6 @@ +using Interpreter.Lib.IR.CheckSemantics.Exceptions; + +namespace Interpreter.Tests.Stubs +{ + public class SemanticExceptionStub : SemanticException { } +} \ No newline at end of file diff --git a/Interpreter.Tests/Unit/Infrastructure/ExecutorTests.cs b/Interpreter.Tests/Unit/Infrastructure/ExecutorTests.cs new file mode 100644 index 00000000..ea28a038 --- /dev/null +++ b/Interpreter.Tests/Unit/Infrastructure/ExecutorTests.cs @@ -0,0 +1,97 @@ +using System; +using System.Collections.Generic; +using Interpreter.Lib.BackEnd; +using Interpreter.Lib.BackEnd.Instructions; +using Interpreter.Lib.FrontEnd.GetTokens; +using Interpreter.Lib.FrontEnd.TopDownParse; +using Interpreter.Lib.IR.Ast; +using Interpreter.Services.Executor.Impl; +using Interpreter.Services.Parsing; +using Interpreter.Tests.Stubs; +using Microsoft.Extensions.Options; +using Moq; +using Xunit; + +namespace Interpreter.Tests.Unit.Infrastructure +{ + public class ExecutorTests + { + private readonly Mock _settings; + private readonly Mock _parsingService; + + public ExecutorTests() + { + _settings = new Mock(); + _settings.Setup(x => x.Dump).Returns(false); + _settings.Setup(x => x.InputFilePath).Returns("file.js"); + + _parsingService = new Mock(); + } + + [Fact] + public void ExecuteGoesOkTest() + { + var ast = new Mock(); + ast.Setup(x => x.GetInstructions()) + .Returns(new List { new Halt(0) }); + + _parsingService.Setup(x => x.Parse(It.IsAny())) + .Returns(ast.Object); + + var executor = new Executor(_parsingService.Object, Options.Create(_settings.Object)); + Assert.Null(Record.Exception(() => executor.Execute())); + } + + [Fact] + public void SemanticExceptionCaughtTest() + { + var ast = new Mock(); + ast.Setup(x => x.GetInstructions()) + .Throws(); + + _parsingService.Setup(x => x.Parse(It.IsAny())) + .Returns(ast.Object); + + var executor = new Executor(_parsingService.Object, Options.Create(_settings.Object)); + Assert.Null(Record.Exception(() => executor.Execute())); + } + + [Fact] + public void LexerExceptionCaughtTest() + { + _parsingService.Setup(x => x.Parse(It.IsAny())) + .Throws(); + + var executor = new Executor(_parsingService.Object, Options.Create(_settings.Object)); + Assert.Null(Record.Exception(() => executor.Execute())); + } + + [Fact] + public void ParserExceptionCaughtTest() + { + _parsingService.Setup(x => x.Parse(It.IsAny())) + .Throws(); + + var executor = new Executor(_parsingService.Object, Options.Create(_settings.Object)); + Assert.Null(Record.Exception(() => executor.Execute())); + } + + [Fact] + public void InternalInterpreterErrorCaughtTest() + { + var instruction = new Mock(MockBehavior.Default, 0); + instruction.Setup(x => x.Execute(It.IsAny())) + .Throws(); + + var ast = new Mock(); + ast.Setup(x => x.GetInstructions()) + .Returns(new List { instruction.Object, new Halt(1) }); + + _parsingService.Setup(x => x.Parse(It.IsAny())) + .Returns(ast.Object); + + var executor = new Executor(_parsingService.Object, Options.Create(_settings.Object)); + Assert.Null(Record.Exception(() => executor.Execute())); + } + } +} \ No newline at end of file diff --git a/Interpreter.Tests/Unit/Infrastructure/ParsingServiceTests.cs b/Interpreter.Tests/Unit/Infrastructure/ParsingServiceTests.cs new file mode 100644 index 00000000..37ff1181 --- /dev/null +++ b/Interpreter.Tests/Unit/Infrastructure/ParsingServiceTests.cs @@ -0,0 +1,34 @@ +using Interpreter.Lib.FrontEnd.TopDownParse; +using Interpreter.Lib.IR.Ast; +using Interpreter.Services.Parsing.Impl; +using Interpreter.Services.Providers; +using Moq; +using Xunit; + +namespace Interpreter.Tests.Unit.Infrastructure +{ + public class ParsingServiceTests + { + [Fact] + public void CertainTextHasBeenParsedTest() + { + const string text = "let x = 1 + 2 - 3"; + + var ast = new Mock(); + var parser = new Mock(); + parser.Setup(x => x.TopDownParse(It.IsAny())) + .Returns(ast.Object).Verifiable(); + + var parserProvider = new Mock(); + parserProvider.Setup(x => x.CreateParser()) + .Returns(parser.Object); + + var parsingService = new ParsingService(parserProvider.Object); + parsingService.Parse(text); + + parser.Verify(x => x.TopDownParse( + It.Is(s => s == text) + ), Times.Once()); + } + } +} \ No newline at end of file diff --git a/Interpreter.Tests/Unit/Infrastructure/ProvidersTests.cs b/Interpreter.Tests/Unit/Infrastructure/ProvidersTests.cs new file mode 100644 index 00000000..37664664 --- /dev/null +++ b/Interpreter.Tests/Unit/Infrastructure/ProvidersTests.cs @@ -0,0 +1,60 @@ +using System; +using Interpreter.Lib.FrontEnd.GetTokens; +using Interpreter.Lib.FrontEnd.GetTokens.Impl; +using Interpreter.Lib.FrontEnd.TopDownParse.Impl; +using Interpreter.Services.Providers; +using Interpreter.Services.Providers.Impl.LexerProvider; +using Interpreter.Services.Providers.Impl.ParserProvider; +using Interpreter.Tests.Stubs; +using Microsoft.Extensions.Options; +using Moq; +using Xunit; + +namespace Interpreter.Tests.Unit.Infrastructure +{ + public class ProvidersTests + { + [Theory] + [InlineData(typeof(Lexer), false)] + [InlineData(typeof(LoggingLexer), true)] + public void CertainLexerProvidedTest(Type lexerType, bool dump) + { + var options = new Mock>(); + options.Setup(x => x.Value) + .Returns(new CommandLineSettings + { + Dump = dump, + InputFilePath = "file.js" + }); + + var lexerProvider = new LexerProvider(new MapperStub(), options.Object); + var lexer = lexerProvider.CreateLexer(); + + Assert.IsType(lexerType, lexer); + } + + [Theory] + [InlineData(typeof(Parser), false)] + [InlineData(typeof(LoggingParser), true)] + public void CertainParserProvidedTest(Type parserType, bool dump) + { + var options = new Mock>(); + options.Setup(x => x.Value) + .Returns(new CommandLineSettings + { + Dump = dump, + InputFilePath = "file.js" + }); + + var lexer = new Mock(); + var lexerProvider = new Mock(); + lexerProvider.Setup(x => x.CreateLexer()) + .Returns(lexer.Object); + + var parserProvider = new ParserProvider(lexerProvider.Object, options.Object); + var parser = parserProvider.CreateParser(); + + Assert.IsType(parserType, parser); + } + } +} \ No newline at end of file diff --git a/Interpreter/CommandLineSettings.cs b/Interpreter/CommandLineSettings.cs index fccf4791..d94f1c2c 100644 --- a/Interpreter/CommandLineSettings.cs +++ b/Interpreter/CommandLineSettings.cs @@ -8,15 +8,16 @@ namespace Interpreter { [SuppressMessage("ReSharper", "UnusedMember.Global")] - [SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] [SuppressMessage("ReSharper", "PropertyCanBeMadeInitOnly.Global")] + [ExcludeFromCodeCoverage] + // ReSharper disable once ClassWithVirtualMembersNeverInherited.Global public class CommandLineSettings { [Value(0, MetaName = "InputFilePath", Required = true, HelpText = "Path to input file")] - public string InputFilePath { get; set; } + public virtual string InputFilePath { get; set; } [Option('d', "dump", Default = false, HelpText = "Show dump data of interpreter")] - public bool Dump { get; set; } + public virtual bool Dump { get; set; } [Usage(ApplicationAlias = "Interpreter")] public static IEnumerable Examples @@ -34,7 +35,7 @@ public static IEnumerable Examples public StructureModel StructureModel { get; } = new(); - public string GetText() => + public virtual string GetText() => File.ReadAllText(InputFilePath); } } \ No newline at end of file diff --git a/Interpreter/Models/StructureModel.cs b/Interpreter/Models/StructureModel.cs index f472129e..b0dbe984 100644 --- a/Interpreter/Models/StructureModel.cs +++ b/Interpreter/Models/StructureModel.cs @@ -1,8 +1,10 @@ using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using Newtonsoft.Json; namespace Interpreter.Models { + [ExcludeFromCodeCoverage] public class StructureModel { public List TokenTypes { get; } diff --git a/Interpreter/Models/TokenTypeModel.cs b/Interpreter/Models/TokenTypeModel.cs index cdddb493..580e119b 100644 --- a/Interpreter/Models/TokenTypeModel.cs +++ b/Interpreter/Models/TokenTypeModel.cs @@ -5,6 +5,7 @@ namespace Interpreter.Models // ReSharper disable once ClassNeverInstantiated.Global [SuppressMessage("ReSharper", "UnusedMember.Global")] [SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Global")] + [ExcludeFromCodeCoverage] public record TokenTypeModel { public string Tag { get; init; } diff --git a/Interpreter/Program.cs b/Interpreter/Program.cs index 3e020de7..5e2baac3 100644 --- a/Interpreter/Program.cs +++ b/Interpreter/Program.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics.CodeAnalysis; using CommandLine; using Microsoft.Extensions.DependencyInjection; using Interpreter.MappingProfiles; @@ -13,6 +14,7 @@ namespace Interpreter { + [ExcludeFromCodeCoverage] public static class Program { private static IServiceCollection ServiceCollection { get; } = new ServiceCollection();