Both sides previous revision Previous revision Next revision | Previous revision |
buzz_syntax_bnf_specification [2016/04/08 15:20] – root | buzz_syntax_bnf_specification [2016/04/10 00:15] (current) – removed ilpincy |
---|
====== Buzz Syntax BNF Specification ====== | |
| |
===== Tokens ===== | |
| |
An **identifier** in Buzz is defined by this regular expression: | |
| |
[[:alpha:]_][[:alnum:]_]* | |
| |
The recognized tokens are: | |
| |
^ Token ^ Id ^ | |
| //identifier// | ''TOKID'' | | |
| //numeric constant// | ''TOKCONST'' | | |
| '''''_string_''''' ''"''_string_''"'' | ''TOKSTRING'' | | |
| ''var'' | ''TOKVAR'' | | |
| ''nil'' | ''TOKNIL'' | | |
| ''if'' | ''TOKIF'' | | |
| ''else'' | ''TOKELSE'' | | |
| ''function'' | ''TOKFUN'' | | |
| ''return'' | ''TOKRETURN'' | | |
| ''for'' | ''TOKFOR'' | | |
| ''while'' | ''TOKWHILE'' | | |
| ''and'', ''or'' | ''TOKANDOR'' | | |
| ''not'' | ''TOKNOT'' | | |
| ''+'', ''-'' | ''TOKADDSUB'' | | |
| ''*'', ''/'' | ''TOKMULDIV'' | | |
| ''%'' | ''TOKMOD'' | | |
| ''^'' | ''TOKPOW'' | | |
| ''{'' | ''TOKBLOCKOPEN'' | | |
| ''}'' | ''TOKBLOCKCLOSE'' | | |
| ''('' | ''TOKPAROPEN'' | | |
| '')'' | ''TOKPARCLOSE'' | | |
| ''['' | ''TOKIDXOPEN'' | | |
| '']'' | ''TOKIDXCLOSE'' | | |
| '';'' ''\n'' | ''TOKSTATEND'' | | |
| '','' | ''TOKLISTSEP'' | | |
| ''='' | ''TOKASSIGN'' | | |
| ''.'' | ''TOKDOT'' | | |
| ''<'' ''<='' ''>'' ''>='' ''=='' ''!='' | ''TOKCMP'' | | |
| |
===== Grammar ===== | |
| |
script ::= statlist | |
| |
statlist ::= stat | statlist stat | |
stat ::= <nil> | vardef | fundef | if | loop | command | |
| |
block ::= TOKBLOCKOPEN statlist TOKBLOCKCLOSE | |
| |
vardef ::= TOKVAR TOKID | TOKVAR TOKID assignment | |
fundef ::= TOKFUN TOKID TOKPAROPEN idlist TOKPARCLOSE block | |
if ::= TOKIF TOKPAROPEN condition TOKPARCLOSE block endif | |
endif ::= <nil> | TOKELSE block | |
loop ::= forloop | whileloop | |
forloop ::= TOKFOR TOKPAROPEN idref TOKASSIGN expression TOKLISTSEP condition TOKLISTSEP idref TOKASSIGN expression TOKPARCLOSE block | |
whileloop ::= TOKWHILE TOKPAROPEN condition TOKPARCLOSE block | |
| |
conditionlist ::= condition | conditionlist TOKLISTSEP condition | |
condition ::= comparison | condition TOKANDOR comparison | |
comparison ::= TOKPAROPEN condition TOKPARCLOSE | NOT comparison | expression | expression TOKCMP expression | |
| |
expression ::= product | expression TOKADDSUB product | |
product ::= modulo | product TOKMULDIV modulo | |
modulo ::= power | modulo TOKMOD power | |
power ::= operand powerrest | |
powerrest ::= <nil> | TOKPOW power | |
operand ::= TOKNIL | tabledef | TOKCONST | TOKSTRING | TOKPAROPEN expression TOKPARCLOSE | TOKADDSUB power | idref | lambda | |
| |
command ::= idref | idref assignment | TOKRETURN expression | |
assignment ::= TOKASSIGN expression | |
| |
tabledef ::= TOKBLOCKOPEN TOKBLOCKCLOSE | TOKBLOCKOPEN tablefielddeflist TOKBLOCKCLOSE | |
tablefielddef ::= TOKDOT idref assignment | TOKDOT TOKCONST assignment | |
tablefielddeflist ::= tablefielddef | tablefielddeflist TOKLISTSEP tablefielddef | |
| |
idlist ::= <nil> | TOKID | idlist TOKLISTSEP TOKID | |
idreflist ::= idref | idreflist TOKLISTSEP idref | |
idref ::= TOKID | idref TOKDOT TOKID | idref TOKIDXOPEN expression TOKIDXCLOSE | idref TOKPAROPEN conditionlist TOKPARCLOSE | |
| |
lambda ::= TOKFUN TOKPAROPEN idlist TOKPARCLOSE block | |