2013-08-27 13:23:37 -04:00
|
|
|
Goal = translation_unit ;
|
|
|
|
|
translation_unit = interpreter_directive WS opt_import_list WS function_list WS ;
|
|
|
|
|
|
|
|
|
|
type = "\*" WS type | "void" | "int" | "float" | "double" | "char" | identifier ;
|
|
|
|
|
|
|
|
|
|
opt_import_list = import_list | ;
|
|
|
|
|
import_list = import_list WS import | import ;
|
|
|
|
|
import = "import" WS identifier WS ";" ;
|
|
|
|
|
|
|
|
|
|
interpreter_directive = "#!" WS path | ;
|
|
|
|
|
path = path path_part | path_part ;
|
|
|
|
|
path_part = forward_slash alphanumeric | back_slash alphanumeric ;
|
|
|
|
|
forward_slash = "/" ;
|
|
|
|
|
back_slash = "\\" ;
|
|
|
|
|
|
|
|
|
|
WS = "( | |
|
|
|
|
|
)+" | ;
|
|
|
|
|
|
|
|
|
|
identifier = alpha | alpha alphanumeric ;
|
|
|
|
|
|
|
|
|
|
function_list = function_list WS function | function ;
|
|
|
|
|
|
|
|
|
|
function = type WS identifier WS "\(" WS opt_typed_parameter_list WS "\)" WS code_block ;
|
|
|
|
|
|
|
|
|
|
opt_typed_parameter_list = typed_parameter_list | ;
|
2013-11-01 02:52:18 -04:00
|
|
|
typed_parameter_list = typed_parameter_list WS "," WS typed_parameter | typed_parameter ;
|
2013-08-27 13:23:37 -04:00
|
|
|
typed_parameter = type WS parameter ;
|
|
|
|
|
|
|
|
|
|
opt_parameter_list = parameter_list | ;
|
|
|
|
|
parameter_list = parameter_list WS parameter | parameter ;
|
|
|
|
|
parameter = expression ;
|
|
|
|
|
|
|
|
|
|
code_block = "{" WS statement_list WS "}" ;
|
|
|
|
|
statement_list = statement_list WS statement | statement ;
|
2013-11-01 02:52:18 -04:00
|
|
|
statement = if_statement | return_statement | expression WS ";" | boolean_expression WS ";" | assignment_statement WS ";" | declaration_statement WS ";" | code_block ;
|
2013-08-27 13:23:37 -04:00
|
|
|
function_call = scope identifier "\(" WS opt_parameter_list WS "\)" ;
|
|
|
|
|
scope = scope identifier "::" | ;
|
|
|
|
|
|
|
|
|
|
if_statement = "if" WS boolean_expression WS statement | "if" WS "\(" WS boolean_expression WS "\)" WS statement ;
|
|
|
|
|
|
|
|
|
|
boolean_expression = boolean_expression WS "\|\|" WS and_boolean_expression | and_boolean_expression ;
|
|
|
|
|
and_boolean_expression = and_boolean_expression "&&" bool_exp | bool_exp ;
|
2013-08-27 16:47:33 -04:00
|
|
|
bool_exp = "!" WS bool_exp | expression WS "==" WS expression | bool ;
|
2013-08-27 13:23:37 -04:00
|
|
|
|
|
|
|
|
return_statement = "return" WS "\(" WS expression WS "\)" WS ";" | "return" WS expression WS ";" ;
|
|
|
|
|
|
|
|
|
|
expression = expression WS "-" WS term | expression WS "\+" WS term | term ;
|
|
|
|
|
term = term WS forward_slash WS factor | term WS "\*" WS factor | factor ;
|
2013-08-27 16:47:33 -04:00
|
|
|
factor = number | identifier | function_call | bool | string ;
|
2013-08-27 13:23:37 -04:00
|
|
|
number = integer | float | double ;
|
|
|
|
|
|
2013-08-27 16:47:33 -04:00
|
|
|
assignment_statement = identifier WS "=" WS expression ;
|
2013-11-01 02:52:18 -04:00
|
|
|
declaration_statement = type WS identifier WS "=" WS expression ;
|
2013-08-27 13:23:37 -04:00
|
|
|
|
|
|
|
|
alphanumeric = alphanumeric numeric | alphanumeric alpha | numeric | alpha ;
|
2013-10-26 15:05:42 -04:00
|
|
|
hexadecimal = "0x(1|2|3|4|5|6|7|8|9|a|b|c|d|e|f)+" ;
|
2013-08-27 16:47:33 -04:00
|
|
|
sign = "\+|-" WS | ;
|
2013-10-26 15:05:42 -04:00
|
|
|
integer = sign numeric | sign hexadecimal | "null" ;
|
2013-08-27 13:23:37 -04:00
|
|
|
float = sign numeric "." numeric "f" ;
|
|
|
|
|
double = sign numeric "." numeric | sign numeric "." numeric "d" ;
|
2013-08-27 16:47:33 -04:00
|
|
|
bool = "true" | "false" | "True" | "False" ;
|
|
|
|
|
alpha = "(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|.|_)+" ;
|
|
|
|
|
numeric = "(0|1|2|3|4|5|6|7|8|9)+" ;
|
2013-10-16 01:43:18 -04:00
|
|
|
string = "\"(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|.|!|_|-| | |\\|/|\||0|1|2|3|4|5|6|7|8|9)+\"" ;
|