What happens between {and} when writing BNF?

I have problems with BNF. I can’t say what is the standard way of doing things (if any), and whether there are types like char or int or something else that has already been built in.

However, my main problem is not how the BNF part in curly braces works.
Given something like:

exp    : term                           {$$ = $1;}  
| exp '+' term                   {$$ = $1 + $3;}  
| exp '-' term                   {$$ = $1 - $3;}  
;  

(It was conveniently stolen from somewhere, and for yacc / C)

What are the things in braces that actually say? I also looked at a similar thing for the happy parser generator and was also confused.

+3
source share
2 answers

BNF ( EBNF) Yacc. , BNF, ; " ", , , . EBNF (ISO 14977: 1996) "{...}" , "{...} -" ( "-", "+" - ). IETF RFC-5234, BNF '{}'.

Yacc , ( ). , "{$$ = $1;}" , "", "exp:: = term" ( BNF).

+2

- C, . $ , , yacc: $$ - , , $1 - $n .

, exp '+' term { $$ = $1 + $3; }, $1 exp, $3 - term, , , exp term .

+2

Source: https://habr.com/ru/post/1771818/


All Articles