简体   繁体   English

模仿Java方法声明的BNF语法

[英]BNF grammar mimicking Java method declarations

How can I write a BNF grammar mimicking Java method declarations? 如何编写模仿Java方法声明的BNF语法?

Here's what I have: 这是我所拥有的:

<call> ::= <return-type> <method-identifier>(<parameter-list>);
<return-type> ::= void | <type>
<type> ::= byte | short | int | long | float | double | boolean | char
<parameter-list> ::= <parameter> | <parameter>,<parameter-list>
<parameter> ::= <type> <parameter-identifier>

Do I have the right idea? 我有正确的主意吗? Is this the correct form for BNF? 这是BNF的正确形式吗? This won't be implemented for anything, I'm just trying to wrap my head around the idea. 这什么都不会实现,我只是想把想法包扎起来。

I think you are going in a good direction. 我认为您的方向不错。 However, type doesn't allow class names (in Java you can pass objects as parameters). 但是, type不允许类名(在Java中,您可以将对象作为参数传递)。 And you are missing throws block and it doesn't allow arrays. 而且您缺少throws块,并且不允许使用数组。

Why don't you compare with the actual BNF grammar for Java ? 为什么不将其与Java的实际BNF语法进行比较?

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

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