简体   繁体   English

Antlr 间接左递归

[英]Antlr Indirect Left Recursion

I've seen this question asked multiple times, and also seen people "solve" it... but it either confused me or didn't solve my specific situation:我多次看到这个问题被问到,也看到人们“解决”了它……但它要么让我感到困惑,要么没有解决我的具体情况:

Here's approximately what's going on:大致情况如下:

block: statement*;
statement: <bunch of stuff> | expressionStatement;
expression_statement: <more stuff, for example> | method_invoke;
method_invoke: expression LEFT_PAREN <args...> RIGHT_PAREN block;
expression: <bunch of stuff> | expression_statement;

Everything inside of the expression_statement that starts with an expression uses indirect left recursion that I do not know how to fix while still being able to use those syntaxes as statements so they'll be usable in blocks(It is possible to do something like Print("hello world"); On it's own(a statement), but also do something like int c = a + b.getValue() as a part of an expression(an expression)... expression_statement中以表达式开头的所有内容都使用我不知道如何修复的间接左递归,同时仍然能够将这些语法用作语句,因此它们可以在块中使用(可以做类似Print("hello world");在它自己的(一个声明)上,但也做一些像int c = a + b.getValue()作为表达式的一部分(一个表达式)......

How would I handle it differently?我将如何以不同的方式处理它?

If you need more info please let me know and I'll try my best to provide如果您需要更多信息,请告诉我,我会尽力提供

I knew that to solve Indirect Left-Recursion I'd have to duplicate one or more of the rules... I hoped there'd be a better way to handle it then what is written online and also said here, but there isn't.我知道要解决间接左递归,我必须复制一个或多个规则......我希望有更好的方法来处理它,然后是在线写的和在这里也说的,但是没有'吨。 I ended up doing that and it worked, thank you我最终这样做了并且成功了,谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM