Daily update on 20250405-231604 by Nitload Youmu. Additional Message : most of repeat block analyzer complete
Signed-off-by: Nitload <YoumuLiu_NSI@whv0t.onmicrosoft.com>
This commit is contained in:
@@ -37,7 +37,12 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace StgSharp.Script
|
namespace StgSharp.Script
|
||||||
{
|
{
|
||||||
public interface ICompileDepthState { }
|
public interface ICompileDepthState
|
||||||
|
{
|
||||||
|
|
||||||
|
string CurrentState { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public class CompileDepthMark
|
public class CompileDepthMark
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ namespace StgSharp.Script.Express
|
|||||||
|
|
||||||
public override string Name => ExpressCompile.PoolString( "ARRAY" );
|
public override string Name => ExpressCompile.PoolString( "ARRAY" );
|
||||||
|
|
||||||
public override ExpNode CreateInstanceNode()
|
public override ExpNode CreateInstanceNode( Token t )
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
@@ -126,7 +126,7 @@ namespace StgSharp.Script.Express
|
|||||||
|
|
||||||
public override string Name => ExpressCompile.PoolString( "BAG" );
|
public override string Name => ExpressCompile.PoolString( "BAG" );
|
||||||
|
|
||||||
public override ExpNode CreateInstanceNode()
|
public override ExpNode CreateInstanceNode( Token t )
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
@@ -149,7 +149,7 @@ namespace StgSharp.Script.Express
|
|||||||
|
|
||||||
public override string Name => ExpressCompile.PoolString( "LIST" );
|
public override string Name => ExpressCompile.PoolString( "LIST" );
|
||||||
|
|
||||||
public override ExpNode CreateInstanceNode()
|
public override ExpNode CreateInstanceNode( Token t )
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
@@ -180,7 +180,7 @@ namespace StgSharp.Script.Express
|
|||||||
_collection.Add( token );
|
_collection.Add( token );
|
||||||
}
|
}
|
||||||
|
|
||||||
public override ExpNode CreateInstanceNode()
|
public override ExpNode CreateInstanceNode( Token t )
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ namespace StgSharp.Script.Express
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override ExpNode CreateInstanceNode()
|
public override ExpNode CreateInstanceNode( Token t )
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ namespace StgSharp.Script.Express
|
|||||||
|
|
||||||
public override ExpElementType ElementType => ExpElementType.Type;
|
public override ExpElementType ElementType => ExpElementType.Type;
|
||||||
|
|
||||||
public ExpTypeSource Void
|
public static ExpTypeSource Void
|
||||||
{
|
{
|
||||||
get => ExpVoidType.Only;
|
get => ExpVoidType.Only;
|
||||||
}
|
}
|
||||||
@@ -77,7 +77,7 @@ namespace StgSharp.Script.Express
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override ExpElementInstance CreateInstanceNode()
|
public override ExpElementInstance CreateInstanceNode( Token t )
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,81 @@
|
|||||||
|
//-----------------------------------------------------------------------
|
||||||
|
//-----------------------------------------------------------------------
|
||||||
|
// file="ExpProcedureControlNode.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 Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
using ExpKeyword = StgSharp.Script.Express.ExpressCompile.Keyword;
|
||||||
|
|
||||||
|
namespace StgSharp.Script.Express
|
||||||
|
{
|
||||||
|
public class ExpProcedureControlNode : ExpNode
|
||||||
|
{
|
||||||
|
|
||||||
|
private ExpNode _additional;
|
||||||
|
|
||||||
|
internal ExpProcedureControlNode( Token source ) : base( source ) { }
|
||||||
|
|
||||||
|
public override ExpNode Left => Empty;
|
||||||
|
|
||||||
|
public override ExpNode Right => _additional;
|
||||||
|
|
||||||
|
public override IExpElementSource EqualityTypeConvert => ExpTypeSource.Void;
|
||||||
|
|
||||||
|
public static ExpProcedureControlNode Return( Token t, ExpNode valueToReturn )
|
||||||
|
{
|
||||||
|
if( t.Value != ExpKeyword.Return ) {
|
||||||
|
throw new InvalidCastException();
|
||||||
|
}
|
||||||
|
ExpProcedureControlNode ret = new ExpProcedureControlNode( t )
|
||||||
|
{
|
||||||
|
_additional = valueToReturn ?? Empty,
|
||||||
|
CodeConvertTemplate = IsNullOrEmpty( valueToReturn! ) ?
|
||||||
|
ExpKeyword.Return : "return {0}",
|
||||||
|
};
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ExpProcedureControlNode Skip( Token t )
|
||||||
|
{
|
||||||
|
ExpProcedureControlNode ret = new ExpProcedureControlNode( t )
|
||||||
|
{
|
||||||
|
_additional = Empty,
|
||||||
|
CodeConvertTemplate = "break"
|
||||||
|
};
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -39,19 +39,51 @@ namespace StgSharp.Script.Express
|
|||||||
public class ExpRepeatNode : ExpNode
|
public class ExpRepeatNode : ExpNode
|
||||||
{
|
{
|
||||||
|
|
||||||
//TODO: Current code cannot represent full functionality defined in ISO10303, need rewrite.
|
private ExpElementInstance _variable;
|
||||||
|
private ExpNode _begin, _end, _increment, _operationBegin,_untilRule,_whileRule;
|
||||||
|
|
||||||
private ExpElementInstance _variable, _begin, _end, _increment;
|
internal ExpRepeatNode(
|
||||||
|
Token source,
|
||||||
|
ExpNode operationBegin,
|
||||||
|
ExpElementInstance variable,
|
||||||
|
ExpNode begin,
|
||||||
|
ExpNode end )
|
||||||
|
: base( source )
|
||||||
|
{
|
||||||
|
ExpNode increment;
|
||||||
|
switch( ( ExpNodeFlag )variable.NodeFlag | ExpNodeFlag.BuiltinType_Any )
|
||||||
|
{
|
||||||
|
case ExpNodeFlag.BuiltinType_Real:
|
||||||
|
increment = new ExpRealNumberNode(
|
||||||
|
new Token(
|
||||||
|
ExpressCompile.PoolString( "1.0f" ), source.Line, -1,
|
||||||
|
TokenFlag.Number ),
|
||||||
|
1.0f, isLiteral: true );
|
||||||
|
break;
|
||||||
|
case ExpNodeFlag.BuiltinType_Int:
|
||||||
|
increment = new ExpIntNode(
|
||||||
|
new Token(
|
||||||
|
ExpressCompile.PoolString( "1" ), source.Line, -1, TokenFlag.Number ),
|
||||||
|
1, isLiteral: true );
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new ExpInvalidTypeException( "Int or Real", "otherwise" );
|
||||||
|
}
|
||||||
|
_begin = begin;
|
||||||
|
_variable = variable;
|
||||||
|
_end = end;
|
||||||
|
_increment = increment;
|
||||||
|
_nodeFlag = ExpNodeFlag.Branch_Repeat;
|
||||||
|
_operationBegin = operationBegin;
|
||||||
|
}
|
||||||
|
|
||||||
private ExpNode _operationBegin;
|
internal ExpRepeatNode(
|
||||||
|
Token source,
|
||||||
public ExpRepeatNode(
|
ExpNode operationBegin,
|
||||||
Token source,
|
ExpElementInstance variable,
|
||||||
ExpNode operationBegin,
|
ExpNode begin,
|
||||||
ExpElementInstance variable,
|
ExpNode end,
|
||||||
ExpElementInstance begin,
|
ExpNode increment )
|
||||||
ExpElementInstance end,
|
|
||||||
ExpElementInstance increment )
|
|
||||||
: base( source )
|
: base( source )
|
||||||
{
|
{
|
||||||
if( variable.NodeFlag != begin.NodeFlag || begin.NodeFlag != end.NodeFlag || ( increment !=
|
if( variable.NodeFlag != begin.NodeFlag || begin.NodeFlag != end.NodeFlag || ( increment !=
|
||||||
@@ -59,28 +91,7 @@ namespace StgSharp.Script.Express
|
|||||||
increment.NodeFlag ) ) {
|
increment.NodeFlag ) ) {
|
||||||
throw new InvalidCastException();
|
throw new InvalidCastException();
|
||||||
}
|
}
|
||||||
if( increment == null )
|
ArgumentNullException.ThrowIfNull( increment );
|
||||||
{
|
|
||||||
switch( ( ExpNodeFlag )variable.NodeFlag | ExpNodeFlag.BuiltinType_Any )
|
|
||||||
{
|
|
||||||
case ExpNodeFlag.BuiltinType_Real:
|
|
||||||
increment = new ExpRealNumberNode(
|
|
||||||
new Token(
|
|
||||||
ExpressCompile.PoolString( "1.0f" ), source.Line, -1,
|
|
||||||
TokenFlag.Number ),
|
|
||||||
1.0f, isLiteral: true );
|
|
||||||
break;
|
|
||||||
case ExpNodeFlag.BuiltinType_Int:
|
|
||||||
increment = new ExpIntNode(
|
|
||||||
new Token(
|
|
||||||
ExpressCompile.PoolString( "1" ), source.Line, -1,
|
|
||||||
TokenFlag.Number ),
|
|
||||||
1, isLiteral: true );
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new ExpInvalidTypeException( "Int or Real", "otherwise" );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_begin = begin;
|
_begin = begin;
|
||||||
_variable = variable;
|
_variable = variable;
|
||||||
_end = end;
|
_end = end;
|
||||||
@@ -100,5 +111,67 @@ namespace StgSharp.Script.Express
|
|||||||
_operationBegin.AppendNode( node );
|
_operationBegin.AppendNode( node );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ExpRepeatNode Create(
|
||||||
|
Token t,
|
||||||
|
ExpElementInstance repeatVariable,
|
||||||
|
ExpNode begin,
|
||||||
|
ExpNode end,
|
||||||
|
ExpNode repeatBody )
|
||||||
|
{
|
||||||
|
string typename = repeatVariable.NodeFlag.ToString();
|
||||||
|
ExpRepeatNode ret = new ExpRepeatNode( t, repeatBody, repeatVariable, begin, end, null )
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* 0 increment variable type
|
||||||
|
* 1: variable name
|
||||||
|
* 2: beginning value
|
||||||
|
* 3: ending value
|
||||||
|
* 4: increment
|
||||||
|
* 5: body
|
||||||
|
*/
|
||||||
|
CodeConvertTemplate = $$"""
|
||||||
|
for({{0}} {{1}} = {{2}}; {{1}} <= {{3}}; {{1}} += {{4}})
|
||||||
|
{
|
||||||
|
{{5}}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
};
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ExpRepeatNode Create(
|
||||||
|
Token t,
|
||||||
|
ExpElementInstance repeatVariable,
|
||||||
|
ExpNode begin,
|
||||||
|
ExpNode end,
|
||||||
|
ExpNode increment,
|
||||||
|
ExpNode whileRule,
|
||||||
|
ExpNode untilRule,
|
||||||
|
ExpNode body )
|
||||||
|
{
|
||||||
|
ExpRepeatNode ret = new ExpRepeatNode( t, body, repeatVariable, begin, end, increment )
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* 0 increment variable type
|
||||||
|
* 1: variable name
|
||||||
|
* 2: beginning value
|
||||||
|
* 3: ending value
|
||||||
|
* 4: increment
|
||||||
|
* 5: body
|
||||||
|
* 6: while
|
||||||
|
* 7: until
|
||||||
|
*/
|
||||||
|
CodeConvertTemplate = $$"""
|
||||||
|
for({{0}} {{1}} = {{2}}; {{1}} <= {{3}}; {{1}} += {{4}})
|
||||||
|
{
|
||||||
|
if(!( {{6}} )) break;
|
||||||
|
{{5}}
|
||||||
|
if(!( {{7}} )) break;
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
};
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,20 +39,11 @@ namespace StgSharp.Script.Express
|
|||||||
public interface IExpElementSource : ITypeSource<IExpElementSource>
|
public interface IExpElementSource : ITypeSource<IExpElementSource>
|
||||||
{
|
{
|
||||||
|
|
||||||
public ExpElementType ElementType
|
public ExpElementType ElementType { get; }
|
||||||
{
|
|
||||||
get;
|
|
||||||
}
|
|
||||||
|
|
||||||
IScriptSourceProvider SourceProvider
|
IScriptSourceProvider SourceProvider { get; }
|
||||||
{
|
|
||||||
get;
|
|
||||||
}
|
|
||||||
|
|
||||||
string Name
|
string Name { get; }
|
||||||
{
|
|
||||||
get;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Analyse();
|
public void Analyse();
|
||||||
|
|
||||||
@@ -63,33 +54,23 @@ namespace StgSharp.Script.Express
|
|||||||
public abstract class ExpInstantiableElement : IExpElementSource
|
public abstract class ExpInstantiableElement : IExpElementSource
|
||||||
{
|
{
|
||||||
|
|
||||||
private List<ExpInstantiableElement> _baseList = new List<ExpInstantiableElement>(
|
private List<ExpInstantiableElement> _baseList = new List<ExpInstantiableElement>(),
|
||||||
),
|
|
||||||
_derivationList = new List<ExpInstantiableElement>();
|
_derivationList = new List<ExpInstantiableElement>();
|
||||||
|
|
||||||
public abstract ExpElementType ElementType
|
public abstract ExpElementType ElementType { get; }
|
||||||
{
|
|
||||||
get;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ExpInstantiableElement Void
|
public static ExpInstantiableElement Void
|
||||||
{
|
{
|
||||||
get => ExpVoidElement.Only;
|
get => ExpVoidElement.Only;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract IScriptSourceProvider SourceProvider
|
public abstract IScriptSourceProvider SourceProvider { get; }
|
||||||
{
|
|
||||||
get;
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract string Name
|
public abstract string Name { get; }
|
||||||
{
|
|
||||||
get;
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract void Analyse();
|
public abstract void Analyse();
|
||||||
|
|
||||||
public abstract ExpNode CreateInstanceNode();
|
public abstract ExpNode CreateInstanceNode( Token t );
|
||||||
|
|
||||||
public bool IsConvertable( IExpElementSource targetType )
|
public bool IsConvertable( IExpElementSource targetType )
|
||||||
{
|
{
|
||||||
@@ -124,14 +105,12 @@ namespace StgSharp.Script.Express
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override ExpNode CreateInstanceNode()
|
public override ExpNode CreateInstanceNode( Token t )
|
||||||
{
|
{
|
||||||
return default!;
|
return ExpNode.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool TryGetMember(
|
public override bool TryGetMember( string name, out ExpNode memberNode )
|
||||||
string name,
|
|
||||||
out ExpNode memberNode )
|
|
||||||
{
|
{
|
||||||
memberNode = ExpNode.Empty;
|
memberNode = ExpNode.Empty;
|
||||||
return false;
|
return false;
|
||||||
@@ -144,20 +123,11 @@ namespace StgSharp.Script.Express
|
|||||||
public abstract class ExpImmutableElement : IExpElementSource
|
public abstract class ExpImmutableElement : IExpElementSource
|
||||||
{
|
{
|
||||||
|
|
||||||
public abstract ExpElementType ElementType
|
public abstract ExpElementType ElementType { get; }
|
||||||
{
|
|
||||||
get;
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract IScriptSourceProvider SourceProvider
|
public abstract IScriptSourceProvider SourceProvider { get; }
|
||||||
{
|
|
||||||
get;
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract string Name
|
public abstract string Name { get; }
|
||||||
{
|
|
||||||
get;
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract void Analyse();
|
public abstract void Analyse();
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,8 @@ namespace StgSharp.Script.Express
|
|||||||
|
|
||||||
public ExpSchema Compile( ExpressCompileOption option )
|
public ExpSchema Compile( ExpressCompileOption option )
|
||||||
{
|
{
|
||||||
switch( option ) {
|
switch( option )
|
||||||
|
{
|
||||||
case ExpressCompileOption.Default:
|
case ExpressCompileOption.Default:
|
||||||
return Compile_Translate( option );
|
return Compile_Translate( option );
|
||||||
case ExpressCompileOption.Translate:
|
case ExpressCompileOption.Translate:
|
||||||
@@ -62,8 +63,7 @@ namespace StgSharp.Script.Express
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal GeneratedExpSchema Compile_Translate(
|
internal GeneratedExpSchema Compile_Translate( ExpressCompileOption option )
|
||||||
ExpressCompileOption option )
|
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,257 @@
|
|||||||
|
//-----------------------------------------------------------------------
|
||||||
|
//-----------------------------------------------------------------------
|
||||||
|
// file="ExpSyntaxAnalyzer.RepeatLoop.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 Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.Design.Serialization;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Resources;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
using ExpKeyword = StgSharp.Script.Express.ExpressCompile.Keyword;
|
||||||
|
|
||||||
|
namespace StgSharp.Script.Express
|
||||||
|
{
|
||||||
|
public partial class ExpSyntaxAnalyzer
|
||||||
|
{
|
||||||
|
|
||||||
|
private Dictionary<string, ExpElementInstance> _tempVariableInLoops { get; }
|
||||||
|
= new Dictionary<string, ExpElementInstance>();
|
||||||
|
|
||||||
|
private bool AppendToken_RepeatLoop( Token t )
|
||||||
|
{
|
||||||
|
RepeatLoopState state = _cache.StateOfCurrentDepth<RepeatLoopState>();
|
||||||
|
if( state == null )
|
||||||
|
{
|
||||||
|
state = new RepeatLoopState( t );
|
||||||
|
_cache.CurrentDepthMark.StateCache = state;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
switch( state.CurrentState )
|
||||||
|
{
|
||||||
|
case ExpKeyword.Repeat:
|
||||||
|
return TryParseRepeatVariable( state, t );
|
||||||
|
case ExpKeyword.To:
|
||||||
|
return TryParseRepeatEnding( state, t );
|
||||||
|
case ExpKeyword.By:
|
||||||
|
return TryParseRepeatVariable( state, t );
|
||||||
|
case ExpKeyword.Until:
|
||||||
|
return TryParseRepeatUntilRegulation( state, t );
|
||||||
|
case ExpKeyword.Assignment:
|
||||||
|
return TryParseRepeatBeginning( state, t );
|
||||||
|
case ExpKeyword.While:
|
||||||
|
return TryParseRepeatWhileRegulation( state, t );
|
||||||
|
case ExpKeyword.Semicolon:
|
||||||
|
if( t.Value != ExpKeyword.EndRepeat )
|
||||||
|
{
|
||||||
|
AppendToken_common( t );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
AppendToken_common( t );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
ExpNode root = _cache.PackAllStatements();
|
||||||
|
state.Body = root;
|
||||||
|
_cache.DecreaseDepth();
|
||||||
|
root = ExpRepeatNode.Create(
|
||||||
|
state.Position, state.Body, state.Begin, state.End, state.IncrementVariable,
|
||||||
|
state.UntilExpression, state.WhileExpression );
|
||||||
|
_cache.StatementsInDepth.Push( root );
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool TryParseRepeatBeginning( RepeatLoopState state, Token t )
|
||||||
|
{
|
||||||
|
switch( t.Value )
|
||||||
|
{
|
||||||
|
case ExpKeyword.To:
|
||||||
|
state.CurrentState = ExpKeyword.To;
|
||||||
|
while( _cache.TryPopOperator( out Token op ) ) {
|
||||||
|
ConvertAndPushOneOperator( op );
|
||||||
|
}
|
||||||
|
_cache.PopOperand( out _, out ExpNode? root );
|
||||||
|
state.Begin = root;
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
AppendToken_common( t );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool TryParseRepeatEnding( RepeatLoopState state, Token t )
|
||||||
|
{
|
||||||
|
switch( t.Value )
|
||||||
|
{
|
||||||
|
case ExpKeyword.By:
|
||||||
|
state.CurrentState = ExpKeyword.By;
|
||||||
|
break;
|
||||||
|
case ExpKeyword.Until:
|
||||||
|
state.CurrentState = ExpKeyword.Until;
|
||||||
|
break;
|
||||||
|
case ExpKeyword.While:
|
||||||
|
state.CurrentState = ExpKeyword.While;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
AppendToken_common( t );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
while( _cache.TryPopOperator( out Token op ) ) {
|
||||||
|
ConvertAndPushOneOperator( op );
|
||||||
|
}
|
||||||
|
_cache.PopOperand( out _, out ExpNode? root );
|
||||||
|
state.End = root;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool TryParseRepeatIncrement( RepeatLoopState state, Token t )
|
||||||
|
{
|
||||||
|
switch( t.Value )
|
||||||
|
{
|
||||||
|
case ExpKeyword.Semicolon:
|
||||||
|
state.CurrentState = ExpKeyword.Semicolon;
|
||||||
|
break;
|
||||||
|
case ExpKeyword.Until:
|
||||||
|
state.CurrentState = ExpKeyword.Until;
|
||||||
|
break;
|
||||||
|
case ExpKeyword.While:
|
||||||
|
state.CurrentState = ExpKeyword.While;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
AppendToken_common( t );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
while( _cache.TryPopOperator( out Token op ) ) {
|
||||||
|
ConvertAndPushOneOperator( op );
|
||||||
|
}
|
||||||
|
_cache.PopOperand( out _, out ExpNode? root );
|
||||||
|
state.IncrementVariable = root;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool TryParseRepeatUntilRegulation( RepeatLoopState state, Token t )
|
||||||
|
{
|
||||||
|
switch( t.Value )
|
||||||
|
{
|
||||||
|
case ExpKeyword.Semicolon:
|
||||||
|
state.CurrentState = ExpKeyword.Semicolon;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
AppendToken_common( t );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
while( _cache.TryPopOperator( out Token op ) ) {
|
||||||
|
ConvertAndPushOneOperator( op );
|
||||||
|
}
|
||||||
|
_cache.PopOperand( out _, out ExpNode? root );
|
||||||
|
state.UntilExpression = root;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool TryParseRepeatVariable( RepeatLoopState state, Token t )
|
||||||
|
{
|
||||||
|
switch( t.Value )
|
||||||
|
{
|
||||||
|
case ExpKeyword.Integer:
|
||||||
|
state.IncrementVariableType = ExpressCompile.ExpInt;
|
||||||
|
return true;
|
||||||
|
case
|
||||||
|
ExpKeyword.Real:
|
||||||
|
state.IncrementVariableType = ExpressCompile.ExpReal;
|
||||||
|
return true;
|
||||||
|
case ExpKeyword.Assignment:
|
||||||
|
state.CurrentState = ExpKeyword.Assignment;
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
if( ExpTypeSource.IsNullOrVoid( state.IncrementVariableType ) )
|
||||||
|
{
|
||||||
|
throw new ExpInvalidTypeException( "Numerical", t.Value );
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
state.IncrementVariable = state.IncrementVariableType
|
||||||
|
.CreateInstanceNode( t );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool TryParseRepeatWhileRegulation( RepeatLoopState state, Token t )
|
||||||
|
{
|
||||||
|
switch( t.Value )
|
||||||
|
{
|
||||||
|
case ExpKeyword.Until:
|
||||||
|
state.CurrentState = ExpKeyword.Until;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
AppendToken_common( t );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
while( _cache.TryPopOperator( out Token op ) ) {
|
||||||
|
ConvertAndPushOneOperator( op );
|
||||||
|
}
|
||||||
|
_cache.PopOperand( out _, out ExpNode? root );
|
||||||
|
state.WhileExpression = root;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private class RepeatLoopState : ICompileDepthState
|
||||||
|
{
|
||||||
|
|
||||||
|
public RepeatLoopState( Token t )
|
||||||
|
{
|
||||||
|
Position = t;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExpNode IncrementVariable { get; set; }
|
||||||
|
|
||||||
|
public ExpNode Begin { get; set; }
|
||||||
|
|
||||||
|
public ExpNode End { get; set; }
|
||||||
|
|
||||||
|
public ExpNode UntilExpression { get; set; }
|
||||||
|
|
||||||
|
public ExpNode WhileExpression { get; set; }
|
||||||
|
|
||||||
|
public ExpNode Body { get; set; }
|
||||||
|
|
||||||
|
public ExpTypeSource IncrementVariableType { get; set; }
|
||||||
|
|
||||||
|
public string CurrentState { get; set; }
|
||||||
|
|
||||||
|
public Token Position { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -28,6 +28,8 @@
|
|||||||
//
|
//
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -102,6 +104,9 @@ namespace StgSharp.Script.Express
|
|||||||
if( TryParseInstance( t ) ) {
|
if( TryParseInstance( t ) ) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if( TryParseKeyword( t ) ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
//Many thing miss here
|
//Many thing miss here
|
||||||
|
|
||||||
@@ -230,9 +235,26 @@ namespace StgSharp.Script.Express
|
|||||||
{
|
{
|
||||||
_cache.PushOperand( ExpInstanceReferenceNode.MakeReferenceFrom( t, instance ) );
|
_cache.PushOperand( ExpInstanceReferenceNode.MakeReferenceFrom( t, instance ) );
|
||||||
return true;
|
return true;
|
||||||
|
} else if( _tempVariableInLoops.TryGetValue( t.Value, out instance ) ) {
|
||||||
|
_cache.PushOperand( ExpInstanceReferenceNode.MakeReferenceFrom( t, instance ) );
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool TryParseKeyword( Token t )
|
||||||
|
{
|
||||||
|
switch( t.Value )
|
||||||
|
{
|
||||||
|
case ExpKeyword.Return:
|
||||||
|
_cache.PushOperator( t );
|
||||||
|
return true;
|
||||||
|
case ExpKeyword.Skip:
|
||||||
|
_cache.PushOperand( ExpProcedureControlNode.Skip( t ) );
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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+17a226c20653a1c92f6a3b420d6388c31f6a8c1e")]
|
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+1a1db3554b10ed4a707671695d5100eee621af75")]
|
||||||
[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/17a226c20653a1c92f6a3b420d6388c31f6a8c1e/*"}}
|
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\内核源代码\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/1a1db3554b10ed4a707671695d5100eee621af75/*"}}
|
||||||
Reference in New Issue
Block a user