简体   繁体   中英

BNF grammar mimicking Java method declarations

How can I write a BNF grammar mimicking Java method declarations?

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? 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). And you are missing throws block and it doesn't allow arrays.

Why don't you compare with the actual BNF grammar for Java ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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