Daily update on 20250313-044921 by Nitload Youmu. Additional Message : Parser to TokenFlag.Member, improvement of exiting StgSharp platform
Signed-off-by: Nitload <YoumuLiu_NSI@whv0t.onmicrosoft.com>
This commit is contained in:
@@ -37,6 +37,8 @@ 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
|
||||
@@ -58,6 +60,8 @@ namespace StgSharp.Script.Express
|
||||
_cache = new CompileStack<ExpNode, IExpElementSource>();
|
||||
}
|
||||
|
||||
/**/
|
||||
|
||||
/// <summary>
|
||||
/// Append a token to top of cache. This method will automatically convert token to node if
|
||||
/// meets separators or operators.
|
||||
@@ -65,6 +69,7 @@ namespace StgSharp.Script.Express
|
||||
public void AppendToken( Token expToken )
|
||||
{
|
||||
switch( expToken.Flag ) {
|
||||
// operand, check precedence and push
|
||||
case TokenFlag.Symbol_Unary or TokenFlag.Symbol_Binary:
|
||||
int cmp = -1;
|
||||
processPrecedence:
|
||||
@@ -76,17 +81,37 @@ namespace StgSharp.Script.Express
|
||||
}
|
||||
_cache.PushOperand( expToken );
|
||||
break;
|
||||
|
||||
// literal, construxt and ppush
|
||||
case TokenFlag.Number or TokenFlag.String:
|
||||
_cache.PushOperand( expToken );
|
||||
break;
|
||||
|
||||
// instance ref, make ref and push
|
||||
// function call, push as operator
|
||||
// keyword, call TryParseKeyWord method to process
|
||||
// name of member in instance, parse as MemberNameNode
|
||||
case TokenFlag.Member:
|
||||
if( _context.TryGetFunction( expToken.Value, out _ ) ) {
|
||||
_cache.PushOperator( expToken );
|
||||
} else { }
|
||||
} else if( _local.TryGetMember(
|
||||
expToken.Value, out ExpNode? node ) ) {
|
||||
if( node is ExpElementInstanceBase instance ) {
|
||||
_cache.PushOperand(
|
||||
instance.MakeReference( expToken ) );
|
||||
return; // ref of an instance
|
||||
}
|
||||
} else if( TryParseKeyWord( expToken ) ) {
|
||||
return;
|
||||
} else {
|
||||
_cache.PushOperand(
|
||||
new ExpElementMemberNameNode( expToken ) );
|
||||
}
|
||||
break;
|
||||
case TokenFlag.Separator_Single: //a , ; found
|
||||
// if operator stack is not empty, convert all operators to node until meet a same separator
|
||||
// or OperandAheadOfSeparator property is less than certain value
|
||||
_cache.PushOperator( expToken );
|
||||
break;
|
||||
case TokenFlag.Separator_Left: //a ( [ { found
|
||||
// check if the last token is a function name, loop block or branch
|
||||
@@ -110,6 +135,8 @@ namespace StgSharp.Script.Express
|
||||
if( _cache.PopOperand( out Token t, out ExpNode? n ) ) {
|
||||
return n;
|
||||
} else { }
|
||||
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -134,5 +161,20 @@ namespace StgSharp.Script.Express
|
||||
}
|
||||
}
|
||||
|
||||
private bool TryParseKeyWord( Token t )
|
||||
{
|
||||
if( t.Value == ExpKeyWord.True ) {
|
||||
_cache.PushOperand( new ExpBoolNode( t, true ) );
|
||||
return true;
|
||||
} else if( t.Value == ExpKeyWord.False ) {
|
||||
_cache.PushOperand( new ExpBoolNode( t, false ) );
|
||||
return true;
|
||||
} else if( true ) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**/
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user