如何处理python中的结构化语言文件
How to process the stuctured language file in python
我有一个像这样的大结构化语言文件:
TASK SchM_Task {
TYPE = AUTO;
SCHEDULE = NON;
PRIORITY = 160;
ACTIVATION = 1;
TIMING_PROTECTION = FALSE;
AUTOSTART = FALSE;
EVENT = SchM_Event;
RESOURCE = SystemS_Resource;
StackSize = 1024;
NotUsingSchedule = FALSE;
}: "BSW task for calling of bsw runnables";
ALARM SchM_Alarm {
COUNTER = SystemTimer;
ACTION = SETEVENT
{
TASK = SchM_Task;
EVENT = SchM_Event;
};
AUTOSTART = FALSE
{
StaticAlarm = FALSE;
};
};
RESOURCE SystemS_Resource {
RESOURCEPROPERTY = INTERNAL;
}: "Via this resource the cooperativ behavior can be set";
EVENT SchM_Event {
MASK = AUTO;
};
ISR CanIsr_1 {
CATEGORY = 2;
TIMING_PROTECTION = FALSE;
EnableNesting = TRUE;
InterruptLevel = 30;
InterruptSource = CAN1IRQ;
StackSize = 1024;
UseSpecialFunctionName = FALSE;
}: "CAN Send/Receive (main CAN)";
我对 python 和脚本编写真的很陌生。如何使用 python 将此文本文件解析为 AST。在网上搜索时,我发现 python 中的 grako 可能是一个选项。你能解释一下 grako 是如何使用示例代码工作的吗?先谢谢了。
我有一个像这样的大结构化语言文件:
TASK SchM_Task {
TYPE = AUTO;
SCHEDULE = NON;
PRIORITY = 160;
ACTIVATION = 1;
TIMING_PROTECTION = FALSE;
AUTOSTART = FALSE;
EVENT = SchM_Event;
RESOURCE = SystemS_Resource;
StackSize = 1024;
NotUsingSchedule = FALSE;
}: "BSW task for calling of bsw runnables";
ALARM SchM_Alarm {
COUNTER = SystemTimer;
ACTION = SETEVENT
{
TASK = SchM_Task;
EVENT = SchM_Event;
};
AUTOSTART = FALSE
{
StaticAlarm = FALSE;
};
};
RESOURCE SystemS_Resource {
RESOURCEPROPERTY = INTERNAL;
}: "Via this resource the cooperativ behavior can be set";
EVENT SchM_Event {
MASK = AUTO;
};
ISR CanIsr_1 {
CATEGORY = 2;
TIMING_PROTECTION = FALSE;
EnableNesting = TRUE;
InterruptLevel = 30;
InterruptSource = CAN1IRQ;
StackSize = 1024;
UseSpecialFunctionName = FALSE;
}: "CAN Send/Receive (main CAN)";
我对 python 和脚本编写真的很陌生。如何使用 python 将此文本文件解析为 AST。在网上搜索时,我发现 python 中的 grako 可能是一个选项。你能解释一下 grako 是如何使用示例代码工作的吗?先谢谢了。