I would like to use lark to generate a parser for C# 6.
I found a C# 6 antlr grammar but it does not work out-of-the-box with lark.
Is there anybody who could tell me how to reformat the g4 grammar to something I can feed lark with?
It seems that the format between what expect lark and g4 are kinda different.
from lark import Lark
filename = 'grammar.bnf'
with open(filename,'r') as file:
output = file.read()
parser = Lark(output, start='compilation_unit')
grammar.bnf
contains the C# 6 grammar I mentioned above, with the starting point being compilation_unit
.
Excerpt from the original bnf file:
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]
Note that I removed everything before the entry point compilation_unit
:
parser grammar CSharpParser;
options { tokenVocab=CSharpLexer; }