Daily update on 20250323-151439 by Nitload Youmu. Additional Message : none

Signed-off-by: Nitload <YoumuLiu_NSI@whv0t.onmicrosoft.com>
This commit is contained in:
Nitload
2025-03-23 15:14:39 +08:00
parent 528d0c5462
commit 148b0fed4a
29 changed files with 313 additions and 178 deletions
@@ -14,7 +14,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp.Model")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+6788bc4a0065508d7afa5f740da1b4ca6dd1efef")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+528d0c5462b4d3da107ad29b859f9c8006fb675a")]
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp.Model")]
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Model")]
[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/528d0c5462b4d3da107ad29b859f9c8006fb675a/*"}}
@@ -103,7 +103,7 @@ namespace StgSharp.Script.Express
public override int Count => _collection.Length;
public override string Name => ExpCompile.PoolString( "ARRAY" );
public override string Name => ExpressCompile.PoolString( "ARRAY" );
public override ExpNode CreateInstanceNode()
{
@@ -128,7 +128,7 @@ namespace StgSharp.Script.Express
public override int Count => _collection.Count;
public override string Name => ExpCompile.PoolString( "BAG" );
public override string Name => ExpressCompile.PoolString( "BAG" );
public override ExpNode CreateInstanceNode()
{
@@ -152,7 +152,7 @@ namespace StgSharp.Script.Express
public override int Count => _collection.Count;
public override string Name => ExpCompile.PoolString( "LIST" );
public override string Name => ExpressCompile.PoolString( "LIST" );
public override ExpNode CreateInstanceNode()
{
@@ -175,7 +175,7 @@ namespace StgSharp.Script.Express
public override int Count => _collection.Count;
public override string Name => ExpCompile.PoolString( "SET" );
public override string Name => ExpressCompile.PoolString( "SET" );
public void Add( ExpElementInstanceBase token )
{
@@ -36,7 +36,7 @@ using System.Threading.Tasks;
namespace StgSharp.Script.Express
{
public static partial class ExpCompile
public static partial class ExpressCompile
{
public static ExpTypeSource ExpInt
@@ -34,23 +34,23 @@ using System.Collections.Frozen;
using System.Collections.Generic;
using System.Linq;
using static StgSharp.Script.Express.ExpCompile;
using static StgSharp.Script.Express.ExpressCompile;
namespace StgSharp.Script.Express
{
internal partial class ExpSchema_Nitload : ExpSchema
internal partial class ExpSchema_Builtin : ExpSchema
{
private static readonly ExpSchema_Nitload _onlyInstance = new ExpSchema_Nitload(
private static readonly ExpSchema_Builtin _onlyInstance = new ExpSchema_Builtin(
);
private ExpSchema_Nitload()
private ExpSchema_Builtin()
: base()
{
Name = "Nitload";
}
internal static ExpSchema_Nitload Only
internal static ExpSchema_Builtin Only
{
get => _onlyInstance;
}
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpCompile.cs"
// file="ExpressCompile.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
@@ -42,7 +42,7 @@ using System.Text;
namespace StgSharp.Script.Express
{
public static partial class ExpCompile
public static partial class ExpressCompile
{
private static string[] _operatorsWithLetter;
@@ -82,7 +82,7 @@ namespace StgSharp.Script.Express
_compileStringCache = new StringPool();
_multiplexer = new ConcurrentStringHashMultiplexer();
ExpSchema_Nitload.Only.Init();
ExpSchema_Builtin.Only.Init();
PoolKeywords();
InitPrecedence();
@@ -99,18 +99,18 @@ namespace StgSharp.Script.Express
KeyWord.Not,
];
ExpSchema_Nitload.Only
ExpSchema_Builtin.Only
.TryGetType(
PoolString( KeyWord.Integer ),
out ExpTypeSource? _expInt );
ExpInt = _expInt;
ExpSchema_Nitload.Only
ExpSchema_Builtin.Only
.TryGetType(
PoolString( KeyWord.Real ),
out ExpTypeSource? _expReal );
ExpReal = _expReal;
ExpSchema_Nitload.Only
ExpSchema_Builtin.Only
.TryGetType(
PoolString( KeyWord.Boolean ),
out ExpTypeSource? _expBool );
@@ -37,7 +37,7 @@ using System.Threading.Tasks;
namespace StgSharp.Script.Express
{
public static partial class ExpCompile
public static partial class ExpressCompile
{
public static bool TryGetOperatorPrecedence(
@@ -37,7 +37,7 @@ using System.Threading.Tasks;
namespace StgSharp.Script.Express
{
public static partial class ExpCompile
public static partial class ExpressCompile
{
private static HashSet<string> _keywordSet;
+2 -2
View File
@@ -50,7 +50,7 @@ namespace StgSharp.Script.Express
{
_sourceProvider = sourceProvider;
_constants = new Dictionary<string, ExpElementInstanceBase>(
ExpCompile.Multiplexer );
ExpressCompile.Multiplexer );
}
public override ExpElementType ElementType => ExpElementType.Const;
@@ -59,7 +59,7 @@ namespace StgSharp.Script.Express
public override string Name
{
get => ExpCompile.KeyWord.Constant;
get => ExpressCompile.KeyWord.Constant;
}
public override void Analyse()
@@ -48,6 +48,18 @@ namespace StgSharp.Script.Express
_transmitter = transmitter;
}
public Dictionary<string, ExpElementInstanceBase> FuncParams
{
get;
init;
} = new Dictionary<string, ExpElementInstanceBase>();
public Dictionary<string, ExpElementInstanceBase> LocalVariables
{
get;
init;
} = new Dictionary<string, ExpElementInstanceBase>();
public override ExpElementType ElementType => ExpElementType.Function;
public override IScriptSourceProvider SourceProvider => _transmitter;
@@ -77,6 +89,16 @@ namespace StgSharp.Script.Express
public override bool TryGetMember( string name, out ExpNode memberNode )
{
if( FuncParams.TryGetValue(
name, out ExpElementInstanceBase? param ) ) {
memberNode = param;
return true;
}
if( LocalVariables.TryGetValue(
name, out ExpElementInstanceBase? variable ) ) {
memberNode = variable;
return true;
}
memberNode = ExpNode.Empty;
return false;
}
@@ -68,7 +68,8 @@ namespace StgSharp.Script.Express
0;
return new ExpBinaryOperatorNode( source )
{
_returnType = isFloat ? ExpCompile.ExpReal : ExpCompile.ExpInt,
_returnType = isFloat ?
ExpressCompile.ExpReal : ExpressCompile.ExpInt,
_nodeFlag = ExpNodeFlag.Operator_Binary | ExpNodeFlag.BuiltinType_Number,
CodeConvertTemplate = "{0} + {1}",
};
@@ -106,7 +107,8 @@ namespace StgSharp.Script.Express
0;
return new ExpBinaryOperatorNode( source )
{
_returnType = isFloat ? ExpCompile.ExpReal : ExpCompile.ExpInt,
_returnType = isFloat ?
ExpressCompile.ExpReal : ExpressCompile.ExpInt,
_nodeFlag = ExpNodeFlag.Operator_Binary | ExpNodeFlag.BuiltinType_Number,
CodeConvertTemplate = "{0} / {1}",
};
@@ -124,7 +126,7 @@ namespace StgSharp.Script.Express
}
return new ExpBinaryOperatorNode( source )
{
_returnType = ExpCompile.ExpBool,
_returnType = ExpressCompile.ExpBool,
_nodeFlag = ExpNodeFlag.BuiltinType_Boolean | ExpNodeFlag.Operator_Binary,
CodeConvertTemplate = "{0} == {1}",
};
@@ -141,7 +143,7 @@ namespace StgSharp.Script.Express
}
return new ExpBinaryOperatorNode( source )
{
_returnType = ExpCompile.ExpBool,
_returnType = ExpressCompile.ExpBool,
_nodeFlag = ExpNodeFlag.BuiltinType_Boolean | ExpNodeFlag.Operator_Binary,
CodeConvertTemplate = "{0} > {1}",
};
@@ -158,7 +160,7 @@ namespace StgSharp.Script.Express
}
return new ExpBinaryOperatorNode( source )
{
_returnType = ExpCompile.ExpBool,
_returnType = ExpressCompile.ExpBool,
_nodeFlag = ExpNodeFlag.BuiltinType_Boolean | ExpNodeFlag.Operator_Binary,
CodeConvertTemplate = "{0} < {1}",
};
@@ -178,7 +180,8 @@ namespace StgSharp.Script.Express
0;
return new ExpBinaryOperatorNode( source )
{
_returnType = isFloat ? ExpCompile.ExpReal : ExpCompile.ExpInt,
_returnType = isFloat ?
ExpressCompile.ExpReal : ExpressCompile.ExpInt,
_nodeFlag = ExpNodeFlag.Operator_Binary | ExpNodeFlag.BuiltinType_Number,
CodeConvertTemplate = "{0} * {1}",
};
@@ -196,7 +199,7 @@ namespace StgSharp.Script.Express
}
return new ExpBinaryOperatorNode( source )
{
_returnType = ExpCompile.ExpBool,
_returnType = ExpressCompile.ExpBool,
_nodeFlag = ExpNodeFlag.BuiltinType_Boolean | ExpNodeFlag.Operator_Binary,
CodeConvertTemplate = "{0} != {1}",
};
@@ -213,7 +216,7 @@ namespace StgSharp.Script.Express
}
return new ExpBinaryOperatorNode( source )
{
_returnType = ExpCompile.ExpBool,
_returnType = ExpressCompile.ExpBool,
_nodeFlag = ExpNodeFlag.BuiltinType_Boolean | ExpNodeFlag.Operator_Binary,
CodeConvertTemplate = "{0} < {1}",
};
@@ -233,7 +236,8 @@ namespace StgSharp.Script.Express
0;
return new ExpBinaryOperatorNode( source )
{
_returnType = isFloat ? ExpCompile.ExpReal : ExpCompile.ExpInt,
_returnType = isFloat ?
ExpressCompile.ExpReal : ExpressCompile.ExpInt,
_nodeFlag = ExpNodeFlag.Operator_Binary | ExpNodeFlag.BuiltinType_Number,
CodeConvertTemplate = "{0} - {1}",
};
@@ -56,7 +56,7 @@ namespace StgSharp.Script.Express
{
ExpSchema.BuiltinSchema
.TryGetType(
ExpCompile.KeyWord.String,
ExpressCompile.KeyWord.String,
out ExpTypeSource? strType );
return strType;
}
@@ -51,13 +51,13 @@ namespace StgSharp.Script.Express
public override IExpElementSource EqualityTypeConvert => ExpSchema.BuiltinSchema
.TryGetType(
ExpCompile.KeyWord.Integer,
ExpressCompile.KeyWord.Integer,
out ExpTypeSource? type ) ?
type : throw new ExpCompileNotInitializedException();
public int Value => _value;
public override string TypeName => ExpCompile.KeyWord.Integer;
public override string TypeName => ExpressCompile.KeyWord.Integer;
}
@@ -75,7 +75,7 @@ namespace StgSharp.Script.Express
public override IExpElementSource EqualityTypeConvert => ExpSchema.BuiltinSchema
.TryGetType(
ExpCompile.KeyWord.String,
ExpressCompile.KeyWord.String,
out ExpTypeSource? type ) ?
type : throw new ExpCompileNotInitializedException();
@@ -101,7 +101,7 @@ namespace StgSharp.Script.Express
public override IExpElementSource EqualityTypeConvert => ExpSchema.BuiltinSchema
.TryGetType(
ExpCompile.KeyWord.Boolean,
ExpressCompile.KeyWord.Boolean,
out ExpTypeSource? type ) ?
type : throw new ExpCompileNotInitializedException();
@@ -125,7 +125,7 @@ namespace StgSharp.Script.Express
public override IExpElementSource EqualityTypeConvert => ExpSchema.BuiltinSchema
.TryGetType(
ExpCompile.KeyWord.String,
ExpressCompile.KeyWord.String,
out ExpTypeSource? type ) ?
type : throw new ExpCompileNotInitializedException();
@@ -149,7 +149,7 @@ namespace StgSharp.Script.Express
public override IExpElementSource EqualityTypeConvert => ExpSchema.BuiltinSchema
.TryGetType(
ExpCompile.KeyWord.Logical,
ExpressCompile.KeyWord.Logical,
out ExpTypeSource? type ) ?
type : throw new ExpCompileNotInitializedException();
@@ -36,7 +36,7 @@ using System.Text;
namespace StgSharp.Script.Express
{
public class ExpRepeatToken : ExpNode
public class ExpRepeatNode : ExpNode
{
//TODO: Current code cannot represent full functionality defined in ISO10303, need rewrite.
@@ -45,7 +45,7 @@ namespace StgSharp.Script.Express
private ExpNode _operationBegin;
public ExpRepeatToken(
public ExpRepeatNode(
Token source,
ExpNode operationBegin,
ExpElementInstanceBase variable,
@@ -64,14 +64,14 @@ namespace StgSharp.Script.Express
case ExpNodeFlag.BuiltinType_Real:
increment = new ExpRealNumberNode(
new Token(
ExpCompile.PoolString( "1.0f" ), source.Line,
ExpressCompile.PoolString( "1.0f" ), source.Line,
-1, TokenFlag.Number ),
1.0f );
break;
case ExpNodeFlag.BuiltinType_Int:
increment = new ExpIntNode(
new Token(
ExpCompile.PoolString( "1" ), source.Line, -1,
ExpressCompile.PoolString( "1" ), source.Line, -1,
TokenFlag.Number ),
1 );
break;
@@ -34,7 +34,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ExpKeyword = StgSharp.Script.Express.ExpCompile.KeyWord;
using ExpKeyword = StgSharp.Script.Express.ExpressCompile.KeyWord;
namespace StgSharp.Script.Express
{
@@ -34,7 +34,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ExpKeyword = StgSharp.Script.Express.ExpCompile.KeyWord;
using ExpKeyword = StgSharp.Script.Express.ExpressCompile.KeyWord;
namespace StgSharp.Script.Express
{
@@ -43,9 +43,9 @@ namespace StgSharp.Script.Express
public int CompareOperatorPrecedence( Token left, Token right )
{
ExpCompile.TryGetOperatorPrecedence(
ExpressCompile.TryGetOperatorPrecedence(
left.Value, out int leftPrecedence );
ExpCompile.TryGetOperatorPrecedence(
ExpressCompile.TryGetOperatorPrecedence(
right.Value, out int rightPrecedence );
return leftPrecedence - rightPrecedence;
}
@@ -35,7 +35,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ExpKeyword = StgSharp.Script.Express.ExpCompile.KeyWord;
using ExpKeyword = StgSharp.Script.Express.ExpressCompile.KeyWord;
namespace StgSharp.Script.Express
{
@@ -34,7 +34,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ExpKeyword = StgSharp.Script.Express.ExpCompile.KeyWord;
using ExpKeyword = StgSharp.Script.Express.ExpressCompile.KeyWord;
namespace StgSharp.Script.Express
{
+14 -2
View File
@@ -40,7 +40,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ExpKeyword = StgSharp.Script.Express.ExpCompile.KeyWord;
using ExpKeyword = StgSharp.Script.Express.ExpressCompile.KeyWord;
namespace StgSharp.Script.Express
{
@@ -55,7 +55,7 @@ namespace StgSharp.Script.Express
private ExpNode _lastStatement;
private GeneratedExpSchema _context;
private ExpSchema _context;
private IExpElementSource _local;
public ExpNodeGenerator()
@@ -63,6 +63,18 @@ namespace StgSharp.Script.Express
_cache = new CompileStack<ExpNode, IExpElementSource>();
}
public ExpNodeGenerator( ExpSchema context, IExpElementSource local )
{
_cache = new CompileStack<ExpNode, IExpElementSource>();
ArgumentNullException.ThrowIfNull( context );
if( context is not ExpSchema_Builtin ) {
_context = context;
} else {
throw new InvalidCastException( "Not a valid Schema type" );
}
_local = local;
}
/**/
/// <summary>
+2 -2
View File
@@ -43,7 +43,7 @@ namespace StgSharp.Script.Express
public static ExpSchema BuiltinSchema
{
get => ExpSchema_Nitload.Only;
get => ExpSchema_Builtin.Only;
}
public string Name
@@ -93,7 +93,7 @@ namespace StgSharp.Script.Express
set;
}
protected ConcurrentStringHashMultiplexer StringMultiplexer => ExpCompile.Multiplexer;
protected ConcurrentStringHashMultiplexer StringMultiplexer => ExpressCompile.Multiplexer;
protected FrozenDictionary<string, ExpRuleSource> RuleDict
{
+134 -89
View File
@@ -44,7 +44,7 @@ namespace StgSharp.Script.Express
private const int
MultiLineEnd = 0x0029002A; // *)
private const string Token = "token", End = "end", Rest = "rest";
private const string TokenMark = "token", EndMark = "end", RestMark = "rest";
private bool _isReadingMultiLineComment;
private int _current, _lineNum;
@@ -67,8 +67,7 @@ namespace StgSharp.Script.Express
public bool IsEmpty
{
get => ( ( string.IsNullOrEmpty( _lineCache ) || _current >=
_lineCache.Length ) ) && _provider.IsEmpty;
get => ( ( string.IsNullOrEmpty( _lineCache ) || _current >= _lineCache.Length ) ) && _provider.IsEmpty;
}
public int LineNumber
@@ -77,38 +76,44 @@ namespace StgSharp.Script.Express
}
/// <summary>
/// <para> Read code until end of a line. Lines in multi-line comment will be ignored. Line
/// begins with part of multi-line comment will automatically remove the comment part, but
/// beginning with a full multi-line comment will not causing removing. </para> <para>(*Just
/// Like The Comment Here*) Will Not Be Removed</para>
/// <para> Read code until end of a line. Lines in multi-line comment will be ignored.
/// Line begins with part of multi-line comment will automatically remove the comment
/// part, but beginning with a full multi-line comment will not causing removing. </para>
/// <para> (*Just Like The Comment Here*) Will Not Be Removed</para>
/// </summary>
/// <returns></returns>
/// <returns>
///
/// </returns>
public unsafe ReadOnlySpan<char> ReadLine()
{
bool lineOver = string.IsNullOrEmpty( _lineCache ) || _current >=
_lineCache.Length;
while( lineOver || _isReadingMultiLineComment ) {
if( lineOver ) {
do {
bool lineOver = string.IsNullOrEmpty( _lineCache ) || _current >= _lineCache.Length;
while( lineOver || _isReadingMultiLineComment )
{
if( lineOver )
{
do
{
_lineCache = _provider.ReadLine( out _lineNum );
} while (string.IsNullOrEmpty( _lineCache ));
_current = 0;
}
if( _isReadingMultiLineComment ) {
if( _isReadingMultiLineComment )
{
int index;
fixed( char* cPtr = _lineCache.AsSpan( _current ) ) {
index = UnsafeCompute.IndexOfCharPair(
cPtr, MultiLineEnd, _lineCache.Length );
}
if( index == -1 ) {
if( index == -1 )
{
_lineCache = string.Empty;
} else {
} else
{
_isReadingMultiLineComment = false;
_current += index + 2;
}
}
lineOver = string.IsNullOrEmpty( _lineCache ) || _current >=
_lineCache.Length;
lineOver = string.IsNullOrEmpty( _lineCache ) || _current >= _lineCache.Length;
}
return _lineCache.AsSpan().Slice( _current );
}
@@ -120,67 +125,71 @@ namespace StgSharp.Script.Express
ReadOnlySpan<char> source = ReadLine();
char c = source[ 0 ];
if( char.IsLetter( c ) ) {
Match match = _nextWordTokenPattern.Match(
_lineCache, _current );
if( match.Success ) {
begin = match.Groups[ Token ].Index;
end = match.Groups[ End ].Index;
rest = match.Groups[ Rest ].Index;
if( char.IsLetter( c ) )
{
Match match = _nextWordTokenPattern.Match( _lineCache, _current );
if( match.Success )
{
begin = match.Groups[ TokenMark ].Index;
end = match.Groups[ EndMark ].Index;
rest = match.Groups[ RestMark ].Index;
_current = rest;
_last = new(
ExpCompile.PoolString( source[ .. ( end - begin ) ] ),
_lineNum, begin, TokenFlag.Member );
ExpressCompile.PoolString( source[ .. ( end - begin ) ] ), _lineNum, begin,
TokenFlag.Member );
return _last;
} else {
} else
{
throw new ExpInvalidTokenException( _current );
}
} else if( char.IsPunctuation( c ) || char.IsSymbol( c ) ) {
switch( c ) {
} else if( char.IsPunctuation( c ) || char.IsSymbol( c ) )
{
switch( c )
{
case '"':
char cNext = source[ 1 ];
if( cNext == '\"' ) //empty string
{
begin = _current;
_current += 2;
return new(
string.Empty, _lineNum, begin,
TokenFlag.String );
return new( string.Empty, _lineNum, begin, TokenFlag.String );
}
Match match = _nextStringLiteralPattern.Match(
_lineCache, _current );
if( match.Success ) {
Match match = _nextStringLiteralPattern.Match( _lineCache, _current );
if( match.Success )
{
begin = match.Groups[ "token" ].Index;
end = match.Groups[ "end" ].Index;
rest = match.Groups[ "rest" ].Index;
_current = rest;
_last = new(
ExpCompile.PoolString(
source[ 1..( end - begin ) ] ),
_lineNum, begin, TokenFlag.String );
ExpressCompile.PoolString( source[ 1..( end - begin ) ] ), _lineNum,
begin, TokenFlag.String );
return _last;
} else {
} else
{
throw new ExpInvalidCharException( '\"' );
}
case '(':
cNext = source[ 1 ];
if( cNext == '*' ) {
if( cNext == '*' )
{
_isReadingMultiLineComment = true;
_current += 2;
goto readLine;
} else {
} else
{
begin = _current;
_current++;
_last = new(
ExpCompile.PoolString( source[ ..1 ] ),
_lineNum, begin, TokenFlag.Separator_Left );
ExpressCompile.PoolString( source[ ..1 ] ), _lineNum, begin,
TokenFlag.Separator_Left );
return _last;
}
case ')' or '}':
begin = _current;
_current++;
_last = new Token(
ExpCompile.PoolString( ")" ), _lineNum, begin,
ExpressCompile.PoolString( ")" ), _lineNum, begin,
TokenFlag.Separator_Right );
return _last;
case '-':
@@ -190,36 +199,41 @@ namespace StgSharp.Script.Express
// 3. - number type param(UNARY)
// 4. param - param(BINARY)
cNext = source[ 1 ];
if( char.IsNumber( cNext ) ) {
match = _nextNumberLiteralPattern.Match(
_lineCache, _current );
if( match.Success ) {
begin = match.Groups[ Token ].Index;
end = match.Groups[ End ].Index;
rest = match.Groups[ Rest ].Index;
if( char.IsNumber( cNext ) )
{
match = _nextNumberLiteralPattern.Match( _lineCache, _current );
if( match.Success )
{
begin = match.Groups[ TokenMark ].Index;
end = match.Groups[ EndMark ].Index;
rest = match.Groups[ RestMark ].Index;
_current = rest;
return new(
ExpCompile.PoolString(
source[ ..( end - begin ) ] ),
ExpressCompile.PoolString( source[ ..( end - begin ) ] ),
_lineNum, begin, TokenFlag.Number );
} else {
} else
{
throw new ExpInvalidTokenException( _current );
}
} else if( cNext == '-' ) {
} else if( cNext == '-' )
{
_lineCache = string.Empty;
_current = 0;
goto readLine;
} else {
} else
{
begin = _current;
_current++;
if( _last.Flag != TokenFlag.Member ) {
if( _last.Flag != TokenFlag.Member )
{
_last = new(
ExpCompile.PoolString( source[ ..1 ] ),
_lineNum, begin, TokenFlag.Symbol_Unary );
} else {
ExpressCompile.PoolString( source[ ..1 ] ), _lineNum, begin,
TokenFlag.Symbol_Unary );
} else
{
_last = new(
ExpCompile.PoolString( source[ ..1 ] ),
_lineNum, begin, TokenFlag.Symbol_Binary );
ExpressCompile.PoolString( source[ ..1 ] ), _lineNum, begin,
TokenFlag.Symbol_Binary );
}
return _last;
}
@@ -227,70 +241,101 @@ namespace StgSharp.Script.Express
begin = _current;
_current++;
return new Token(
ExpCompile.PoolString( "{" ), _lineNum, begin,
ExpressCompile.PoolString( "{" ), _lineNum, begin,
TokenFlag.Separator_Left );
case '[':
begin = _current;
_current++;
return new Token(
ExpCompile.PoolString( "[" ), _lineNum, begin,
ExpressCompile.PoolString( "[" ), _lineNum, begin,
TokenFlag.Index_Left );
case ']':
begin = _current;
_current++;
return new Token(
ExpCompile.PoolString( "]" ), _lineNum, begin,
ExpressCompile.PoolString( "]" ), _lineNum, begin,
TokenFlag.Index_Right );
case ';' or ',':
begin = _current;
_current++;
return new Token(
ExpCompile.PoolString( source[ ..1 ] ), _lineNum,
begin, TokenFlag.Separator_Middle );
case ':' or '+' or '/' or '\\' or '*' or '.':
ExpressCompile.PoolString( source[ ..1 ] ), _lineNum, begin,
TokenFlag.Separator_Middle );
case ':':
if( source[ 1 ] == '=' )
{
begin = _current;
_current += 2;
return new Token(
ExpressCompile.KeyWord.Assignment, _lineNum, begin,
TokenFlag.Index_Right );
}
begin = _current;
_current++;
return new Token(
ExpressCompile.KeyWord.Colon, _lineNum, begin, TokenFlag.Index_Right );
case '+' or '/' or '\\' or '*' or '.':
begin = _current;
_current++;
return new(
ExpCompile.PoolString( source[ ..1 ] ), _lineNum,
begin, TokenFlag.Symbol_Binary );
ExpressCompile.PoolString( source[ ..1 ] ), _lineNum, begin,
TokenFlag.Symbol_Binary );
default:
throw new ExpInvalidCharException( c );
}
} else if( char.IsNumber( c ) ) {
Match match = _nextNumberLiteralPattern.Match(
_lineCache, _current );
if( match.Success ) {
begin = match.Groups[ Token ].Index;
end = match.Groups[ End ].Index;
rest = match.Groups[ Rest ].Index;
} else if( char.IsNumber( c ) )
{
Match match = _nextNumberLiteralPattern.Match( _lineCache, _current );
if( match.Success )
{
begin = match.Groups[ TokenMark ].Index;
end = match.Groups[ EndMark ].Index;
rest = match.Groups[ RestMark ].Index;
_current = rest;
string str = ExpCompile.PoolString(
source[ ..( end - begin ) ] );
string str = ExpressCompile.PoolString( source[ ..( end - begin ) ] );
TokenFlag flag;
if( ReferenceEquals( str, ExpCompile.KeyWord.Not ) ) {
if( ReferenceEquals( str, ExpressCompile.KeyWord.Not ) )
{
flag = TokenFlag.Symbol_Unary;
} else {
flag = ExpCompile.LetterIsOperator( str ) ?
} else
{
flag = ExpressCompile.LetterIsOperator( str ) ?
TokenFlag.Symbol_Binary : TokenFlag.Member;
}
return new( str, _lineNum, begin, flag );
} else {
} else
{
throw new ExpInvalidTokenException( _current );
}
} else if( char.IsWhiteSpace( c ) ) {
} else if( char.IsWhiteSpace( c ) )
{
Match match = _skipBlankPattern.Match( _lineCache, _current );
if( match.Success ) {
rest = match.Groups[ Rest ].Index;
if( match.Success )
{
rest = match.Groups[ RestMark ].Index;
_current = rest;
goto readLine;
} else {
} else
{
throw new ExpInvalidTokenException( _current );
}
} else {
} else
{
throw new ExpInvalidCharException( c );
}
}
public bool TryReadToken( out Token t )
{
if( IsEmpty )
{
t = Token.Empty;
return false;
}
t = ReadToken();
return true;
}
[GeneratedRegex(
@"(?<token>[a-zA-Z][a-zA-Z0-9_]*)(?<end>\s*?)(?<rest>\S|$)",
RegexOptions.Singleline )]
@@ -46,7 +46,7 @@ namespace StgSharp.Script.Express
public static ExpSchema DefaultSchema
{
get => ExpSchema_Nitload.Only;
get => ExpSchema_Builtin.Only;
}
public ExpTypeSource GetExpType( string typeName )
@@ -14,7 +14,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp.Script")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+e73d2fd7fb4e601c32cee66e276f219fc9b4a377")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+528d0c5462b4d3da107ad29b859f9c8006fb675a")]
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp.Script")]
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Script")]
[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/e73d2fd7fb4e601c32cee66e276f219fc9b4a377/*"}}
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\内核源代码\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/528d0c5462b4d3da107ad29b859f9c8006fb675a/*"}}
+82
View File
@@ -0,0 +1,82 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpLinearExpressionTest.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 StgSharp.Script;
using StgSharp.Script.Express;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp
{
internal class ExpTestFuncSource : ExpFunctionSource
{
public ExpTestFuncSource( string name, ScriptSourceTransmitter source )
: base( name, source )
{
LocalVariables.Add(
"a",
ExpElementInstanceBase.CreateLiteral( new Token( "1", 0, 0, TokenFlag.Number ) ) );
LocalVariables.Add(
"b",
ExpElementInstanceBase.CreateLiteral( new Token( "1", 0, 0, TokenFlag.Number ) ) );
LocalVariables.Add(
"c",
ExpElementInstanceBase.CreateLiteral( new Token( "1", 0, 0, TokenFlag.Number ) ) );
}
}
internal static partial class Program
{
public static void ExpLinearExpressionTest()
{
ExpressCompile.InitCompile();
ScriptSourceTransmitter transmitter = new ScriptSourceTransmitter( "END", 0 );
transmitter.WriteLine( @"a := b + c;" );
transmitter.EndWriting();
ExpSourceReader reader = new ExpSourceReader( transmitter );
/*
ExpNodeGenerator generator = new ExpNodeGenerator(
, new ExpTestFuncSource( "test", transmitter ) );
/**/
while( reader.TryReadToken( out Token t ) )
{
Console.WriteLine( t.Value );
}
}
}
}
+1 -31
View File
@@ -58,37 +58,7 @@ namespace StgSharp
{
try {
StgSharp.Init();
CompileStack<ExpNode, IExpElementSource> stack = new CompileStack<ExpNode, IExpElementSource>(
);
for( int i = 0; i < 10; i++ ) {
stack.PushOperand(
new Token( $"{i}", 0, 0, TokenFlag.Number ) );
}
for( int i = 0; i < 10; i++ ) {
stack.PushOperator(
new Token( $"op_{i}", 0, 0, TokenFlag.Member ) );
}
stack.IncreaseDepth( 0 );
for( int i = 0; i < 10; i++ ) {
stack.PushOperand(
new Token( $"{i}", 0, 0, TokenFlag.Number ) );
}
for( int i = 0; i < 10; i++ ) {
stack.PushOperator(
new Token( $"op_{i}", 0, 0, TokenFlag.Member ) );
}
while( stack.TryPopOperand(
out bool isNode, out Token t, out ExpNode n ) ) {
Console.WriteLine( t.Value );
}
while( stack.TryPopOperator( out Token op ) ) {
Console.WriteLine( op.Value );
}
ExpLinearExpressionTest();
return;
}
catch( Exception ex ) {
+1 -1
View File
@@ -43,7 +43,7 @@ namespace StgSharp
private static void TestFileRead()
{
ExpCompile.InitCompile();
ExpressCompile.InitCompile();
ExpFileSource reader = new ExpFileSource( testExpPath );
ExpSchemaSource schemaSource = new ExpSchemaSource();
schemaSource.ReadSchema( reader );
@@ -14,7 +14,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharpDebug")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+6788bc4a0065508d7afa5f740da1b4ca6dd1efef")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+528d0c5462b4d3da107ad29b859f9c8006fb675a")]
[assembly: System.Reflection.AssemblyProductAttribute("StgSharpDebug")]
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharpDebug")]
[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/528d0c5462b4d3da107ad29b859f9c8006fb675a/*"}}