From 446d889b882d66e83180b1dcae8b2d5e4e751131 Mon Sep 17 00:00:00 2001 From: Edward Sabinus <edward.sabinus@informatik.uni-halle.de> Date: Fri, 17 Nov 2023 17:06:37 +0100 Subject: [PATCH] Implemented ExitFTreeleaf for building TreeLeafs for function Trees --- .../BewerterStrukturellerInduktion.sln | 16 ++++++------- .../Eingabeverwaltung/Parser/ADT_Listener.cs | 24 ++++++++++--------- .../Parser/Listener_Helper.cs | 22 +++++++++++++++-- 3 files changed, 41 insertions(+), 21 deletions(-) diff --git a/BewerterStrukturellerInduktion/BewerterStrukturellerInduktion.sln b/BewerterStrukturellerInduktion/BewerterStrukturellerInduktion.sln index aeb1d62..ffb2ed4 100644 --- a/BewerterStrukturellerInduktion/BewerterStrukturellerInduktion.sln +++ b/BewerterStrukturellerInduktion/BewerterStrukturellerInduktion.sln @@ -1,9 +1,9 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.30413.136 +# Visual Studio Version 17 +VisualStudioVersion = 17.8.34309.116 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BaumtransformationBewerter", "BaumtransformationBewerter.csproj", "{92368058-E4B1-446D-8CCD-DC95512F9CA6}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BewerterStrukturellerInduktion", "BewerterStrukturellerInduktion.csproj", "{2DF4D10C-09B1-46FD-B0FA-FE10C08199C4}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -11,15 +11,15 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {92368058-E4B1-446D-8CCD-DC95512F9CA6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {92368058-E4B1-446D-8CCD-DC95512F9CA6}.Debug|Any CPU.Build.0 = Debug|Any CPU - {92368058-E4B1-446D-8CCD-DC95512F9CA6}.Release|Any CPU.ActiveCfg = Release|Any CPU - {92368058-E4B1-446D-8CCD-DC95512F9CA6}.Release|Any CPU.Build.0 = Release|Any CPU + {2DF4D10C-09B1-46FD-B0FA-FE10C08199C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2DF4D10C-09B1-46FD-B0FA-FE10C08199C4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2DF4D10C-09B1-46FD-B0FA-FE10C08199C4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2DF4D10C-09B1-46FD-B0FA-FE10C08199C4}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {CC6FE5A7-3FC6-4A91-858E-CF70F4CFCB8F} + SolutionGuid = {F701E637-8DE3-434E-B944-AAB6E73E4DA4} EndGlobalSection EndGlobal diff --git a/BewerterStrukturellerInduktion/Eingabeverwaltung/Parser/ADT_Listener.cs b/BewerterStrukturellerInduktion/Eingabeverwaltung/Parser/ADT_Listener.cs index e2c1edc..2290aec 100644 --- a/BewerterStrukturellerInduktion/Eingabeverwaltung/Parser/ADT_Listener.cs +++ b/BewerterStrukturellerInduktion/Eingabeverwaltung/Parser/ADT_Listener.cs @@ -141,25 +141,27 @@ namespace Eingabeverwaltung.Parser public void EnterTreeLeaf([NotNull] ADTParser.TreeLeafContext context) { } public void ExitTreeLeaf([NotNull] ADTParser.TreeLeafContext context) - => LH.ExitTreeLeaf(context.BEZ().GetText()); + => LH.ExitTreeLeaf(context.BEZ().GetText(),new Listener_Helper.Coords(context.Start.Line,context.Start.Column)); public void EnterTreeNode([NotNull] ADTParser.TreeNodeContext context) { } public void ExitTreeNode([NotNull] ADTParser.TreeNodeContext context) - => LH.ExitTreeNode(context.BEZ().GetText(), context.ChildCount, context.GetText()); + => LH.ExitTreeNode(context.BEZ().GetText(), context.ChildCount, context.GetText(), new Listener_Helper.Coords(context.Start.Line, context.Start.Column)); // function Trees - public void EnterFTree([NotNull] ADTParser.FTreeContext context) => throw new NotImplementedException(); + public void EnterFTree([NotNull] ADTParser.FTreeContext context) { } - public void ExitFTree([NotNull] ADTParser.FTreeContext context) => throw new NotImplementedException(); + public void ExitFTree([NotNull] ADTParser.FTreeContext context) + => LH.ExitFTreeNode(context.BEZ().GetText(), context.ChildCount, context.GetText(), new Listener_Helper.Coords(context.Start.Line, context.Start.Column)); + public void EnterFTreeBracketFree([NotNull] ADTParser.FTreeBracketFreeContext context) { } + public void ExitFTreeBracketFree([NotNull] ADTParser.FTreeBracketFreeContext context) + => LH.ExitFTreeNode(context.BEZ().GetText(), context.ChildCount, context.GetText(), new Listener_Helper.Coords(context.Start.Line, context.Start.Column)); - public void EnterFTreeBracketFree([NotNull] ADTParser.FTreeBracketFreeContext context) => throw new NotImplementedException(); - public void ExitFTreeBracketFree([NotNull] ADTParser.FTreeBracketFreeContext context) => throw new NotImplementedException(); + public void EnterTreeBracket([NotNull] ADTParser.TreeBracketContext context) { } + public void ExitTreeBracket([NotNull] ADTParser.TreeBracketContext context) { } - public void EnterTreeBracket([NotNull] ADTParser.TreeBracketContext context) => throw new NotImplementedException(); - public void ExitTreeBracket([NotNull] ADTParser.TreeBracketContext context) => throw new NotImplementedException(); + public void EnterTreeBez([NotNull] ADTParser.TreeBezContext context) { } - public void EnterTreeBez([NotNull] ADTParser.TreeBezContext context) => throw new NotImplementedException(); - - public void ExitTreeBez([NotNull] ADTParser.TreeBezContext context) => throw new NotImplementedException(); + public void ExitTreeBez([NotNull] ADTParser.TreeBezContext context) + => LH.ExitFTreeLeaf(context.BEZ().GetText(), new Listener_Helper.Coords(context.Start.Line, context.Start.Column)); // useless Interface requirements public void EnterEveryRule(ParserRuleContext ctx) { } diff --git a/BewerterStrukturellerInduktion/Eingabeverwaltung/Parser/Listener_Helper.cs b/BewerterStrukturellerInduktion/Eingabeverwaltung/Parser/Listener_Helper.cs index 532f912..7c5c4c6 100644 --- a/BewerterStrukturellerInduktion/Eingabeverwaltung/Parser/Listener_Helper.cs +++ b/BewerterStrukturellerInduktion/Eingabeverwaltung/Parser/Listener_Helper.cs @@ -79,8 +79,8 @@ namespace Eingabeverwaltung.Parser adt_vars.Add(new Variable(variableName, sort)); } - public void ExitTreeLeaf(string treeName) => ExitTreeLeaf(treeName,new Coords(-1,-1)); - // Trees + // classic Trees + public void ExitTreeLeaf(string treeName) => ExitTreeLeaf(treeName, new Coords(-1, -1)); /// <summary> /// TreeLeaf is whether a Variable or a constant (ComposedTree without children) /// </summary> @@ -128,6 +128,24 @@ namespace Eingabeverwaltung.Parser } } + // function Trees + public void ExitFTreeLeaf(string treeName, Coords coords) + { + Tree result = null; + Variable variable = findVariableInADT_Vars(treeName); + if (variable != null) + result = new TreeVariable(variable); + else + { + Operation operation = findOperationInADT_Ops(treeName, -1, false, coords); // can't test it here because of structure of fTrees + if (operation != null) + result = new ComposedTree(operation, new List<Tree>()); + } + if (result == null) throw new ParsingException(coords,"The Tree " + treeName + " could not be found in Vars or Operations of the ADT!"); + trees.Add(result); + + } + // Helping functions /// <summary> -- GitLab