XCSB language grammar (using BNF)


<type>			::=	<signed_type> | <unsigned_type>

<signed_type>		::=	'byte' | 'int' | 'long' | 'float'

<unsigned_type>		::=	'char' |'ubyte' | 'uint' | 'ulong'

<ref_name>		::=	<name> | '*' <name> | '*' 'const' <name>

<var_spec>		::=	<ref_name> | <name> '[' <const_number> ']'

<var_spec_list>		::=	<var_spec> | <var_spec_list> ',' <var_spec>

<global_var_declaration> ::=	<type> <var_spec_list>

<local_var_declaration>	::=	<type> <var_spec_list>



<const_value>		::=	<number> | <name> | <const_expr>

<const_value_list>	::=	<const_value> | <const_value_list> ',' <const_value>

<const_declaration>	::=	'const' <type> <ref_name> '=' <const_value_list> |
				'const' <name> '=' <const_value>

<hwreg_declaration>	::=	'hwreg' <name> '=' <const_value>


<arg_spec>		::=	<type> <ref_name>

<arg_spec_list>		::=	<arg_spec> | <arg_spec_list> ',' <arg_spec>

<proc_spec>		::=	<name> '(' <arg_spec_list> ')' <NL> <statement_list> 

<invoke_opt>		::=	'fastcall' | 'inline'

<proc_declaration>	::=	'proc' <type> <proc_spec> 'endproc' |
				'proc' <type> '*' <proc_spec> 'endproc' |
				'proc' <proc_spec> 'endproc' |
				'proc' <invoke_opt> <type> <proc_spec> 'endproc' |
				'proc' <invoke_opt> <type> '*' <proc_spec> 'endproc' |
				'proc' <invoke_opt> <proc_spec> 'endproc'

<if_statement>		::=	'if' <cond_expr> 'then' <NL> <statement_list> <NL> 'endif' |
				'if' <cond_expr> 'then' <NL> <statement_list> <NL> 'else' <NL> <statement_list> <NL> 'endif' |
				'if' <cond_expr> 'then' <NL> <statement_list> <NL> 'else' <if_statement>


<for_statement>		::=	'for' <expr> 'while' <cond_expr> 'step' <expr> 'do' <NL> <statement_list> <NL> 'done'


<while_statement>	::=	'while' <cond_expr> 'do' <NL> <statement_list> <NL> 'done'


<return_statement>	::=	'return' | 'return' <expr>

<break_statement> 	::=	'break'

<continue_statement> 	::=	'continue'

<goto_statement> 	::=	'goto' <name>

<label_statement>	::=	<name> ':'

<actual_arg_list>	::=	<expr> | <actual_arg_list> ',' <expr>

<proc_invocation>	::=	<name> '(' <actual_arg_list> ')'

<array_dereference>	::=	<name> '[' <expr> ']'

<ref>			::=	<address_op> <name>

<dereference>		::=	<dereference_op> <expr>

<expr>			::=	<expr> <binary_op> <expr> |
				<unary_op> <expr> |
				'(' <expr> ')' |
				<proc_invocation> |
				<array_dereference> |
				<name> |
				<number> |
				<ref> |
				<dereference>

<statement>		::=	<if_statement> |
				<for_statement> |
				<while_statement> |
				<return_statement> |
				<break_statement> |
				<continue_statement> |
				<expr> |
				<local_var_declaration> |
				<goto_statement> |
				<label_statement>

<statement_list>	::=	<statement> | <statement_list> <NL> <statement>

<include_statement>	::=	'include' <string>

<primary_statement>	::=	<global_var_declaration> |
				<const_declaration> |
				<hwreg_declaration> |
				<include_statement> |
				<proc_declaration>

<primary_statement_list> ::=	<primary_statement> | <primary_statement_list> <NL> <primary_statement>


<binary_op>		::=	<add_op> |
				<sub_op> |
				<mult_op> |
				<div_op> |
				<mod_op> |
				<xor_op> |
				<or_op> |
				<and_op> |
				<shift_left_op> |
				<shift_right_op> |
				<logical_or_op> |
				<logical_and_op>

<add_op>		::=	'+'
<sub_op>		::=	'-'
<mult_op>		::=	'*'
<div_op>		::=	'/'
<mod_op>		::=	'%'
<xor_op>		::=	'^'
<or_op>			::=	'|'
<and_op>		::=	'&'
<shift_left_op>		::=	'<<'
<shift_right_op>	::=	'>>'
<logical_or_op>		::=	'||'
<logical_and_op>	::=	'&&'

<unary_op>		::=	<negate_op> |
				<not_op> |
				<logical_not_op> |
				<address_op> |
				<dereference_op>

<negate_op>		::=	'-'
<not_op>		::=	'~'
<logical_not_op>	::=	'!'
<address_op>		::=	'&'
<dereference_op>	::=	'*'


<comment>		::=	'//' <any_text> <NL>