Daily update on 20250323-080223 by Nitload Youmu. Additional Message : Unit test(not included in public repo) and syntax reverse analyzer
Signed-off-by: Nitload <YoumuLiu_NSI@whv0t.onmicrosoft.com>
This commit is contained in:
@@ -50,7 +50,76 @@ namespace StgSharp.Script.Express
|
|||||||
return leftPrecedence - rightPrecedence;
|
return leftPrecedence - rightPrecedence;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool TryGenerateBinaryNode( Token t, out ExpNode node )
|
public bool TryGenerateUnaryNode( Token t, out ExpNode node )
|
||||||
|
{
|
||||||
|
ExpNode operand = GetNextOperandCache();
|
||||||
|
switch( t.Value ) {
|
||||||
|
case ExpKeyword.UnaryPlus:
|
||||||
|
node = ExpUnaryOperatorNode.UnaryPlus( t, operand );
|
||||||
|
return true;
|
||||||
|
case ExpKeyword.UnaryMinus:
|
||||||
|
node = ExpUnaryOperatorNode.UnaryMinus( t, operand );
|
||||||
|
return true;
|
||||||
|
case ExpKeyword.Not:
|
||||||
|
node = ExpUnaryOperatorNode.UnaryNot( t, operand );
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
node = ExpNode.Empty;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// WARNING: This method cannot process INDEXOF, FUNCTION CALLING, LOOP and any ENDING
|
||||||
|
/// SYMBOLS.
|
||||||
|
/// </summary>
|
||||||
|
private ExpNode ConvertOneOperator( Token op )
|
||||||
|
{
|
||||||
|
switch( op.Flag ) {
|
||||||
|
case TokenFlag.Symbol_Unary:
|
||||||
|
TryGenerateUnaryNode( op, out ExpNode? node );
|
||||||
|
_cache.PushOperand( node );
|
||||||
|
return node;
|
||||||
|
case TokenFlag.Symbol_Binary:
|
||||||
|
TryGenerateBinaryNode( op, out node );
|
||||||
|
_cache.PushOperand( node );
|
||||||
|
return node;
|
||||||
|
case TokenFlag.Member:
|
||||||
|
if( _context.TryGetFunction(
|
||||||
|
op.Value, out ExpFunctionSource? f ) ) {
|
||||||
|
if( !_cache.PopOperand( out Token t,
|
||||||
|
out ExpNode? p ) ) {
|
||||||
|
node = ExpFunctionCallingNode.CallFunction(
|
||||||
|
op, f, p );
|
||||||
|
return node;
|
||||||
|
} else {
|
||||||
|
throw new ExpCompileException(
|
||||||
|
t,
|
||||||
|
"An ExpNode for function calling is needed, but a token was popped" );
|
||||||
|
}
|
||||||
|
} else if( ExpSchema.BuiltinSchema
|
||||||
|
.TryGetFunction( op.Value, out f ) ) {
|
||||||
|
if( !_cache.PopOperand( out Token t,
|
||||||
|
out ExpNode? p ) ) {
|
||||||
|
node = ExpFunctionCallingNode.CallFunction(
|
||||||
|
op, f, p );
|
||||||
|
return node;
|
||||||
|
} else {
|
||||||
|
throw new ExpCompileException(
|
||||||
|
t,
|
||||||
|
"An ExpNode for function calling is needed, but a token was popped" );
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
|
||||||
|
//uncertain case here
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool TryGenerateBinaryNode( Token t, out ExpNode node )
|
||||||
{
|
{
|
||||||
ExpNode left = GetNextOperandCache();
|
ExpNode left = GetNextOperandCache();
|
||||||
ExpNode right = GetNextOperandCache();
|
ExpNode right = GetNextOperandCache();
|
||||||
@@ -85,71 +154,5 @@ namespace StgSharp.Script.Express
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool TryGenerateUnaryNode( Token t, out ExpNode node )
|
|
||||||
{
|
|
||||||
ExpNode operand = GetNextOperandCache();
|
|
||||||
switch( t.Value ) {
|
|
||||||
case ExpKeyword.UnaryPlus:
|
|
||||||
node = ExpUnaryOperatorNode.UnaryPlus( t, operand );
|
|
||||||
return true;
|
|
||||||
case ExpKeyword.UnaryMinus:
|
|
||||||
node = ExpUnaryOperatorNode.UnaryMinus( t, operand );
|
|
||||||
return true;
|
|
||||||
case ExpKeyword.Not:
|
|
||||||
node = ExpUnaryOperatorNode.UnaryNot( t, operand );
|
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
node = ExpNode.Empty;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// WARNING: This method cannot process INDEXOF, FUNCTION CALLING, LOOP and any ENDING
|
|
||||||
/// SYMBOLS.
|
|
||||||
/// </summary>
|
|
||||||
private void ConvertOneOperator()
|
|
||||||
{
|
|
||||||
Token @operator = _cache.PopOperator();
|
|
||||||
|
|
||||||
switch( @operator.Flag ) {
|
|
||||||
case TokenFlag.Symbol_Unary:
|
|
||||||
TryGenerateUnaryNode( @operator, out ExpNode? node );
|
|
||||||
_cache.PushOperand( node );
|
|
||||||
break;
|
|
||||||
case TokenFlag.Symbol_Binary:
|
|
||||||
TryGenerateBinaryNode( @operator, out node );
|
|
||||||
_cache.PushOperand( node );
|
|
||||||
break;
|
|
||||||
case TokenFlag.Member:
|
|
||||||
if( _context.TryGetFunction(
|
|
||||||
@operator.Value, out ExpFunctionSource? f ) ) {
|
|
||||||
if( !_cache.PopOperand( out Token t,
|
|
||||||
out ExpNode? p ) ) {
|
|
||||||
ExpFunctionCallingNode.CallFunction(
|
|
||||||
@operator, f, p );
|
|
||||||
} else {
|
|
||||||
throw new ExpCompileException(
|
|
||||||
t,
|
|
||||||
"An ExpNode for function calling is needed, but a token was popped" );
|
|
||||||
}
|
|
||||||
} else if( ExpSchema.BuiltinSchema
|
|
||||||
.TryGetFunction( @operator.Value, out f ) ) {
|
|
||||||
if( !_cache.PopOperand( out Token t,
|
|
||||||
out ExpNode? p ) ) {
|
|
||||||
ExpFunctionCallingNode.CallFunction(
|
|
||||||
@operator, f, p );
|
|
||||||
} else {
|
|
||||||
throw new ExpCompileException(
|
|
||||||
t,
|
|
||||||
"An ExpNode for function calling is needed, but a token was popped" );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,92 @@
|
|||||||
|
//-----------------------------------------------------------------------
|
||||||
|
//-----------------------------------------------------------------------
|
||||||
|
// file="ExpNodeGenerator.PrefixReverseAnalysing.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.ComponentModel.DataAnnotations;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
using ExpKeyword = StgSharp.Script.Express.ExpCompile.KeyWord;
|
||||||
|
|
||||||
|
namespace StgSharp.Script.Express
|
||||||
|
{
|
||||||
|
public partial class ExpNodeGenerator
|
||||||
|
{
|
||||||
|
|
||||||
|
private void ClosePrefixReverse( Token rightSeparator )
|
||||||
|
{
|
||||||
|
Token op;
|
||||||
|
while( _cache.TryPopOperator( out op ) ) {
|
||||||
|
if( op.Value == ExpKeyword.Comma ) {
|
||||||
|
if( !_cache.TryPopOperand(
|
||||||
|
out bool isNode, out Token t1, out ExpNode? n1 ) ) {
|
||||||
|
throw new ExpCompileException(
|
||||||
|
op, "No expression before a comma" );
|
||||||
|
}
|
||||||
|
if( !isNode ) {
|
||||||
|
//On some occasions, a token may found,
|
||||||
|
//but the processor is not implemented
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
if( !_cache.TryPopOperand(
|
||||||
|
out isNode, out Token t2, out ExpNode? n2 ) ) {
|
||||||
|
throw new ExpCompileException(
|
||||||
|
op, "No expression before a comma" );
|
||||||
|
}
|
||||||
|
if( !isNode ) {
|
||||||
|
//On some occasions, a token may found,
|
||||||
|
//but the processor is not implemented
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
n1.PrependNode( n2 );
|
||||||
|
_cache.PushOperand( n1 );
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
ConvertOneOperator( op );
|
||||||
|
|
||||||
|
ExpNode node = GetNextOperandCache();
|
||||||
|
_cache.PushOperand( node );
|
||||||
|
}
|
||||||
|
if( !_cache.TryPopOperand( out _, out _, out ExpNode? root ) ) {
|
||||||
|
_cache.PushOperand( ExpNode.Empty );
|
||||||
|
}
|
||||||
|
_cache.DecreaseDepth();
|
||||||
|
if( IsSeparatorMatch( _cache.PeekOperator(), rightSeparator ) ) {
|
||||||
|
_cache.PopOperator();
|
||||||
|
} else {
|
||||||
|
// some unexpected occasions
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -41,14 +41,19 @@ namespace StgSharp.Script.Express
|
|||||||
public partial class ExpNodeGenerator
|
public partial class ExpNodeGenerator
|
||||||
{
|
{
|
||||||
|
|
||||||
private bool IsSeparatorMatch( Token source, Token target )
|
private bool IsSeparatorMatch(
|
||||||
|
Token leftSperator,
|
||||||
|
Token rightSeparator )
|
||||||
{
|
{
|
||||||
return source.Value switch
|
return leftSperator.Value switch
|
||||||
{
|
{
|
||||||
ExpKeyword.LeftBrace => target.Value == ExpKeyword.RightBrace,
|
ExpKeyword.LeftBrace => rightSeparator.Value ==
|
||||||
ExpKeyword.LeftParen => target.Value == ExpKeyword.RightParen,
|
ExpKeyword.RightBrace,
|
||||||
ExpKeyword.Comma => target.Value == ExpKeyword.Comma,
|
ExpKeyword.LeftParen => rightSeparator.Value ==
|
||||||
ExpKeyword.Semicolon => target.Value == ExpKeyword.Semicolon,
|
ExpKeyword.RightParen,
|
||||||
|
ExpKeyword.Comma => rightSeparator.Value == ExpKeyword.Comma,
|
||||||
|
ExpKeyword.Semicolon => rightSeparator.Value ==
|
||||||
|
ExpKeyword.Semicolon,
|
||||||
_ => false
|
_ => false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -76,9 +81,15 @@ namespace StgSharp.Script.Express
|
|||||||
}
|
}
|
||||||
|
|
||||||
//reverse building
|
//reverse building
|
||||||
|
ClosePrefixReverse( t );
|
||||||
|
|
||||||
//make index node
|
//make index node
|
||||||
_cache.PushOperand( ExpCollectionIndexNode.Create( t ) );
|
_cache.PopOperand( out _, out ExpNode? expNode );
|
||||||
|
if( !_cache.PopOperand(
|
||||||
|
out Token colleToken, out ExpNode? colleNode ) ) { }
|
||||||
|
_cache.PushOperand(
|
||||||
|
ExpCollectionIndexNode.Create(
|
||||||
|
t, ( colleNode as ExpCollectionInstanceBase )!, expNode ) );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,7 +139,8 @@ namespace StgSharp.Script.Express
|
|||||||
_cache.PushOperand( t );
|
_cache.PushOperand( t );
|
||||||
_cache.PushOperator( t );
|
_cache.PushOperator( t );
|
||||||
} else {
|
} else {
|
||||||
ConvertOneOperator();
|
ExpNode node = ConvertOneOperator( op );
|
||||||
|
_cache.PushOperand( node );
|
||||||
goto processOperator;
|
goto processOperator;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -158,9 +170,7 @@ namespace StgSharp.Script.Express
|
|||||||
if( t.Flag != TokenFlag.Separator_Right ) {
|
if( t.Flag != TokenFlag.Separator_Right ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
ClosePrefixReverse( t );
|
||||||
//convert all operator to node until meet a prefix separator
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,11 +183,13 @@ namespace StgSharp.Script.Express
|
|||||||
|
|
||||||
int cmp = -1;
|
int cmp = -1;
|
||||||
processPrecedence:
|
processPrecedence:
|
||||||
Token tmp = _cache.PeekOperator();
|
if( _cache.TryPopOperator( out Token tmp ) ) {
|
||||||
cmp = CompareOperatorPrecedence( t, tmp );
|
cmp = CompareOperatorPrecedence( t, tmp );
|
||||||
if( cmp <= 0 ) {
|
if( cmp <= 0 ) {
|
||||||
ConvertOneOperator();
|
ExpNode node = ConvertOneOperator( tmp );
|
||||||
goto processPrecedence;
|
_cache.PushOperand( node );
|
||||||
|
goto processPrecedence;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_cache.PushOperand( t );
|
_cache.PushOperand( t );
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ using System.Reflection;
|
|||||||
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp.Script")]
|
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp.Script")]
|
||||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+6788bc4a0065508d7afa5f740da1b4ca6dd1efef")]
|
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+e73d2fd7fb4e601c32cee66e276f219fc9b4a377")]
|
||||||
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp.Script")]
|
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp.Script")]
|
||||||
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Script")]
|
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Script")]
|
||||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\内核源代码\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/6788bc4a0065508d7afa5f740da1b4ca6dd1efef/*"}}
|
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\内核源代码\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/e73d2fd7fb4e601c32cee66e276f219fc9b4a377/*"}}
|
||||||
Reference in New Issue
Block a user