如何用正式的BNF来描述这一事件日志? [英] How to describe this event log in formal BNF?

查看:8
本文介绍了如何用正式的BNF来描述这一事件日志?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的事件日志格式,只是在BNF(对于gocc)中描述它有困难。

以下是我的简单事件日志格式:

timestamp nested-event-A Running
timestamp Start of nested-event-B
timestamp Start unested-event-C
timestamp End unested-event-C
timestamp Start unested-event-D
timestamp End unested-event-D
timestamp Start unested-event-E
timestamp End unested-event-E
. . .
timestamp End of nested-event-B 
timestamp nested-event-A completed

假设语法以EventLog开始,我甚至在启动第一个BNF时都遇到了困难。

我应该从

开始吗?
EventLog ::= nested-event | unested-event

我应该从

开始吗?
EventLog ::= nested-event

nested-event ::= nested-event-start unested-event+ nested-event-end

您认为描述它的最佳方式是什么?

推荐答案

好的,这是完整的goccbnf,经过测试并正常工作:

/* Lexical part */

_digit : '0'-'9' ;

_jobLog     : 'M'  'y'  'J'  'o'  'b' ;

_lineend : [ '
' ] '
' ;

timestamp
  : _digit _digit _digit _digit '-' _digit _digit '-' _digit _digit
    ' ' _digit _digit ':' _digit _digit ':' _digit _digit '.' { _digit } ' '
  ;

jobLogStart     : _jobLog' '  'R'  'u'  'n'  'n'  'i'  'n'  'g'  ' '  'j'  'o'  'b' _lineend ;
processLogStart : 'S'  't'  'a'  'r'  't'  ' '  'o'  'f'  ' ' { . } _lineend;
taskLogStart    : 'S'  't'  'a'  'r'  't'  ' ' { . } _lineend;
taskLogEnd  : 'E'  'n'  'd'  ' ' { . } _lineend;
processLogEnd   : 'E'  'n'  'd'  ' '  'o'  'f'  ' ' { . } _lineend;
jobLogEnd       : _jobLog ' '  'J'  'o'  'b'  ' '  'c'  'o'  'm'  'p'  'l'  'e'  't'  'e'  'd' _lineend ;


/* Syntax part */

EventLog
  : JobLog
  ;

JobLog
  : JobLogStart ProcessLog JobLogEnd
  ;

ProcessLog
  : ProcessLogStart TaskLog ProcessLogEnd
  ;

TaskLog
  : TaskLogStart TaskLogEnd
  | TaskLog
    TaskLogStart TaskLogEnd
  ;

TaskLogStart : timestamp taskLogStart ;
TaskLogEnd   : timestamp  taskLogEnd  ;

ProcessLogStart : timestamp processLogStart ;
ProcessLogEnd   : timestamp  processLogEnd  ;

JobLogStart : timestamp jobLogStart ;
JobLogEnd   : timestamp  jobLogEnd  ;

为了完整性,以下是使用上述语法测试良好的示例数据:

2022-01-18 10:19:41.6007 MyJob Running job
2022-01-18 10:21:24.8027 Start of The Processing 1/18/2022
2022-01-18 10:21:24.8027 Start unested event C
2022-01-18 10:21:24.8027 End unested event C
2022-01-18 10:21:24.8199 Start unested event D with more words
2022-01-18 10:33:21.9885 End unested event D with more words
2022-01-18 10:33:21.9885 Start unested event E with different words
2022-01-18 10:33:21.9885 End unested event E with different words
2022-01-18 10:33:23.9087 Start unested event F with different words
2022-01-18 10:33:40.8774 End unested event F with different words
2022-01-18 10:33:40.8774 Start ...
2022-01-18 10:35:13.4284 End ...
2022-01-18 10:35:13.4445 Start ...
2022-01-18 10:35:13.5237 End ...
2022-01-18 10:35:13.5237 Start ...
2022-01-18 10:35:13.6597 End ...
2022-01-18 10:35:13.6597 Start ...
2022-01-18 10:36:24.4468 End ...
2022-01-18 10:36:24.4468 Start ...
2022-01-18 10:36:24.4554 End ...
2022-01-18 10:36:24.7238 End of The Processing 1/18/2022
2022-01-18 10:36:24.9746 MyJob Job completed

这篇关于如何用正式的BNF来描述这一事件日志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆