Daily update on 20250324-100332 by Nitload Youmu. Additional Message : Single line syntax analyzer ok, gonging on unit test of multi line, func call. Then building branch, loop, area syntax analyzer. Some of descriptors not supported.

Signed-off-by: Nitload <YoumuLiu_NSI@whv0t.onmicrosoft.com>
This commit is contained in:
Nitload
2025-03-24 10:03:32 +08:00
parent 148b0fed4a
commit ffd5825a05
52 changed files with 522 additions and 560 deletions
@@ -46,7 +46,12 @@ namespace StgSharp.Script.Express
private ExpNode _left;
private ExpNode _right;
private ExpBinaryOperatorNode( Token source ) : base( source ) { }
private ExpBinaryOperatorNode( Token source, ExpNode left, ExpNode right )
: base( source )
{
_left = left;
_right = right;
}
public override ExpInstantiableElement EqualityTypeConvert => _returnType;
@@ -54,77 +59,59 @@ namespace StgSharp.Script.Express
public override ExpNode Right => _right;
public static ExpBinaryOperatorNode Add(
Token source,
ExpNode left,
ExpNode right )
public static ExpBinaryOperatorNode Add( Token source, ExpNode left, ExpNode right )
{
if( !left.IsNumber && !right.IsNumber ) {
throw new ExpInvalidTypeException(
"Number", left.EqualityTypeConvert.Name );
throw new ExpInvalidTypeException( "Number", left.EqualityTypeConvert.Name );
}
bool isFloat =
( left._nodeFlag | ExpNodeFlag.BuiltinType_Real ) == 0 || ( right._nodeFlag | ExpNodeFlag.BuiltinType_Real ) ==
0;
return new ExpBinaryOperatorNode( source )
return new ExpBinaryOperatorNode( source, left, right )
{
_returnType = isFloat ?
ExpressCompile.ExpReal : ExpressCompile.ExpInt,
_returnType = isFloat ? ExpressCompile.ExpReal : ExpressCompile.ExpInt,
_nodeFlag = ExpNodeFlag.Operator_Binary | ExpNodeFlag.BuiltinType_Number,
CodeConvertTemplate = "{0} + {1}",
};
}
public static ExpBinaryOperatorNode Assign(
Token source,
ExpNode left,
ExpNode right )
public static ExpBinaryOperatorNode Assign( Token source, ExpNode left, ExpNode right )
{
if( left.EqualityTypeConvert != right.EqualityTypeConvert ) {
throw new ExpInvalidTypeException(
left.EqualityTypeConvert.Name,
right.EqualityTypeConvert.Name );
left.EqualityTypeConvert.Name, right.EqualityTypeConvert.Name );
}
return new ExpBinaryOperatorNode( source )
return new ExpBinaryOperatorNode( source, left, right )
{
_returnType = ExpInstantiableElement.Void,
_nodeFlag = ExpNodeFlag.Operator_Binary | left._nodeFlag,
CodeConvertTemplate = "{0} & {1}",
CodeConvertTemplate = "{0} = {1}",
};
}
public static ExpBinaryOperatorNode Div(
Token source,
ExpNode left,
ExpNode right )
public static ExpBinaryOperatorNode Div( Token source, ExpNode left, ExpNode right )
{
if( !left.IsNumber && !right.IsNumber ) {
throw new ExpInvalidTypeException(
"Number", left.EqualityTypeConvert.Name );
throw new ExpInvalidTypeException( "Number", left.EqualityTypeConvert.Name );
}
bool isFloat =
( left._nodeFlag | ExpNodeFlag.BuiltinType_Real ) == 0 || ( right._nodeFlag | ExpNodeFlag.BuiltinType_Real ) ==
0;
return new ExpBinaryOperatorNode( source )
return new ExpBinaryOperatorNode( source, left, right )
{
_returnType = isFloat ?
ExpressCompile.ExpReal : ExpressCompile.ExpInt,
_returnType = isFloat ? ExpressCompile.ExpReal : ExpressCompile.ExpInt,
_nodeFlag = ExpNodeFlag.Operator_Binary | ExpNodeFlag.BuiltinType_Number,
CodeConvertTemplate = "{0} / {1}",
};
}
public static ExpBinaryOperatorNode EqualTo(
Token source,
ExpNode left,
ExpNode right )
public static ExpBinaryOperatorNode EqualTo( Token source, ExpNode left, ExpNode right )
{
if( left.EqualityTypeConvert != right.EqualityTypeConvert ) {
throw new ExpInvalidTypeException(
left.EqualityTypeConvert.Name,
right.EqualityTypeConvert.Name );
left.EqualityTypeConvert.Name, right.EqualityTypeConvert.Name );
}
return new ExpBinaryOperatorNode( source )
return new ExpBinaryOperatorNode( source, left, right )
{
_returnType = ExpressCompile.ExpBool,
_nodeFlag = ExpNodeFlag.BuiltinType_Boolean | ExpNodeFlag.Operator_Binary,
@@ -132,16 +119,12 @@ namespace StgSharp.Script.Express
};
}
public static ExpBinaryOperatorNode GreaterThan(
Token source,
ExpNode left,
ExpNode right )
public static ExpBinaryOperatorNode GreaterThan( Token source, ExpNode left, ExpNode right )
{
if( !left.IsNumber && !right.IsNumber ) {
throw new ExpInvalidTypeException(
"Number", left.EqualityTypeConvert.Name );
throw new ExpInvalidTypeException( "Number", left.EqualityTypeConvert.Name );
}
return new ExpBinaryOperatorNode( source )
return new ExpBinaryOperatorNode( source, left, right )
{
_returnType = ExpressCompile.ExpBool,
_nodeFlag = ExpNodeFlag.BuiltinType_Boolean | ExpNodeFlag.Operator_Binary,
@@ -149,16 +132,12 @@ namespace StgSharp.Script.Express
};
}
public static ExpBinaryOperatorNode LessThan(
Token source,
ExpNode left,
ExpNode right )
public static ExpBinaryOperatorNode LessThan( Token source, ExpNode left, ExpNode right )
{
if( !left.IsNumber && !right.IsNumber ) {
throw new ExpInvalidTypeException(
"Number", left.EqualityTypeConvert.Name );
throw new ExpInvalidTypeException( "Number", left.EqualityTypeConvert.Name );
}
return new ExpBinaryOperatorNode( source )
return new ExpBinaryOperatorNode( source, left, right )
{
_returnType = ExpressCompile.ExpBool,
_nodeFlag = ExpNodeFlag.BuiltinType_Boolean | ExpNodeFlag.Operator_Binary,
@@ -166,38 +145,29 @@ namespace StgSharp.Script.Express
};
}
public static ExpBinaryOperatorNode Mul(
Token source,
ExpNode left,
ExpNode right )
public static ExpBinaryOperatorNode Mul( Token source, ExpNode left, ExpNode right )
{
if( !left.IsNumber && !right.IsNumber ) {
throw new ExpInvalidTypeException(
"Number", left.EqualityTypeConvert.Name );
throw new ExpInvalidTypeException( "Number", left.EqualityTypeConvert.Name );
}
bool isFloat =
( left._nodeFlag | ExpNodeFlag.BuiltinType_Real ) == 0 || ( right._nodeFlag | ExpNodeFlag.BuiltinType_Real ) ==
0;
return new ExpBinaryOperatorNode( source )
return new ExpBinaryOperatorNode( source, left, right )
{
_returnType = isFloat ?
ExpressCompile.ExpReal : ExpressCompile.ExpInt,
_returnType = isFloat ? ExpressCompile.ExpReal : ExpressCompile.ExpInt,
_nodeFlag = ExpNodeFlag.Operator_Binary | ExpNodeFlag.BuiltinType_Number,
CodeConvertTemplate = "{0} * {1}",
};
}
public static ExpBinaryOperatorNode NotEqualTo(
Token source,
ExpNode left,
ExpNode right )
public static ExpBinaryOperatorNode NotEqualTo( Token source, ExpNode left, ExpNode right )
{
if( left.EqualityTypeConvert != right.EqualityTypeConvert ) {
throw new ExpInvalidTypeException(
left.EqualityTypeConvert.Name,
right.EqualityTypeConvert.Name );
left.EqualityTypeConvert.Name, right.EqualityTypeConvert.Name );
}
return new ExpBinaryOperatorNode( source )
return new ExpBinaryOperatorNode( source, left, right )
{
_returnType = ExpressCompile.ExpBool,
_nodeFlag = ExpNodeFlag.BuiltinType_Boolean | ExpNodeFlag.Operator_Binary,
@@ -205,16 +175,12 @@ namespace StgSharp.Script.Express
};
}
public static ExpBinaryOperatorNode SmallerThan(
Token source,
ExpNode left,
ExpNode right )
public static ExpBinaryOperatorNode SmallerThan( Token source, ExpNode left, ExpNode right )
{
if( !left.IsNumber && !right.IsNumber ) {
throw new ExpInvalidTypeException(
"Number", left.EqualityTypeConvert.Name );
throw new ExpInvalidTypeException( "Number", left.EqualityTypeConvert.Name );
}
return new ExpBinaryOperatorNode( source )
return new ExpBinaryOperatorNode( source, left, right )
{
_returnType = ExpressCompile.ExpBool,
_nodeFlag = ExpNodeFlag.BuiltinType_Boolean | ExpNodeFlag.Operator_Binary,
@@ -222,22 +188,17 @@ namespace StgSharp.Script.Express
};
}
public static ExpBinaryOperatorNode Sub(
Token source,
ExpNode left,
ExpNode right )
public static ExpBinaryOperatorNode Sub( Token source, ExpNode left, ExpNode right )
{
if( !left.IsNumber && !right.IsNumber ) {
throw new ExpInvalidTypeException(
"Number", left.EqualityTypeConvert.Name );
throw new ExpInvalidTypeException( "Number", left.EqualityTypeConvert.Name );
}
bool isFloat =
( left._nodeFlag | ExpNodeFlag.BuiltinType_Real ) == 0 || ( right._nodeFlag | ExpNodeFlag.BuiltinType_Real ) ==
0;
return new ExpBinaryOperatorNode( source )
return new ExpBinaryOperatorNode( source, left, right )
{
_returnType = isFloat ?
ExpressCompile.ExpReal : ExpressCompile.ExpInt,
_returnType = isFloat ? ExpressCompile.ExpReal : ExpressCompile.ExpInt,
_nodeFlag = ExpNodeFlag.Operator_Binary | ExpNodeFlag.BuiltinType_Number,
CodeConvertTemplate = "{0} - {1}",
};
@@ -55,9 +55,7 @@ namespace StgSharp.Script.Express
get
{
ExpSchema.BuiltinSchema
.TryGetType(
ExpressCompile.KeyWord.String,
out ExpTypeSource? strType );
.TryGetType( ExpressCompile.Keyword.String, out ExpTypeSource? strType );
return strType;
}
}
@@ -42,22 +42,19 @@ namespace StgSharp.Script.Express
private ExpElementInstanceBase _instance;
internal ExpInstanceReferenceNode(
Token source,
ExpElementInstanceBase instance )
internal ExpInstanceReferenceNode( Token source, ExpElementInstanceBase instance )
: base( source )
{
_instance = instance;
_nodeFlag = ( _instance._nodeFlag | ( ExpNodeFlag.Name_Any | ExpNodeFlag.Collection_Any ) );
}
internal ExpInstanceReferenceNode(
Token source,
ExpInstanceReferenceNode reference )
internal ExpInstanceReferenceNode( Token source, ExpInstanceReferenceNode reference )
: base( source )
{
_instance = reference._instance;
_nodeFlag = ( _instance._nodeFlag | ( ExpNodeFlag.Name_Any | ExpNodeFlag.Collection_Any ) );
CodeConvertTemplate = source.Value;
}
public override ExpNode Left => Empty;
@@ -68,9 +65,14 @@ namespace StgSharp.Script.Express
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static ExpInstanceReferenceNode Create(
Token source,
ExpElementInstanceBase instance )
Token source,
ExpElementInstanceBase instance )
{
/*
if( instance.CodeConvertTemplate != source.Value ) {
throw new ExpCompileException( source, "Token point at a wrong instance" );
}
/**/
return new ExpInstanceReferenceNode( source, instance );
}
@@ -50,14 +50,14 @@ namespace StgSharp.Script.Express
}
public override IExpElementSource EqualityTypeConvert => ExpSchema.BuiltinSchema
.TryGetType(
ExpressCompile.KeyWord.Integer,
out ExpTypeSource? type ) ?
.TryGetType(
ExpressCompile.Keyword.Integer,
out ExpTypeSource? type ) ?
type : throw new ExpCompileNotInitializedException();
public int Value => _value;
public override string TypeName => ExpressCompile.KeyWord.Integer;
public override string TypeName => ExpressCompile.Keyword.Integer;
}
@@ -74,9 +74,9 @@ namespace StgSharp.Script.Express
}
public override IExpElementSource EqualityTypeConvert => ExpSchema.BuiltinSchema
.TryGetType(
ExpressCompile.KeyWord.String,
out ExpTypeSource? type ) ?
.TryGetType(
ExpressCompile.Keyword.String,
out ExpTypeSource? type ) ?
type : throw new ExpCompileNotInitializedException();
public override string TypeName => EqualityTypeConvert.Name;
@@ -100,9 +100,9 @@ namespace StgSharp.Script.Express
public bool Value => _value;
public override IExpElementSource EqualityTypeConvert => ExpSchema.BuiltinSchema
.TryGetType(
ExpressCompile.KeyWord.Boolean,
out ExpTypeSource? type ) ?
.TryGetType(
ExpressCompile.Keyword.Boolean,
out ExpTypeSource? type ) ?
type : throw new ExpCompileNotInitializedException();
public override string TypeName => EqualityTypeConvert.Name;
@@ -124,9 +124,9 @@ namespace StgSharp.Script.Express
public float Value => _value;
public override IExpElementSource EqualityTypeConvert => ExpSchema.BuiltinSchema
.TryGetType(
ExpressCompile.KeyWord.String,
out ExpTypeSource? type ) ?
.TryGetType(
ExpressCompile.Keyword.String,
out ExpTypeSource? type ) ?
type : throw new ExpCompileNotInitializedException();
public override string TypeName => EqualityTypeConvert.Name;
@@ -148,9 +148,9 @@ namespace StgSharp.Script.Express
public ExpLogic Value => _value;
public override IExpElementSource EqualityTypeConvert => ExpSchema.BuiltinSchema
.TryGetType(
ExpressCompile.KeyWord.Logical,
out ExpTypeSource? type ) ?
.TryGetType(
ExpressCompile.Keyword.Logical,
out ExpTypeSource? type ) ?
type : throw new ExpCompileNotInitializedException();
public override string TypeName => EqualityTypeConvert.Name;
+10 -27
View File
@@ -56,37 +56,20 @@ namespace StgSharp.Script.Express
get { return ( _nodeFlag | ExpNodeFlag.BuiltinType_Number ) != 0; }
}
public abstract ExpNode Left
{
get;
}
public abstract ExpNode Left { get; }
public static ExpNode Empty
{
get => ExpEmptyNode._only;
}
public ExpNode Next
{
get;
set;
}
public ExpNode Next { get; set; }
public abstract ExpNode Right
{
get;
}
public abstract ExpNode Right { get; }
public ExpNode Previous
{
get;
set;
}
public ExpNode Previous { get; set; }
public abstract IExpElementSource EqualityTypeConvert
{
get;
}
public abstract IExpElementSource EqualityTypeConvert { get; }
public int Line => _source.Line;
@@ -94,10 +77,11 @@ namespace StgSharp.Script.Express
public long NodeFlag => ( long )_nodeFlag;
public string CodeConvertTemplate
public string CodeConvertTemplate { get; init; }
public Token Source
{
get;
init;
get => _source;
}
public void AppendNode( ExpNode nextNode )
@@ -160,8 +144,7 @@ namespace StgSharp.Script.Express
public ExpEmptyNode() : base( Token.Empty ) { }
public ExpEmptyNode( int line, int column )
: base(
new Token( string.Empty, line, column, TokenFlag.None ) ) { }
: base( new Token( string.Empty, line, column, TokenFlag.None ) ) { }
public override ExpInstantiableElement EqualityTypeConvert => ExpInstantiableElement.Void;