I'm interested in the famous The syntax of C in Backus-Naur Form and studied for a while, what confuse me is that some syntax looks wrong to me but is considered right according to the BNF.
For example, int test {}
, what's this? I think this is a ill syntax in C, but the truth is the BNF considered this a function definition:
int -> type_const -> type_spec -> decl_specs
test-> id -> direct_declarator -> declarator
'{' '}' -> compound_stat
decl_specs declarator compound_stat -> function_definition
I tried this with bison, it considered the input int test {}
is a right form, but I tried this on a C compiler, it will not compile.
So got questions:
int test {}
a right syntax or not?- If it is a right syntax, what is that mean and why compiler do not recognized it?
- If it is an ill syntax, can I say the BNF is not rigorous? And does that mean modern C compiler does not stick with this BNF?
int test {}
is syntax valid, but semantics wrong? – Colorable