标签: antlr4cs

将 ANTLR 与 Visual Studio 2022 结合使用

我找不到任何说明如何在 Visual Studio 2022 中获得 ANTLR 支持的文档。似乎 ANTLR 扩展开发人员没有跟上对 Visual Studio API 对象模型所做的更改:ANTLR VSIX仅与 Visual 兼容Studio 2019 和ANTLR 语言支持不适用于 Visual Studio 2017 以后的任何版本。

如何使用 Visual Studio 2022 在 .NET 6.0 中使用 ANTLR 语法并构建解析器?

visual-studio antlr4 antlr4cs visual-studio-2022

7
推荐指数
0
解决办法
3325
查看次数

如何检测行的开头,或:“当前上下文中不存在名称‘getCharPositionInLine’”

我正在尝试创建一个行首标记:

lexer grammar ScriptLexer;

BOL : {getCharPositionInLine() == 0;}; // Beginning Of Line token
Run Code Online (Sandbox Code Playgroud)

但上面发出错误

The name 'getCharPositionInLine' does not exist in the current context
Run Code Online (Sandbox Code Playgroud)

当它创建此代码时:

private void BOL_action(RuleContext _localctx, int actionIndex) {
    switch (actionIndex) {
    case 0: getCharPositionInLine() == 0; break;
    }
}
Run Code Online (Sandbox Code Playgroud)

getCharPositionInLine()方法不存在...

c# antlr4 antlr4cs

6
推荐指数
1
解决办法
1711
查看次数

ANTLR4 生成的类中“找不到合适的方法来覆盖”

我定义了一个 ANTLR4 语法,其中词法分析器和解析器位于两个不同的文件中。它是一种类似于 XML 的语法。在我的解析器中,我也想定义一个可以重复使用自身用于计算目的的表达式(如“(1+1)*2”)。

parser grammar TestExpressionParser;

options { tokenVocab=TestExpressionLexer; }

compileUnit             : calculator ;

calculator              : '<' 'calculator' '>' tiers? rules?'</' 'calculator' '>' ;

// tiers
tiers                   : '<' 'tiers' '>' tier* '</' 'tiers' '>' ; 
tier                    : '<' 'tier' attrReference '>' '</' 'tier' '>' ;

// rules 
rules                   : '<' 'rules' '>' (rule) '</' 'rules' '>' ;
rule                    : '<' 'rule' '>' (calculation|reference|description)* '</' 'rule' '>' ;

calculation             : '<' 'calculation' '>' expression '</' 'calculation' '>' ; …
Run Code Online (Sandbox Code Playgroud)

c# antlr4 antlr4cs

2
推荐指数
1
解决办法
496
查看次数

标签 统计

antlr4 ×3

antlr4cs ×3

c# ×2

visual-studio ×1

visual-studio-2022 ×1