This commit is contained in:
ninemine
2025-07-02 18:46:09 +08:00
parent 9345700d8a
commit 15878d7e3b
5 changed files with 93 additions and 23 deletions

View File

@@ -16,11 +16,6 @@ namespace Convention.Symbolization.Internal
public static readonly Dictionary<string, Keyword> Keywords = new();
public abstract SymbolizationContext Execute(SymbolizationContext context, Variable[] leftParameters, Variable[] rightParameters);
public override string ToString()
{
return SymbolInfo.SymbolName;
}
}
public abstract class Keyword<T> : Keyword where T:Keyword<T>,new()
@@ -49,19 +44,6 @@ namespace Convention.Symbolization.Internal
namespace Convention.Symbolization.Keyword
{
public sealed class ExitScope : Internal.Keyword<ExitScope>
{
public ExitScope() : base("__exit_scope__")
{
}
public override SymbolizationContext Execute(SymbolizationContext context, Internal.Variable[] leftParameters, Internal.Variable[] rightParameters)
{
context.CurrentNamespace.EndAndTApplyUpdate();
return context.ParentContext;
}
}
public sealed class Namespace : Internal.Keyword<Namespace>
{
public Namespace() : base("namespace")
@@ -80,6 +62,69 @@ namespace Convention.Symbolization.Keyword
}
}
public sealed class Return : Internal.Keyword<Return>
{
public Return() : base("return")
{
}
public override SymbolizationContext Execute(SymbolizationContext context, Internal.Variable[] leftParameters, Internal.Variable[] rightParameters)
{
if (leftParameters.Length != 0)
throw new InvalidGrammarException($"{this}: has invalid subject");
if (rightParameters.Length > 1)
throw new InvalidGrammarException($"{this}: has invalid object");
// Inject return command to context
return context;
}
}
public sealed class While : Internal.Keyword<While>
{
public While() : base("while")
{
}
public override SymbolizationContext Execute(SymbolizationContext context, Internal.Variable[] leftParameters, Internal.Variable[] rightParameters)
{
if (leftParameters.Length != 0)
throw new InvalidGrammarException($"{this}: needs to have one and only one subject");
if (rightParameters.Length != 1)
throw new InvalidGrammarException($"{this}: has invalid object");
SymbolizationContext subContext
return context;
}
}
public sealed class Break : Internal.Keyword<Break>
{
public Break() : base("break")
{
}
public override SymbolizationContext Execute(SymbolizationContext context, Internal.Variable[] leftParameters, Internal.Variable[] rightParameters)
{
if (leftParameters.Length != 0)
throw new InvalidGrammarException($"{this}: has invalid subject");
if (rightParameters.Length != 0)
throw new InvalidGrammarException($"{this}: has invalid object");
return context;
}
}
public sealed class Continue : Internal.Keyword<Continue>
{
public Continue() : base("continue")
{
}
public override SymbolizationContext Execute(SymbolizationContext context, Internal.Variable[] leftParameters, Internal.Variable[] rightParameters)
{
if (leftParameters.Length != 0)
throw new InvalidGrammarException($"{this}: has invalid subject");
if (rightParameters.Length != 0)
throw new InvalidGrammarException($"{this}: has invalid object");
return context;
}
}
public sealed class Structure : Internal.Keyword<Structure>
{
public Structure() : base("struct")
@@ -92,10 +137,21 @@ namespace Convention.Symbolization.Keyword
throw new InvalidGrammarException($"{this}: has invalid subject");
if (rightParameters.Length != 1)
throw new InvalidGrammarException($"{this}: needs to have one and only one object");
Internal.Namespace subNamespace = context.CurrentNamespace.CreateOrGetSubNamespace(rightParameters[0].ToString());
subNamespace.BeginUpdate();
SymbolizationContext subContext = new(context, subNamespace);
return subContext;
return context;
}
public sealed class Function : Internal.Keyword<Function>
{
public Function() : base("def")
{
}
public override SymbolizationContext Execute(SymbolizationContext context, Internal.Variable[] leftParameters, Internal.Variable[] rightParameters)
{
if (leftParameters.Length != 0)
throw new InvalidGrammarException($"{this}: has invalid subject");
}
}
}
}