编程语言
首页 > 编程语言> > 如何在python中处理结构化语言文件

如何在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的工作方式.谢谢你

解决方法:

语言似乎很简单.无论使用哪种编程语言,您都应该阅读一些有关parsing的内容,以了解您必须做什么.

PyParsing在Python程序员中很流行.我认为Grako(我是作者)对于初学者来说太复杂了.

标签:ebnf,parser-generator,abstract-syntax-tree,python,grako
来源: https://codeday.me/bug/20191120/2045781.html