我想用lark为C#6生成一个解析器。你知道吗
我找到了一个C# 6 antlr grammar,但它不能与百灵鸟一起使用。你知道吗
有没有人能告诉我如何将g4语法重新格式化成我能用的东西?你知道吗
似乎expect lark和g4之间的格式有点不同。你知道吗
from lark import Lark
filename = 'grammar.bnf'
with open(filename,'r') as file:
output = file.read()
parser = Lark(output, start='compilation_unit')
grammar.bnf
包含我提到的c6语法above,起点是compilation_unit
。你知道吗
原始bnf文件摘录:
parser grammar CSharpParser;
options { tokenVocab=CSharpLexer; }
// entry point
compilation_unit
: BYTE_ORDER_MARK? extern_alias_directives? using_directives?
global_attribute_section* namespace_member_declarations? EOF
;
//B.2 Syntactic grammar
//B.2.1 Basic concepts
namespace_or_type_name
: (identifier type_argument_list? | qualified_alias_member) ('.' identifier type_argument_list?)*
;
[Rest of the file]
请注意,我删除了入口点compilation_unit
之前的所有内容:
parser grammar CSharpParser;
options { tokenVocab=CSharpLexer; }
目前没有回答
相关问题 更多 >
编程相关推荐