feat: 按照open_set中的示例调整语法 (#71)

添加了构建LR分析表冲突的报错

Reviewed-on: PostGuard/Canon#71
This commit is contained in:
2024-05-01 21:06:27 +08:00
parent feddbff205
commit 6130adfa7c
32 changed files with 1382 additions and 985 deletions

View File

@@ -38,28 +38,6 @@ public class BasicType : NonTerminatedSyntaxNode
}
}
public override void GenerateCCode(CCodeBuilder builder)
{
var keywordType = Children[0].Convert<TerminatedSyntaxNode>().Token
.Convert<KeywordSemanticToken>().KeywordType;
switch (keywordType)
{
case KeywordType.Integer:
builder.AddString(" int");
break;
case KeywordType.Real:
builder.AddString(" double");
break;
case KeywordType.Boolean:
builder.AddString(" bool");
break;
case KeywordType.Character:
builder.AddString(" char");
break;
}
}
public override void PreVisit(SyntaxNodeVisitor visitor)
{
visitor.PreVisit(this);

View File

@@ -6,12 +6,12 @@ using Canon.Core.SemanticParser;
namespace Canon.Core.SyntaxNodes;
public class OnSimpleExpressionGeneratorEventArgs : EventArgs
public class SimpleExpressionGeneratorEventArgs : EventArgs
{
public required SimpleExpression SimpleExpression { get; init; }
}
public class OnRelationGeneratorEventArgs : EventArgs
public class RelationGeneratorEventArgs : EventArgs
{
public required SimpleExpression Left { get; init; }
@@ -76,12 +76,12 @@ public class Expression : NonTerminatedSyntaxNode
/// <summary>
/// 直接赋值产生式的事件
/// </summary>
public event EventHandler<OnSimpleExpressionGeneratorEventArgs>? OnSimpleExpressionGenerator;
public event EventHandler<SimpleExpressionGeneratorEventArgs>? OnSimpleExpressionGenerator;
/// <summary>
/// 关系产生式的事件
/// </summary>
public event EventHandler<OnRelationGeneratorEventArgs>? OnRelationGenerator;
public event EventHandler<RelationGeneratorEventArgs>? OnRelationGenerator;
private PascalType? _expressionType;
@@ -111,14 +111,14 @@ public class Expression : NonTerminatedSyntaxNode
{
if (Children.Count == 1)
{
OnSimpleExpressionGenerator?.Invoke(this, new OnSimpleExpressionGeneratorEventArgs
OnSimpleExpressionGenerator?.Invoke(this, new SimpleExpressionGeneratorEventArgs
{
SimpleExpression = Children[0].Convert<SimpleExpression>()
});
}
else
{
OnRelationGenerator?.Invoke(this, new OnRelationGeneratorEventArgs
OnRelationGenerator?.Invoke(this, new RelationGeneratorEventArgs
{
Left = Children[0].Convert<SimpleExpression>(),
Operator = Children[1].Convert<RelationOperator>(),

View File

@@ -1,43 +1,57 @@
using Canon.Core.Abstractions;
using Canon.Core.CodeGenerators;
using Canon.Core.Enums;
using Canon.Core.LexicalParser;
using Canon.Core.SemanticParser;
namespace Canon.Core.SyntaxNodes;
public class OnNumberGeneratorEventArgs : EventArgs
public class NumberGeneratorEventArgs : EventArgs
{
public required NumberSemanticToken Token { get; init; }
}
public class OnVariableGeneratorEventArgs : EventArgs
public class VariableGeneratorEventArgs : EventArgs
{
public required Variable Variable { get; init; }
}
public class OnParethnesisGeneratorEventArgs : EventArgs
public class ParethnesisGeneratorEventArgs : EventArgs
{
public required Expression Expression { get; init; }
}
public class OnProcedureCallGeneratorEventArgs : EventArgs
public class NoParameterProcedureCallGeneratorEventArgs : EventArgs
{
public required IdentifierSemanticToken ProcedureName { get; init; }
}
public class ProcedureCallGeneratorEventArgs : EventArgs
{
public required IdentifierSemanticToken ProcedureName { get; init; }
public required ExpressionList Parameters { get; init; }
}
public class OnNotGeneratorEventArgs : EventArgs
public class NotGeneratorEventArgs : EventArgs
{
public required Factor Factor { get; init; }
}
public class OnUminusGeneratorEventArgs : EventArgs
public class UminusGeneratorEventArgs : EventArgs
{
public required Factor Factor { get; init; }
}
public class PlusGeneratorEventArgs : EventArgs
{
public required Factor Factor { get; init; }
}
public class BooleanGeneratorEventArgs : EventArgs
{
public required bool Value { get; init; }
}
public class Factor : NonTerminatedSyntaxNode
{
public override NonTerminatorType Type => NonTerminatorType.Factor;
@@ -57,32 +71,47 @@ public class Factor : NonTerminatedSyntaxNode
/// <summary>
/// 使用数值产生式的事件
/// </summary>
public event EventHandler<OnNumberGeneratorEventArgs>? OnNumberGenerator;
public event EventHandler<NumberGeneratorEventArgs>? OnNumberGenerator;
/// <summary>
/// 使用括号产生式的事件
/// </summary>
public event EventHandler<OnParethnesisGeneratorEventArgs>? OnParethnesisGenerator;
public event EventHandler<ParethnesisGeneratorEventArgs>? OnParethnesisGenerator;
/// <summary>
/// 使用变量产生式的事件
/// </summary>
public event EventHandler<OnVariableGeneratorEventArgs>? OnVariableGenerator;
/// <summary>
/// 使用过程调用产生式的事件
/// </summary>
public event EventHandler<OnProcedureCallGeneratorEventArgs>? OnProcedureCallGenerator;
public event EventHandler<VariableGeneratorEventArgs>? OnVariableGenerator;
/// <summary>
/// 使用否定产生式的事件
/// </summary>
public event EventHandler<OnNotGeneratorEventArgs>? OnNotGenerator;
public event EventHandler<NotGeneratorEventArgs>? OnNotGenerator;
/// <summary>
/// 使用负号产生式的事件
/// </summary>
public event EventHandler<OnUminusGeneratorEventArgs>? OnUminusGenerator;
public event EventHandler<UminusGeneratorEventArgs>? OnUminusGenerator;
/// <summary>
/// 使用加号产生式的事件
/// </summary>
public event EventHandler<PlusGeneratorEventArgs>? OnPlusGenerator;
/// <summary>
/// 使用布尔值产生式的事件
/// </summary>
public event EventHandler<BooleanGeneratorEventArgs>? OnBooleanGenerator;
/// <summary>
/// 没有参数的过程调用产生式事件
/// </summary>
public event EventHandler<NoParameterProcedureCallGeneratorEventArgs>? OnNoParameterProcedureCallGenerator;
/// <summary>
/// 过程调用产生式的事件
/// </summary>
public event EventHandler<ProcedureCallGeneratorEventArgs>? OnProcedureCallGenerator;
private PascalType? _factorType;
@@ -97,10 +126,7 @@ public class Factor : NonTerminatedSyntaxNode
return _factorType;
}
set
{
_factorType = value;
}
set { _factorType = value; }
}
public static Factor Create(List<SyntaxNodeBase> children)
@@ -112,51 +138,94 @@ public class Factor : NonTerminatedSyntaxNode
{
if (Children.Count == 1)
{
//factor -> num
if (Children[0].IsTerminated)
{
SemanticToken token = Children[0].Convert<TerminatedSyntaxNode>().Token;
OnNumberGenerator?.Invoke(this,
new OnNumberGeneratorEventArgs { Token = token.Convert<NumberSemanticToken>() });
switch (token.TokenType)
{
// factor -> num
case SemanticTokenType.Number:
OnNumberGenerator?.Invoke(this,
new NumberGeneratorEventArgs { Token = token.Convert<NumberSemanticToken>() });
break;
// factor -> true | false
case SemanticTokenType.Keyword:
KeywordSemanticToken keywordSemanticToken = token.Convert<KeywordSemanticToken>();
switch (keywordSemanticToken.KeywordType)
{
case KeywordType.True:
OnBooleanGenerator?.Invoke(this, new BooleanGeneratorEventArgs { Value = true });
break;
case KeywordType.False:
OnBooleanGenerator?.Invoke(this, new BooleanGeneratorEventArgs { Value = false });
break;
}
break;
}
}
// factor -> variable
else
{
OnVariableGenerator?.Invoke(this,
new OnVariableGeneratorEventArgs { Variable = Children[0].Convert<Variable>() });
new VariableGeneratorEventArgs { Variable = Children[0].Convert<Variable>() });
}
}
//factor -> ( expression )
else if (Children.Count == 3)
{
OnParethnesisGenerator?.Invoke(this,
new OnParethnesisGeneratorEventArgs { Expression = Children[1].Convert<Expression>() });
TerminatedSyntaxNode terminatedSyntaxNode = Children[0].Convert<TerminatedSyntaxNode>();
// factor -> ( expression )
if (terminatedSyntaxNode.Token.TokenType == SemanticTokenType.Delimiter)
{
OnParethnesisGenerator?.Invoke(this,
new ParethnesisGeneratorEventArgs { Expression = Children[1].Convert<Expression>() });
}
else
{
// factor -> id ( )
OnNoParameterProcedureCallGenerator?.Invoke(this, new NoParameterProcedureCallGeneratorEventArgs
{
ProcedureName = terminatedSyntaxNode.Token.Convert<IdentifierSemanticToken>()
});
}
}
//factor -> id ( expression )
else if (Children.Count == 4)
{
OnProcedureCallGenerator?.Invoke(this,
new OnProcedureCallGeneratorEventArgs
{
ProcedureName =
Children[0].Convert<TerminatedSyntaxNode>().Token.Convert<IdentifierSemanticToken>(),
Parameters = Children[2].Convert<ExpressionList>()
});
// factor -> id ( expressionList)
OnProcedureCallGenerator?.Invoke(this, new ProcedureCallGeneratorEventArgs
{
ProcedureName = Children[0].Convert<TerminatedSyntaxNode>().Token.Convert<IdentifierSemanticToken>(),
Parameters = Children[2].Convert<ExpressionList>()
});
}
else
{
SemanticToken token = Children[0].Convert<TerminatedSyntaxNode>().Token;
Factor factor = Children[1].Convert<Factor>();
if (token.TokenType == SemanticTokenType.Keyword)
{
// factor -> not factor
OnNotGenerator?.Invoke(this, new OnNotGeneratorEventArgs { Factor = factor });
OnNotGenerator?.Invoke(this, new NotGeneratorEventArgs { Factor = factor });
}
else
{
// factor -> uminus factor
OnUminusGenerator?.Invoke(this, new OnUminusGeneratorEventArgs { Factor = factor });
OperatorSemanticToken operatorSemanticToken = token.Convert<OperatorSemanticToken>();
switch (operatorSemanticToken.OperatorType)
{
// factor -> + factor
case OperatorType.Plus:
OnPlusGenerator?.Invoke(this, new PlusGeneratorEventArgs { Factor = factor });
break;
// factor -> - factor
case OperatorType.Minus:
OnUminusGenerator?.Invoke(this, new UminusGeneratorEventArgs { Factor = factor });
break;
}
}
}

View File

@@ -5,14 +5,14 @@ using Canon.Core.SemanticParser;
namespace Canon.Core.SyntaxNodes;
public class OnIdentifierGeneratorEventArgs : EventArgs
public class IdentifierGeneratorEventArgs : EventArgs
{
public required IdentifierSemanticToken IdentifierToken { get; init; }
public required IdentifierList IdentifierList { get; init; }
}
public class OnTypeGeneratorEventArgs : EventArgs
public class TypeGeneratorEventArgs : EventArgs
{
public required TypeSyntaxNode TypeSyntaxNode { get; init; }
}
@@ -66,9 +66,9 @@ public class IdentifierList : NonTerminatedSyntaxNode
/// </summary>
public bool IsProcedure { get; set; }
public event EventHandler<OnIdentifierGeneratorEventArgs>? OnIdentifierGenerator;
public event EventHandler<IdentifierGeneratorEventArgs>? OnIdentifierGenerator;
public event EventHandler<OnTypeGeneratorEventArgs>? OnTypeGenerator;
public event EventHandler<TypeGeneratorEventArgs>? OnTypeGenerator;
public static IdentifierList Create(List<SyntaxNodeBase> children)
{
@@ -80,11 +80,11 @@ public class IdentifierList : NonTerminatedSyntaxNode
if (Children.Count == 2)
{
OnTypeGenerator?.Invoke(this,
new OnTypeGeneratorEventArgs { TypeSyntaxNode = Children[1].Convert<TypeSyntaxNode>() });
new TypeGeneratorEventArgs { TypeSyntaxNode = Children[1].Convert<TypeSyntaxNode>() });
}
else
{
OnIdentifierGenerator?.Invoke(this, new OnIdentifierGeneratorEventArgs
OnIdentifierGenerator?.Invoke(this, new IdentifierGeneratorEventArgs
{
IdentifierToken = Children[1].Convert<TerminatedSyntaxNode>().Token.Convert<IdentifierSemanticToken>(),
IdentifierList = Children[2].Convert<IdentifierList>()

View File

@@ -4,7 +4,7 @@ using Canon.Core.SemanticParser;
namespace Canon.Core.SyntaxNodes;
public class OnIndexGeneratorEventArgs : EventArgs
public class IndexGeneratorEventArgs : EventArgs
{
public required ExpressionList IndexParameters { get; init; }
}
@@ -38,7 +38,7 @@ public class IdentifierVarPart : NonTerminatedSyntaxNode
/// <summary>
/// 使用了索引产生式的事件
/// </summary>
public event EventHandler<OnIndexGeneratorEventArgs>? OnIndexGenerator;
public event EventHandler<IndexGeneratorEventArgs>? OnIndexGenerator;
public static IdentifierVarPart Create(List<SyntaxNodeBase> children)
{
@@ -49,7 +49,7 @@ public class IdentifierVarPart : NonTerminatedSyntaxNode
{
if (Children.Count == 3)
{
OnIndexGenerator?.Invoke(this, new OnIndexGeneratorEventArgs()
OnIndexGenerator?.Invoke(this, new IndexGeneratorEventArgs()
{
IndexParameters = Children[1].Convert<ExpressionList>()
});

View File

@@ -1,14 +1,17 @@
using Canon.Core.Abstractions;
using Canon.Core.Enums;
using Canon.Core.LexicalParser;
using Canon.Core.SemanticParser;
namespace Canon.Core.SyntaxNodes;
public class OnParameterGeneratorEventArgs : EventArgs
public class ParameterGeneratorEventArgs : EventArgs
{
public required ExpressionList Parameters { get; init; }
}
public class NoParameterGeneratorEventArgs : EventArgs;
public class ProcedureCall : NonTerminatedSyntaxNode
{
public override NonTerminatorType Type => NonTerminatorType.ProcedureCall;
@@ -19,7 +22,31 @@ public class ProcedureCall : NonTerminatedSyntaxNode
/// <summary>
/// 调用函数时含有参数的事件
/// </summary>
public event EventHandler<OnParameterGeneratorEventArgs>? OnParameterGenerator;
public event EventHandler<ParameterGeneratorEventArgs>? OnParameterGenerator;
/// <summary>
/// 调用函数是没有参数的事件
/// </summary>
public event EventHandler<NoParameterGeneratorEventArgs>? OnNoParameterGenerator;
private PascalType? _pascalType;
public PascalType ReturnType
{
get
{
if (_pascalType is null)
{
throw new InvalidOperationException();
}
return _pascalType;
}
set
{
_pascalType = value;
}
}
public override void PreVisit(SyntaxNodeVisitor visitor)
{
@@ -42,12 +69,17 @@ public class ProcedureCall : NonTerminatedSyntaxNode
{
if (Children.Count == 4)
{
OnParameterGenerator?.Invoke(this, new OnParameterGeneratorEventArgs
OnParameterGenerator?.Invoke(this, new ParameterGeneratorEventArgs
{
Parameters = Children[2].Convert<ExpressionList>()
});
}
else
{
OnNoParameterGenerator?.Invoke(this, new NoParameterGeneratorEventArgs());
}
OnParameterGenerator = null;
OnNoParameterGenerator = null;
}
}

View File

@@ -5,12 +5,12 @@ using Canon.Core.SemanticParser;
namespace Canon.Core.SyntaxNodes;
public class OnTermGeneratorEventArgs : EventArgs
public class TermGeneratorEventArgs : EventArgs
{
public required Term Term { get; init; }
}
public class OnAddGeneratorEventArgs : EventArgs
public class AddGeneratorEventArgs : EventArgs
{
public required SimpleExpression Left { get; init; }
@@ -38,12 +38,12 @@ public class SimpleExpression : NonTerminatedSyntaxNode
/// <summary>
/// 直接赋值产生式的事件
/// </summary>
public event EventHandler<OnTermGeneratorEventArgs>? OnTermGenerator;
public event EventHandler<TermGeneratorEventArgs>? OnTermGenerator;
/// <summary>
/// 加法产生式的事件
/// </summary>
public event EventHandler<OnAddGeneratorEventArgs>? OnAddGenerator;
public event EventHandler<AddGeneratorEventArgs>? OnAddGenerator;
private PascalType? _simpleExpressionType;
@@ -73,14 +73,14 @@ public class SimpleExpression : NonTerminatedSyntaxNode
{
if (Children.Count == 1)
{
OnTermGenerator?.Invoke(this, new OnTermGeneratorEventArgs
OnTermGenerator?.Invoke(this, new TermGeneratorEventArgs
{
Term = Children[0].Convert<Term>()
});
}
else
{
OnAddGenerator?.Invoke(this, new OnAddGeneratorEventArgs
OnAddGenerator?.Invoke(this, new AddGeneratorEventArgs
{
Left = Children[0].Convert<SimpleExpression>(),
Operator = Children[1].Convert<AddOperator>(),

View File

@@ -5,21 +5,14 @@ using Canon.Core.LexicalParser;
namespace Canon.Core.SyntaxNodes;
public class OnAssignGeneratorEventArgs : EventArgs
public class AssignGeneratorEventArgs : EventArgs
{
public required Variable Variable { get; init; }
public required Expression Expression { get; init; }
}
public class OnReturnGeneratorEventArgs : EventArgs
{
public required IdentifierSemanticToken FunctionName { get; set; }
public required Expression Expression { get; init; }
}
public class OnIfGeneratorEventArgs : EventArgs
public class IfGeneratorEventArgs : EventArgs
{
public required Expression Condition { get; init; }
@@ -28,7 +21,7 @@ public class OnIfGeneratorEventArgs : EventArgs
public required ElsePart ElseSentence { get; init; }
}
public class OnForGeneratorEventArgs : EventArgs
public class ForGeneratorEventArgs : EventArgs
{
public required IdentifierSemanticToken Iterator { get; init; }
@@ -58,22 +51,17 @@ public class Statement : NonTerminatedSyntaxNode
/// <summary>
/// 使用赋值产生式的事件
/// </summary>
public event EventHandler<OnAssignGeneratorEventArgs>? OnAssignGenerator;
/// <summary>
/// 使用返回产生式的事件
/// </summary>
public event EventHandler<OnReturnGeneratorEventArgs>? OnReturnGenerator;
public event EventHandler<AssignGeneratorEventArgs>? OnAssignGenerator;
/// <summary>
/// 使用If产生式的事件
/// </summary>
public event EventHandler<OnIfGeneratorEventArgs>? OnIfGenerator;
public event EventHandler<IfGeneratorEventArgs>? OnIfGenerator;
/// <summary>
/// 使用For产生式的事件
/// </summary>
public event EventHandler<OnForGeneratorEventArgs>? OnForGenerator;
public event EventHandler<ForGeneratorEventArgs>? OnForGenerator;
public static Statement Create(List<SyntaxNodeBase> children)
{
@@ -84,41 +72,32 @@ public class Statement : NonTerminatedSyntaxNode
{
if (Children.Count == 3)
{
if (Children[0].IsTerminated)
{
OnReturnGenerator?.Invoke(this, new OnReturnGeneratorEventArgs
OnAssignGenerator?.Invoke(this,
new AssignGeneratorEventArgs
{
FunctionName = Children[0].Convert<TerminatedSyntaxNode>().Token.Convert<IdentifierSemanticToken>(),
Expression = Children[2].Convert<Expression>()
Variable = Children[0].Convert<Variable>(), Expression = Children[2].Convert<Expression>()
});
}
else
{
OnAssignGenerator?.Invoke(this, new OnAssignGeneratorEventArgs
{
Variable = Children[0].Convert<Variable>(),
Expression = Children[2].Convert<Expression>()
});
}
}
else if (Children.Count == 5)
{
OnIfGenerator?.Invoke(this, new OnIfGeneratorEventArgs
{
Condition = Children[1].Convert<Expression>(),
Sentence = Children[3].Convert<Statement>(),
ElseSentence = Children[4].Convert<ElsePart>()
});
OnIfGenerator?.Invoke(this,
new IfGeneratorEventArgs
{
Condition = Children[1].Convert<Expression>(),
Sentence = Children[3].Convert<Statement>(),
ElseSentence = Children[4].Convert<ElsePart>()
});
}
else if (Children.Count == 8)
{
OnForGenerator?.Invoke(this, new OnForGeneratorEventArgs
{
Iterator = Children[1].Convert<TerminatedSyntaxNode>().Token.Convert<IdentifierSemanticToken>(),
Begin = Children[3].Convert<Expression>(),
End = Children[5].Convert<Expression>(),
Sentence = Children[7].Convert<Statement>()
});
OnForGenerator?.Invoke(this,
new ForGeneratorEventArgs
{
Iterator = Children[1].Convert<TerminatedSyntaxNode>().Token.Convert<IdentifierSemanticToken>(),
Begin = Children[3].Convert<Expression>(),
End = Children[5].Convert<Expression>(),
Sentence = Children[7].Convert<Statement>()
});
}
}
}

View File

@@ -4,9 +4,9 @@ using Canon.Core.LexicalParser;
namespace Canon.Core.SyntaxNodes;
public class OnProcedureGeneratorEventArgs : EventArgs;
public class ProcedureGeneratorEventArgs : EventArgs;
public class OnFunctionGeneratorEventArgs : EventArgs
public class FunctionGeneratorEventArgs : EventArgs
{
public required BasicType ReturnType { get; init; }
}
@@ -40,9 +40,9 @@ public class SubprogramHead : NonTerminatedSyntaxNode
RaiseEvent();
}
public event EventHandler<OnProcedureGeneratorEventArgs>? OnProcedureGenerator;
public event EventHandler<ProcedureGeneratorEventArgs>? OnProcedureGenerator;
public event EventHandler<OnFunctionGeneratorEventArgs>? OnFunctionGenerator;
public event EventHandler<FunctionGeneratorEventArgs>? OnFunctionGenerator;
public static SubprogramHead Create(List<SyntaxNodeBase> children)
{
@@ -71,12 +71,12 @@ public class SubprogramHead : NonTerminatedSyntaxNode
{
if (IsProcedure)
{
OnProcedureGenerator?.Invoke(this, new OnProcedureGeneratorEventArgs());
OnProcedureGenerator?.Invoke(this, new ProcedureGeneratorEventArgs());
}
else
{
OnFunctionGenerator?.Invoke(this,
new OnFunctionGeneratorEventArgs { ReturnType = Children[4].Convert<BasicType>() });
new FunctionGeneratorEventArgs { ReturnType = Children[4].Convert<BasicType>() });
}
OnProcedureGenerator = null;

View File

@@ -5,7 +5,7 @@ using Canon.Core.LexicalParser;
namespace Canon.Core.SyntaxNodes;
public abstract class SyntaxNodeBase : ICCodeGenerator
public abstract class SyntaxNodeBase
{
public abstract bool IsTerminated { get; }
@@ -25,13 +25,6 @@ public abstract class SyntaxNodeBase : ICCodeGenerator
return result;
}
/// <summary>
/// 语法树节点基类对于生成C代码的默认实现
/// </summary>
public virtual void GenerateCCode(CCodeBuilder builder)
{
}
public override string ToString()
{
return IsTerminated.ToString();

View File

@@ -5,12 +5,12 @@ using Canon.Core.SemanticParser;
namespace Canon.Core.SyntaxNodes;
public class OnFactorGeneratorEventArgs : EventArgs
public class FactorGeneratorEventArgs : EventArgs
{
public required Factor Factor { get; init; }
}
public class OnMultiplyGeneratorEventArgs : EventArgs
public class MultiplyGeneratorEventArgs : EventArgs
{
public required Term Left { get; init; }
@@ -38,12 +38,12 @@ public class Term : NonTerminatedSyntaxNode
/// <summary>
/// 直接赋值产生式的事件
/// </summary>
public event EventHandler<OnFactorGeneratorEventArgs>? OnFactorGenerator;
public event EventHandler<FactorGeneratorEventArgs>? OnFactorGenerator;
/// <summary>
/// 乘法产生式的事件
/// </summary>
public event EventHandler<OnMultiplyGeneratorEventArgs>? OnMultiplyGenerator;
public event EventHandler<MultiplyGeneratorEventArgs>? OnMultiplyGenerator;
private PascalType? _termType;
@@ -73,14 +73,14 @@ public class Term : NonTerminatedSyntaxNode
{
if (Children.Count == 1)
{
OnFactorGenerator?.Invoke(this, new OnFactorGeneratorEventArgs
OnFactorGenerator?.Invoke(this, new FactorGeneratorEventArgs
{
Factor = Children[0].Convert<Factor>()
});
}
else
{
OnMultiplyGenerator?.Invoke(this, new OnMultiplyGeneratorEventArgs
OnMultiplyGenerator?.Invoke(this, new MultiplyGeneratorEventArgs
{
Left = Children[0].Convert<Term>(),
Operator = Children[1].Convert<MultiplyOperator>(),

View File

@@ -5,12 +5,12 @@ using Canon.Core.SemanticParser;
namespace Canon.Core.SyntaxNodes;
public class OnBasicTypeGeneratorEventArgs : EventArgs
public class BasicTypeGeneratorEventArgs : EventArgs
{
public required BasicType BasicType { get; init; }
}
public class OnArrayTypeGeneratorEventArgs : EventArgs
public class ArrayTypeGeneratorEventArgs : EventArgs
{
public required Period Period { get; init; }
@@ -33,9 +33,9 @@ public class TypeSyntaxNode : NonTerminatedSyntaxNode
RaiseEvent();
}
public event EventHandler<OnBasicTypeGeneratorEventArgs>? OnBasicTypeGenerator;
public event EventHandler<BasicTypeGeneratorEventArgs>? OnBasicTypeGenerator;
public event EventHandler<OnArrayTypeGeneratorEventArgs>? OnArrayTypeGenerator;
public event EventHandler<ArrayTypeGeneratorEventArgs>? OnArrayTypeGenerator;
/// <summary>
/// 是否在过程定义中使用
@@ -74,14 +74,14 @@ public class TypeSyntaxNode : NonTerminatedSyntaxNode
{
if (Children.Count == 1)
{
OnBasicTypeGenerator?.Invoke(this, new OnBasicTypeGeneratorEventArgs
OnBasicTypeGenerator?.Invoke(this, new BasicTypeGeneratorEventArgs
{
BasicType = Children[0].Convert<BasicType>()
});
}
else
{
OnArrayTypeGenerator?.Invoke(this, new OnArrayTypeGeneratorEventArgs
OnArrayTypeGenerator?.Invoke(this, new ArrayTypeGeneratorEventArgs
{
Period = Children[2].Convert<Period>(),
BasicType = Children[5].Convert<BasicType>()