Daily update on 20250305-052510 by Nitload Youmu. Additional Message : message
Signed-off-by: Nitload <YoumuLiu_NSI@whv0t.onmicrosoft.com>
This commit is contained in:
@@ -83,8 +83,8 @@ namespace StgSharp.Script.Express
|
||||
Remove = "REMOVE",
|
||||
ANDOR = "ANDOR",
|
||||
GetIndex = "[",
|
||||
UnaryAdd = "+",
|
||||
UnarySub = "-",
|
||||
UnaryPlus = "+",
|
||||
UnaryMinus = "-",
|
||||
Exp = "**";
|
||||
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ namespace StgSharp.Script.Express
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => _operand.EqualityTypeConvert;
|
||||
|
||||
public static ExpUnaryOperatorNode UnaryNegation( ExpNode operand )
|
||||
public static ExpUnaryOperatorNode UnaryMinus( ExpNode operand )
|
||||
{
|
||||
if( !operand.IsNumber ) {
|
||||
throw new ExpInvalidTypeException(
|
||||
@@ -87,5 +87,20 @@ namespace StgSharp.Script.Express
|
||||
};
|
||||
}
|
||||
|
||||
public static ExpUnaryOperatorNode UnaryPlus( ExpNode operand )
|
||||
{
|
||||
if( !operand.IsNumber ) {
|
||||
throw new ExpInvalidTypeException(
|
||||
"Number", operand.EqualityTypeConvert.Name );
|
||||
}
|
||||
bool isFloat =
|
||||
( operand._nodeFlag | ExpNodeFlag.BuiltinType_Float ) == 0;
|
||||
return new ExpUnaryOperatorNode( ExpCompile.KeyWord.SUB )
|
||||
{
|
||||
_nodeFlag = ExpNodeFlag.Operator_Unary | ExpNodeFlag.BuiltinType_Number,
|
||||
CodeConvertTemplate = "+ {0}",
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ using CommunityToolkit.HighPerformance.Buffers;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
@@ -96,11 +97,11 @@ namespace StgSharp.Script.Express
|
||||
|
||||
public string Name => _name;
|
||||
|
||||
public virtual void AppendNode( ExpNode nextToken )
|
||||
public void AppendNode( ExpNode nextNode )
|
||||
{
|
||||
Next.Previous = nextToken;
|
||||
nextToken.Next = Next;
|
||||
Next = nextToken;
|
||||
Next.Previous = nextNode;
|
||||
nextNode.Next = Next;
|
||||
Next = nextNode;
|
||||
Next.Previous = this;
|
||||
}
|
||||
|
||||
@@ -114,6 +115,20 @@ namespace StgSharp.Script.Express
|
||||
return node == ExpEmptyNode._only || node == null;
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static ExpNode NonOperation( string name )
|
||||
{
|
||||
return new ExpEmptyNode( name );
|
||||
}
|
||||
|
||||
public void PrependNode( ExpNode previousNode )
|
||||
{
|
||||
Previous.Next = previousNode;
|
||||
previousNode.Previous = Previous;
|
||||
Previous = previousNode;
|
||||
previousNode.Next = this;
|
||||
}
|
||||
|
||||
public static bool VerifyTypeConvertable( ExpNode left, ExpNode right )
|
||||
{
|
||||
IExpElementSource tLeft = left.EqualityTypeConvert,
|
||||
@@ -131,6 +146,8 @@ namespace StgSharp.Script.Express
|
||||
|
||||
public ExpEmptyNode() : base( string.Empty ) { }
|
||||
|
||||
public ExpEmptyNode( string name ) : base( name ) { }
|
||||
|
||||
public override ExpInstantiableElement EqualityTypeConvert => ExpInstantiableElement.Void;
|
||||
|
||||
public override ExpNode Left => _only;
|
||||
|
||||
@@ -66,88 +66,55 @@ namespace StgSharp.Script.Express
|
||||
/// meets separators or operators.
|
||||
/// </summary>
|
||||
/// <param name="expToken"></param>
|
||||
public void AppendToken( Token expToken )
|
||||
public ExpNode AppendToken( Token expToken )
|
||||
{
|
||||
switch( expToken.Flag ) {
|
||||
case TokenFlag.Symbol_Unary or TokenFlag.Symbol_Binary:
|
||||
|
||||
_operandsToken.Push( expToken );
|
||||
break;
|
||||
case TokenFlag.Number or TokenFlag.String or TokenFlag.Member:
|
||||
break;
|
||||
case TokenFlag.Separator_Single:
|
||||
case TokenFlag.Separator_Single: // a , ; found
|
||||
break;
|
||||
case TokenFlag.Separator_Left:
|
||||
case TokenFlag.Separator_Left: //a ( [ { found
|
||||
break;
|
||||
case TokenFlag.Separator_Right:
|
||||
case TokenFlag.Separator_Right: //a } ] ) found
|
||||
break;
|
||||
case TokenFlag.Index_Left:
|
||||
case TokenFlag.Index_Left: // a [ found
|
||||
break;
|
||||
case TokenFlag.Index_Right:
|
||||
case TokenFlag.Index_Right: // a ] found
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void CacheNextOperandNode( ExpNode node )
|
||||
public ExpNode GetNextOperandCache()
|
||||
{
|
||||
_operandsNode.Push( node );
|
||||
if( _operandsNode.Count != 0 ) {
|
||||
return _operandsNode.Pop();
|
||||
}
|
||||
if( _operandsToken.Count != 0 ) {
|
||||
Token token = _operandsToken.Pop();
|
||||
}
|
||||
return ExpNode.Empty;
|
||||
}
|
||||
|
||||
public AbstractSyntaxTree<ExpNode, IExpElementSource> CloseAndDispose()
|
||||
//ConvertOneOperator not finish
|
||||
private void ConvertOneOperator()
|
||||
{
|
||||
if( _operandsToken.Count != 0 ) {
|
||||
// convert rest to AST
|
||||
}
|
||||
return new AbstractSyntaxTree<ExpNode, IExpElementSource>();
|
||||
}
|
||||
/*
|
||||
public ExpNode GenerateNode( Token t )
|
||||
{
|
||||
switch( t.Flag ) {
|
||||
Token @operator = _operators.Pop();
|
||||
switch( @operator.Flag ) {
|
||||
case TokenFlag.Symbol_Unary:
|
||||
break;
|
||||
case TokenFlag.Symbol_Binary:
|
||||
break;
|
||||
case TokenFlag.Number:
|
||||
break;
|
||||
case TokenFlag.String:
|
||||
break;
|
||||
case TokenFlag.Member:
|
||||
break;
|
||||
case TokenFlag.Separator_Single:
|
||||
break;
|
||||
case TokenFlag.Separator_Left:
|
||||
break;
|
||||
case TokenFlag.Separator_Right:
|
||||
break;
|
||||
case TokenFlag.Index_Left:
|
||||
break;
|
||||
case TokenFlag.Index_Right:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
/**/
|
||||
|
||||
public int GetNextOperandCache( out Token? token, out ExpNode? node )
|
||||
{
|
||||
if( _operandsNode.Count != 0 ) {
|
||||
node = _operandsNode.Pop();
|
||||
token = null!;
|
||||
return 2;
|
||||
}
|
||||
if( _operandsToken.Count != 0 ) {
|
||||
token = _operandsToken.Pop();
|
||||
node = null!;
|
||||
return 1;
|
||||
}
|
||||
token = null;
|
||||
node = null!;
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="FunctionCallingGenerator.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using static StgSharp.Script.Express.ExpCompile;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public partial class ExpNodeGenerator
|
||||
{
|
||||
|
||||
private bool _isCallingFunction = false;
|
||||
private Stack<int> _callDepth = new Stack<int>();
|
||||
|
||||
private void EnterFunctionCalling( Token funcNameToken )
|
||||
{
|
||||
_isCallingFunction = true;
|
||||
_callDepth.Push( _operandsToken.Count );
|
||||
}
|
||||
|
||||
private void ExitFunctionCalling()
|
||||
{
|
||||
_callDepth.Pop();
|
||||
if( _callDepth.Count == 0 ) {
|
||||
_isCallingFunction = false;
|
||||
}
|
||||
}
|
||||
|
||||
//TODO cannot process occasion of void input or null at first
|
||||
private void MergeFunctionCallingParameter()
|
||||
{
|
||||
if( _callDepth.Peek() == _operandsToken.Count ) {
|
||||
_operandsNode.Peek()
|
||||
.PrependNode(
|
||||
ExpNode.NonOperation( PoolString( "FuncParam" ) ) );
|
||||
} else {
|
||||
//TODO compile the param expression
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -38,21 +38,48 @@ namespace StgSharp.Script.Express
|
||||
{
|
||||
public partial class ExpNodeGenerator
|
||||
{
|
||||
/*
|
||||
public ExpNode GenerateUnaryToken( Token t )
|
||||
|
||||
public bool TryGenerateBinaryNode( Token t, out ExpNode node )
|
||||
{
|
||||
ExpNode left = GetNextOperandCache();
|
||||
ExpNode right = GetNextOperandCache();
|
||||
switch( t.Value ) {
|
||||
case ExpCompile.KeyWord.UnaryAdd:
|
||||
break;
|
||||
case ExpCompile.KeyWord.UnarySub:
|
||||
break;
|
||||
case ExpCompile.KeyWord.NOT:
|
||||
break;
|
||||
case ExpCompile.KeyWord.ADD:
|
||||
node = ExpBinaryOperatorNode.Add( left, right );
|
||||
return true;
|
||||
case ExpCompile.KeyWord.SUB:
|
||||
node = ExpBinaryOperatorNode.Sub( left, right );
|
||||
return true;
|
||||
case ExpCompile.KeyWord.MUL:
|
||||
node = ExpBinaryOperatorNode.Mul( left, right );
|
||||
return true;
|
||||
case ExpCompile.KeyWord.DIV:
|
||||
node = ExpBinaryOperatorNode.Div( left, right );
|
||||
return true;
|
||||
default:
|
||||
break;
|
||||
node = ExpNode.Empty;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool TryGenerateUnaryNode( Token t, out ExpNode node )
|
||||
{
|
||||
ExpNode operand = GetNextOperandCache();
|
||||
switch( t.Value ) {
|
||||
case ExpCompile.KeyWord.UnaryPlus:
|
||||
node = ExpUnaryOperatorNode.UnaryPlus( operand );
|
||||
return true;
|
||||
case ExpCompile.KeyWord.UnaryMinus:
|
||||
node = ExpUnaryOperatorNode.UnaryMinus( operand );
|
||||
return true;
|
||||
case ExpCompile.KeyWord.NOT:
|
||||
node = ExpUnaryOperatorNode.UnaryNot( operand );
|
||||
return true;
|
||||
default:
|
||||
node = ExpNode.Empty;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**/
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user