我试图弄清楚为什么我的Antlr生成的解析器没有将输入的一部分识别为与我的一条规则(“ and_converge”规则,“网关”的一部分)匹配。我的语法看起来像:
process : PROCESS id CURLY_OPEN (stmt_list | pool_list) CURLY_CLOSE EOF ; /* starting rule */
stmt_list : (stmt STMT_TERM?)* ;
stmt : sequence | sequence_elem | association ;
sequence : sequence_elem sequence_flow sequence_elem (sequence_flow sequence_elem)* ;
sequence_elem : activity | gateway | event | link ;
activity : task | subprocess ;
task : SQRE_OPEN task_type id
(VERT_LINE (input_set)? (output_set)?)? /* input/output sets */
(VERT_LINE attr_list)? /* attributes for activity */
(VERT_LINE boundary_event)* /* associated boundary events */
SQRE_CLOSE ;
task_type : USER | SERVICE | SCRIPT ;
event : PAREN_OPEN event_type id (VERT_LINE attr_list)? PAREN_CLOSE ;
gateway : ANGLE_OPEN (fork_diverge | condition_diverge | event_diverge | and_converge | or_converge) ANGLE_CLOSE ;
fork_diverge : FORK id (VERT_LINE attr_list)? VERT_LINE outflows ;
event_diverge : EVENT_SPLIT VERT_LINE event_links ;
condition_diverge : (OR_SPLIT | XOR_SPLIT) id (VERT_LINE attr_list)? VERT_LINE cond_outflows ;
and_converge : JOIN id (VERT_LINE attr_list)? (VERT_LINE inflows)? ;
or_converge : (XOR_JOIN | OR_JOIN) id (VERT_LINE attr_list)? (VERT_LINE inflows)? ;
inflows : IN ':' link_list ;
outflows : OUT ':' link_list ;
cond_outflows : OUT ':' cond_outflow (',' cond_outflow)* (DEFAULT ':' link)?;
cond_outflow : expression ':' link ;
为了简洁起见,我省略了大部分语法,但是您可以在此处看到完整版本:https://github.com/bspies/dotbpm/blob/dotbpm-parser/src/main/java/dot/bpm/parser/antlr/DOTBPM.g4。
当我在语法中输入以下内容时,它将失败:
/* A fork followed by a join, 4 "sequences" altogether */
process fork_join {
(> start) ==> [user t1] ==>
<fork g1 | out: #[t2], #[t3]>
[user t2] ==> #<g2>
[user t3] ==> #<g2>
<join g2> ==> (/ end)
}
在与“加入”网关:line 7:4 no viable alternative at input '<join'
的线路上失败。对其进行调试,似乎无法遵循“ stmt”规则,无法确定采用哪种替代方法。考虑到执行它的“ fork”规则工作得很好,并且在语法上采用了非常相似的路径,即通过“ gateway”规则,这令人颇为困惑。
解析树在这里:
我试图弄清楚为什么我的Antlr生成的解析器没有将输入的一部分识别为与我的一条规则(“ and_converge”规则,“网关”的一部分)匹配。我的语法看起来像:process ...
如果运行此代码: