Next revision | Previous revision |
buzz_syntax_bnf [2016/04/10 00:14] – created ilpincy | buzz_syntax_bnf [2018/07/17 18:59] (current) – ilpincy |
---|
====== Buzz Syntax BNF Specification ====== | ====== Buzz Syntax BNF Specification ====== |
| |
| For an example-driven explanation of the Buzz syntax, see the [[buzz_syntax_cheatsheet|syntax cheatsheet]]. In what follows, we report a formal [[https://en.wikipedia.org/wiki/Backus%E2%80%93Naur_Form|Backus-Naur Form grammar]] specification. |
===== Tokens ===== | ===== Tokens ===== |
| |
The recognized tokens are: | The recognized tokens are: |
| |
^ Token ^ Id ^ | ^ Token ^ Id ^ |
| //identifier// | ''TOKID'' | | | //identifier// | ''TOKID'' | |
| //numeric constant// | ''TOKCONST'' | | | //numeric constant// | ''TOKCONST'' | |
| '''''_string_''''' ''"''_string_''"'' | ''TOKSTRING'' | | | '''''_string_''''' ''"''_string_''"'' | ''TOKSTRING'' | |
| ''var'' | ''TOKVAR'' | | | ''var'' | ''TOKVAR'' | |
| ''nil'' | ''TOKNIL'' | | | ''nil'' | ''TOKNIL'' | |
| ''if'' | ''TOKIF'' | | | ''if'' | ''TOKIF'' | |
| ''else'' | ''TOKELSE'' | | | ''else'' | ''TOKELSE'' | |
| ''function'' | ''TOKFUN'' | | | ''function'' | ''TOKFUN'' | |
| ''return'' | ''TOKRETURN'' | | | ''return'' | ''TOKRETURN'' | |
| ''for'' | ''TOKFOR'' | | | ''for'' | ''TOKFOR'' | |
| ''while'' | ''TOKWHILE'' | | | ''while'' | ''TOKWHILE'' | |
| ''and'', ''or'' | ''TOKANDOR'' | | | ''and'', ''or'' | ''TOKLANDOR'' | |
| ''not'' | ''TOKNOT'' | | | ''not'' | ''TOKLNOT'' | |
| ''+'', ''-'' | ''TOKADDSUB'' | | | ''+'', ''-'' | ''TOKADDSUB'' | |
| ''*'', ''/'' | ''TOKMULDIV'' | | | ''*'', ''/'' | ''TOKMULDIV'' | |
| ''%'' | ''TOKMOD'' | | | ''%'' | ''TOKMOD'' | |
| ''^'' | ''TOKPOW'' | | | ''^'' | ''TOKPOW'' | |
| ''{'' | ''TOKBLOCKOPEN'' | | | ''<<'' ''>>'' | ''TOKLRSHIFT'' | |
| ''}'' | ''TOKBLOCKCLOSE'' | | | ''&'' ''|'' | ''TOKBANDOR'' | |
| ''('' | ''TOKPAROPEN'' | | | ''!'' | ''TOKBNOT'' | |
| '')'' | ''TOKPARCLOSE'' | | | ''{'' | ''TOKBLOCKOPEN'' | |
| ''['' | ''TOKIDXOPEN'' | | | ''}'' | ''TOKBLOCKCLOSE'' | |
| '']'' | ''TOKIDXCLOSE'' | | | ''('' | ''TOKPAROPEN'' | |
| '';'' ''\n'' | ''TOKSTATEND'' | | | '')'' | ''TOKPARCLOSE'' | |
| '','' | ''TOKLISTSEP'' | | | ''['' | ''TOKIDXOPEN'' | |
| ''='' | ''TOKASSIGN'' | | | '']'' | ''TOKIDXCLOSE'' | |
| ''.'' | ''TOKDOT'' | | | '';'' ''\n'' | ''TOKSTATEND'' | |
| ''<'' ''<='' ''>'' ''>='' ''=='' ''!='' | ''TOKCMP'' | | | '','' | ''TOKLISTSEP'' | |
| | ''='' | ''TOKASSIGN'' | |
| | ''.'' | ''TOKDOT'' | |
| | ''<'' ''<='' ''>'' ''>='' ''=='' ''!='' | ''TOKCMP'' | |
| |
===== Grammar ===== | ===== Grammar ===== |
| |
conditionlist ::= condition | conditionlist TOKLISTSEP condition | conditionlist ::= condition | conditionlist TOKLISTSEP condition |
condition ::= comparison | condition TOKANDOR comparison | condition ::= comparison | condition TOKLANDOR comparison | TOKLNOT condition |
comparison ::= TOKPAROPEN condition TOKPARCLOSE | NOT comparison | expression | expression TOKCMP expression | comparison ::= expression | expression TOKCMP expression |
| |
expression ::= product | expression TOKADDSUB product | expression ::= product | expression TOKADDSUB product |
product ::= modulo | product TOKMULDIV modulo | product ::= modulo | product TOKMULDIV modulo |
modulo ::= power | modulo TOKMOD power | modulo ::= power | modulo TOKMOD power |
power ::= operand powerrest | power ::= bitshift powerrest |
powerrest ::= <nil> | TOKPOW power | powerrest ::= <nil> | TOKPOW power |
operand ::= TOKNIL | TOKCONST | TOKSTRING | TOKPAROPEN expression TOKPARCLOSE | TOKADDSUB power | idref | lambda | tabledef | bitshift ::= bitwiseandor | operand TOKLRSHIFT bitwiseandor |
| bitwiseandor ::= bitwisenot | bitwiseandor TOKBANDOR bitwisenot |
| bitwisenot ::= operand | TOKBNOT bitwisenot |
| operand ::= TOKNIL | TOKCONST | TOKSTRING | TOKPAROPEN condition TOKPARCLOSE | TOKADDSUB power | idref | lambda | tabledef |
| |
command ::= idref | idref assignment | TOKRETURN expression | command ::= idref | idref assignment | TOKRETURN expression |