Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grammar railroad diagram #106

Open
mingodad opened this issue Jul 18, 2021 · 0 comments
Open

Grammar railroad diagram #106

mingodad opened this issue Jul 18, 2021 · 0 comments

Comments

@mingodad
Copy link

Using the sql output of the lemon parser generator with the query shown bellow give us an EBNF understood by https://www.bottlecaps.de/rr/ui to generate railroad diagrams.

lemon -S zephir.lemon
select name || ' ::=' || group_concat(
	case when hasOr == 1 then ' (' || trim(rtxt) || ')'
	else
		case when length(rtxt) == 0 then ' /* empty */' else rtxt end
	end, '
	|')
from (
	select lhs, name, substr(txt, instr(txt, tbl.sep) + length(tbl.sep)) rtxt, (instr(txt, '|') > 0) hasOr
	from rule left join symbol on lhs=id, (select '::=' as sep) tbl
) as t
group by lhs;

We can see a railroad diagram for the grammar in parser/zephir.lemon with tokens manually added from parser/scanner.re, copy and paste the EBNF shown bellow on https://www.bottlecaps.de/rr/ui in the tab Edit Grammar then switching to the tab View Diagram.

input ::= xx_language
xx_language ::= xx_top_statement_list
xx_top_statement_list ::= xx_top_statement_list xx_top_statement
    | xx_top_statement
xx_top_statement ::= xx_namespace_def
    | xx_use_aliases
    | xx_function_def
    | xx_class_def
    | xx_interface_def
    | xx_comment
    | xx_cblock
xx_namespace_def ::= NAMESPACE IDENTIFIER DOTCOMMA
    | USE xx_use_aliases_list DOTCOMMA
xx_use_aliases ::= IDENTIFIER
    | IDENTIFIER AS IDENTIFIER
xx_function_def ::= FUNCTION IDENTIFIER PARENTHESES_OPEN PARENTHESES_CLOSE ARROW xx_method_return_type BRACKET_OPEN BRACKET_CLOSE
    | FUNCTION IDENTIFIER PARENTHESES_OPEN PARENTHESES_CLOSE ARROW xx_method_return_type DOTCOMMA
    | FUNCTION IDENTIFIER PARENTHESES_OPEN xx_parameter_list PARENTHESES_CLOSE ARROW xx_method_return_type BRACKET_OPEN BRACKET_CLOSE
    | FUNCTION IDENTIFIER PARENTHESES_OPEN xx_parameter_list PARENTHESES_CLOSE ARROW xx_method_return_type DOTCOMMA
    | FUNCTION IDENTIFIER PARENTHESES_OPEN PARENTHESES_CLOSE ARROW xx_method_return_type BRACKET_OPEN xx_statement_list BRACKET_CLOSE
    | FUNCTION IDENTIFIER PARENTHESES_OPEN xx_parameter_list PARENTHESES_CLOSE ARROW xx_method_return_type BRACKET_OPEN xx_statement_list BRACKET_CLOSE
    | FUNCTION IDENTIFIER PARENTHESES_OPEN PARENTHESES_CLOSE BRACKET_OPEN BRACKET_CLOSE
    | FUNCTION IDENTIFIER PARENTHESES_OPEN PARENTHESES_CLOSE DOTCOMMA
    | FUNCTION IDENTIFIER PARENTHESES_OPEN xx_parameter_list PARENTHESES_CLOSE BRACKET_OPEN BRACKET_CLOSE
    | FUNCTION IDENTIFIER PARENTHESES_OPEN xx_parameter_list PARENTHESES_CLOSE DOTCOMMA
    | FUNCTION IDENTIFIER PARENTHESES_OPEN PARENTHESES_CLOSE BRACKET_OPEN xx_statement_list BRACKET_CLOSE
    | FUNCTION IDENTIFIER PARENTHESES_OPEN xx_parameter_list PARENTHESES_CLOSE BRACKET_OPEN xx_statement_list BRACKET_CLOSE
xx_class_def ::= CLASS IDENTIFIER xx_class_body
    | CLASS IDENTIFIER EXTENDS IDENTIFIER xx_class_body
    | CLASS IDENTIFIER IMPLEMENTS xx_implements_list xx_class_body
    | CLASS IDENTIFIER EXTENDS IDENTIFIER IMPLEMENTS xx_implements_list xx_class_body
    | ABSTRACT CLASS IDENTIFIER xx_class_body
    | ABSTRACT CLASS IDENTIFIER EXTENDS IDENTIFIER xx_class_body
    | ABSTRACT CLASS IDENTIFIER IMPLEMENTS xx_implements_list xx_class_body
    | ABSTRACT CLASS IDENTIFIER EXTENDS IDENTIFIER IMPLEMENTS xx_implements_list xx_class_body
    | FINAL CLASS IDENTIFIER xx_class_body
    | FINAL CLASS IDENTIFIER EXTENDS IDENTIFIER xx_class_body
    | FINAL CLASS IDENTIFIER IMPLEMENTS xx_implements_list xx_class_body
    | FINAL CLASS IDENTIFIER EXTENDS IDENTIFIER IMPLEMENTS xx_implements_list xx_class_body
xx_interface_def ::= INTERFACE IDENTIFIER xx_interface_body
    | INTERFACE IDENTIFIER EXTENDS xx_implements_list xx_interface_body
xx_comment ::= COMMENT
xx_cblock ::= CBLOCK
xx_use_aliases_list ::= xx_use_aliases_list COMMA xx_use_aliases
    | xx_use_aliases
xx_method_return_type ::= VOID
    | xx_method_return_type_list
xx_parameter_list ::= xx_parameter_list COMMA xx_parameter
    | xx_parameter
xx_statement_list ::= xx_statement_list xx_statement
    | xx_statement
xx_interface_body ::= BRACKET_OPEN BRACKET_CLOSE
    | BRACKET_OPEN xx_interface_definition BRACKET_CLOSE
xx_implements_list ::= xx_implements_list COMMA xx_implements
    | xx_implements
xx_class_body ::= BRACKET_OPEN BRACKET_CLOSE
    | BRACKET_OPEN xx_class_definition BRACKET_CLOSE
xx_class_definition ::= xx_class_properties_definition
    | xx_class_consts_definition
    | xx_class_methods_definition
    | xx_class_properties_definition xx_class_methods_definition
    | xx_class_properties_definition xx_class_consts_definition
    | xx_class_consts_definition xx_class_properties_definition
    | xx_class_consts_definition xx_class_methods_definition
    | xx_class_properties_definition xx_class_consts_definition xx_class_methods_definition
    | xx_class_consts_definition xx_class_properties_definition xx_class_methods_definition
xx_implements ::= IDENTIFIER
xx_interface_definition ::= xx_class_consts_definition
    | xx_interface_methods_definition
    | xx_class_consts_definition xx_interface_methods_definition
xx_class_properties_definition ::= xx_class_properties_definition xx_class_property_definition
    | xx_class_property_definition
xx_class_consts_definition ::= xx_class_consts_definition xx_class_const_definition
    | xx_class_const_definition
xx_class_methods_definition ::= xx_class_methods_definition xx_class_method_definition
    | xx_class_method_definition
xx_interface_methods_definition ::= xx_interface_methods_definition xx_interface_method_definition
    | xx_interface_method_definition
xx_class_property_definition ::= COMMENT xx_visibility_list IDENTIFIER DOTCOMMA
    | xx_visibility_list IDENTIFIER DOTCOMMA
    | COMMENT xx_visibility_list IDENTIFIER ASSIGN xx_literal_expr DOTCOMMA
    | xx_visibility_list IDENTIFIER ASSIGN xx_literal_expr DOTCOMMA
    | COMMENT xx_visibility_list IDENTIFIER xx_class_property_shortcuts DOTCOMMA
    | xx_visibility_list IDENTIFIER xx_class_property_shortcuts DOTCOMMA
    | COMMENT xx_visibility_list IDENTIFIER ASSIGN xx_literal_expr xx_class_property_shortcuts DOTCOMMA
    | xx_visibility_list IDENTIFIER ASSIGN xx_literal_expr xx_class_property_shortcuts DOTCOMMA
xx_visibility_list ::= xx_visibility_list xx_visibility
    | xx_visibility
xx_literal_expr ::= INTEGER
    | CHAR
    | STRING
    | DOUBLE
    | NULL
    | FALSE
    | TRUE
    | IDENTIFIER DOUBLECOLON CONSTANT
    | CONSTANT
    | SBRACKET_OPEN SBRACKET_CLOSE
    | SBRACKET_OPEN xx_literal_array_list SBRACKET_CLOSE
xx_class_property_shortcuts ::= BRACKET_OPEN BRACKET_CLOSE
    | BRACKET_OPEN xx_class_property_shortcuts_list BRACKET_CLOSE
xx_class_property_shortcuts_list ::= xx_class_property_shortcuts_list COMMA xx_class_property_shortcut
    | xx_class_property_shortcut
xx_class_property_shortcut ::= IDENTIFIER
    | COMMENT IDENTIFIER
xx_class_const_definition ::= COMMENT CONST CONSTANT ASSIGN xx_literal_expr DOTCOMMA
    | CONST CONSTANT ASSIGN xx_literal_expr DOTCOMMA
    | COMMENT CONST IDENTIFIER ASSIGN xx_literal_expr DOTCOMMA
    | CONST IDENTIFIER ASSIGN xx_literal_expr DOTCOMMA
xx_class_method_definition ::= xx_visibility_list FUNCTION IDENTIFIER PARENTHESES_OPEN PARENTHESES_CLOSE BRACKET_OPEN BRACKET_CLOSE
    | xx_visibility_list FUNCTION IDENTIFIER PARENTHESES_OPEN PARENTHESES_CLOSE DOTCOMMA
    | xx_visibility_list FUNCTION IDENTIFIER PARENTHESES_OPEN xx_parameter_list PARENTHESES_CLOSE BRACKET_OPEN BRACKET_CLOSE
    | xx_visibility_list FUNCTION IDENTIFIER PARENTHESES_OPEN xx_parameter_list PARENTHESES_CLOSE DOTCOMMA
    | xx_visibility_list FUNCTION IDENTIFIER PARENTHESES_OPEN PARENTHESES_CLOSE BRACKET_OPEN xx_statement_list BRACKET_CLOSE
    | xx_visibility_list FUNCTION IDENTIFIER PARENTHESES_OPEN xx_parameter_list PARENTHESES_CLOSE BRACKET_OPEN xx_statement_list BRACKET_CLOSE
    | COMMENT xx_visibility_list FUNCTION IDENTIFIER PARENTHESES_OPEN PARENTHESES_CLOSE BRACKET_OPEN BRACKET_CLOSE
    | COMMENT xx_visibility_list FUNCTION IDENTIFIER PARENTHESES_OPEN PARENTHESES_CLOSE DOTCOMMA
    | COMMENT xx_visibility_list FUNCTION IDENTIFIER PARENTHESES_OPEN xx_parameter_list PARENTHESES_CLOSE BRACKET_OPEN BRACKET_CLOSE
    | COMMENT xx_visibility_list FUNCTION IDENTIFIER PARENTHESES_OPEN xx_parameter_list PARENTHESES_CLOSE DOTCOMMA
    | COMMENT xx_visibility_list FUNCTION IDENTIFIER PARENTHESES_OPEN PARENTHESES_CLOSE BRACKET_OPEN xx_statement_list BRACKET_CLOSE
    | COMMENT xx_visibility_list FUNCTION IDENTIFIER PARENTHESES_OPEN xx_parameter_list PARENTHESES_CLOSE BRACKET_OPEN xx_statement_list BRACKET_CLOSE
    | xx_visibility_list FUNCTION IDENTIFIER PARENTHESES_OPEN PARENTHESES_CLOSE ARROW xx_method_return_type BRACKET_OPEN BRACKET_CLOSE
    | xx_visibility_list FUNCTION IDENTIFIER PARENTHESES_OPEN PARENTHESES_CLOSE ARROW xx_method_return_type DOTCOMMA
    | xx_visibility_list FUNCTION IDENTIFIER PARENTHESES_OPEN xx_parameter_list PARENTHESES_CLOSE ARROW xx_method_return_type BRACKET_OPEN BRACKET_CLOSE
    | xx_visibility_list FUNCTION IDENTIFIER PARENTHESES_OPEN xx_parameter_list PARENTHESES_CLOSE ARROW xx_method_return_type DOTCOMMA
    | xx_visibility_list FUNCTION IDENTIFIER PARENTHESES_OPEN PARENTHESES_CLOSE ARROW xx_method_return_type BRACKET_OPEN xx_statement_list BRACKET_CLOSE
    | xx_visibility_list FUNCTION IDENTIFIER PARENTHESES_OPEN xx_parameter_list PARENTHESES_CLOSE ARROW xx_method_return_type BRACKET_OPEN xx_statement_list BRACKET_CLOSE
    | COMMENT xx_visibility_list FUNCTION IDENTIFIER PARENTHESES_OPEN PARENTHESES_CLOSE ARROW xx_method_return_type BRACKET_OPEN BRACKET_CLOSE
    | COMMENT xx_visibility_list FUNCTION IDENTIFIER PARENTHESES_OPEN PARENTHESES_CLOSE ARROW xx_method_return_type DOTCOMMA
    | COMMENT xx_visibility_list FUNCTION IDENTIFIER PARENTHESES_OPEN xx_parameter_list PARENTHESES_CLOSE ARROW xx_method_return_type BRACKET_OPEN BRACKET_CLOSE
    | COMMENT xx_visibility_list FUNCTION IDENTIFIER PARENTHESES_OPEN xx_parameter_list PARENTHESES_CLOSE ARROW xx_method_return_type DOTCOMMA
    | COMMENT xx_visibility_list FUNCTION IDENTIFIER PARENTHESES_OPEN PARENTHESES_CLOSE ARROW xx_method_return_type BRACKET_OPEN xx_statement_list BRACKET_CLOSE
    | COMMENT xx_visibility_list FUNCTION IDENTIFIER PARENTHESES_OPEN xx_parameter_list PARENTHESES_CLOSE ARROW xx_method_return_type BRACKET_OPEN xx_statement_list BRACKET_CLOSE
xx_interface_method_definition ::= xx_visibility_list FUNCTION IDENTIFIER PARENTHESES_OPEN PARENTHESES_CLOSE ARROW xx_method_return_type DOTCOMMA
    | xx_visibility_list FUNCTION IDENTIFIER PARENTHESES_OPEN xx_parameter_list PARENTHESES_CLOSE ARROW xx_method_return_type DOTCOMMA
    | COMMENT xx_visibility_list FUNCTION IDENTIFIER PARENTHESES_OPEN PARENTHESES_CLOSE ARROW xx_method_return_type DOTCOMMA
    | COMMENT xx_visibility_list FUNCTION IDENTIFIER PARENTHESES_OPEN xx_parameter_list PARENTHESES_CLOSE ARROW xx_method_return_type DOTCOMMA
    | xx_visibility_list FUNCTION IDENTIFIER PARENTHESES_OPEN PARENTHESES_CLOSE DOTCOMMA
    | xx_visibility_list FUNCTION IDENTIFIER PARENTHESES_OPEN xx_parameter_list PARENTHESES_CLOSE DOTCOMMA
    | COMMENT xx_visibility_list FUNCTION IDENTIFIER PARENTHESES_OPEN PARENTHESES_CLOSE DOTCOMMA
    | COMMENT xx_visibility_list FUNCTION IDENTIFIER PARENTHESES_OPEN xx_parameter_list PARENTHESES_CLOSE DOTCOMMA
xx_visibility ::= INTERNAL
    | PUBLIC
    | PROTECTED
    | PRIVATE
    | STATIC
    | SCOPED
    | INLINE
    | DEPRECATED
    | ABSTRACT
    | FINAL
xx_method_return_type_list ::= xx_method_return_type_list BITWISE_OR xx_method_return_type_item
    | xx_method_return_type_item
xx_method_return_type_item ::= xx_parameter_type
    | NULL
    | THIS
    | xx_parameter_type NOT
    | xx_parameter_cast
    | xx_parameter_cast_collection
xx_parameter_type ::= TYPE_INTEGER
    | TYPE_UINTEGER
    | TYPE_LONG
    | TYPE_ULONG
    | TYPE_CHAR
    | TYPE_UCHAR
    | TYPE_DOUBLE
    | TYPE_BOOL
    | TYPE_STRING
    | TYPE_ARRAY
    | TYPE_VAR
    | TYPE_CALLABLE
    | TYPE_RESOURCE
    | TYPE_OBJECT
xx_parameter_cast ::= LESS IDENTIFIER GREATER
xx_parameter_cast_collection ::= LESS IDENTIFIER SBRACKET_OPEN SBRACKET_CLOSE GREATER
xx_parameter ::= IDENTIFIER
    | BITWISE_AND IDENTIFIER
    | CONST IDENTIFIER
    | CONST BITWISE_AND IDENTIFIER
    | xx_parameter_type IDENTIFIER
    | xx_parameter_type BITWISE_AND IDENTIFIER
    | CONST xx_parameter_type IDENTIFIER
    | CONST xx_parameter_type BITWISE_AND IDENTIFIER
    | xx_parameter_type NOT IDENTIFIER
    | xx_parameter_type NOT BITWISE_AND IDENTIFIER
    | CONST xx_parameter_type NOT IDENTIFIER
    | CONST xx_parameter_type NOT BITWISE_AND IDENTIFIER
    | xx_parameter_cast IDENTIFIER
    | xx_parameter_cast BITWISE_AND IDENTIFIER
    | CONST xx_parameter_cast IDENTIFIER
    | CONST xx_parameter_cast BITWISE_AND IDENTIFIER
    | IDENTIFIER ASSIGN xx_literal_expr
    | BITWISE_AND IDENTIFIER ASSIGN xx_literal_expr
    | CONST IDENTIFIER ASSIGN xx_literal_expr
    | CONST BITWISE_AND IDENTIFIER ASSIGN xx_literal_expr
    | xx_parameter_type IDENTIFIER ASSIGN xx_literal_expr
    | xx_parameter_type BITWISE_AND IDENTIFIER ASSIGN xx_literal_expr
    | CONST xx_parameter_type IDENTIFIER ASSIGN xx_literal_expr
    | CONST xx_parameter_type BITWISE_AND IDENTIFIER ASSIGN xx_literal_expr
    | xx_parameter_type NOT IDENTIFIER ASSIGN xx_literal_expr
    | xx_parameter_type NOT BITWISE_AND IDENTIFIER ASSIGN xx_literal_expr
    | CONST xx_parameter_type NOT IDENTIFIER ASSIGN xx_literal_expr
    | CONST xx_parameter_type NOT BITWISE_AND IDENTIFIER ASSIGN xx_literal_expr
    | xx_parameter_cast IDENTIFIER ASSIGN xx_literal_expr
    | xx_parameter_cast BITWISE_AND IDENTIFIER ASSIGN xx_literal_expr
    | CONST xx_parameter_cast IDENTIFIER ASSIGN xx_literal_expr
    | CONST xx_parameter_cast BITWISE_AND IDENTIFIER ASSIGN xx_literal_expr
xx_statement ::= xx_cblock
    | xx_let_statement
    | xx_if_statement
    | xx_loop_statement
    | xx_echo_statement
    | xx_return_statement
    | xx_require_statement
    | xx_fetch_statement
    | xx_fcall_statement
    | xx_mcall_statement
    | xx_scall_statement
    | xx_unset_statement
    | xx_throw_statement
    | xx_declare_statement
    | xx_break_statement
    | xx_continue_statement
    | xx_while_statement
    | xx_do_while_statement
    | xx_try_catch_statement
    | xx_switch_statement
    | xx_for_statement
    | xx_comment
    | xx_empty_statement
xx_let_statement ::= LET xx_let_assignments DOTCOMMA
xx_if_statement ::= IF xx_eval_expr BRACKET_OPEN BRACKET_CLOSE
    | IF xx_eval_expr BRACKET_OPEN BRACKET_CLOSE xx_elseif_statements
    | IF xx_eval_expr BRACKET_OPEN BRACKET_CLOSE ELSE BRACKET_OPEN BRACKET_CLOSE
    | IF xx_eval_expr BRACKET_OPEN BRACKET_CLOSE xx_elseif_statements ELSE BRACKET_OPEN BRACKET_CLOSE
    | IF xx_eval_expr BRACKET_OPEN xx_statement_list BRACKET_CLOSE
    | IF xx_eval_expr BRACKET_OPEN xx_statement_list BRACKET_CLOSE xx_elseif_statements
    | IF xx_eval_expr BRACKET_OPEN xx_statement_list BRACKET_CLOSE ELSE BRACKET_OPEN xx_statement_list BRACKET_CLOSE
    | IF xx_eval_expr BRACKET_OPEN xx_statement_list BRACKET_CLOSE xx_elseif_statements ELSE BRACKET_OPEN xx_statement_list BRACKET_CLOSE
    | IF xx_eval_expr BRACKET_OPEN xx_statement_list BRACKET_CLOSE ELSE BRACKET_OPEN BRACKET_CLOSE
    | IF xx_eval_expr BRACKET_OPEN xx_statement_list BRACKET_CLOSE xx_elseif_statements ELSE BRACKET_OPEN BRACKET_CLOSE
    | IF xx_eval_expr BRACKET_OPEN BRACKET_CLOSE ELSE BRACKET_OPEN xx_statement_list BRACKET_CLOSE
xx_loop_statement ::= LOOP BRACKET_OPEN BRACKET_CLOSE
    | LOOP BRACKET_OPEN xx_statement_list BRACKET_CLOSE
xx_echo_statement ::= ECHO xx_echo_expressions DOTCOMMA
xx_return_statement ::= RETURN xx_common_expr DOTCOMMA
    | RETURN DOTCOMMA
xx_require_statement ::= REQUIRE xx_common_expr DOTCOMMA
xx_fetch_statement ::= xx_fetch_expr DOTCOMMA
xx_fcall_statement ::= xx_fcall_expr DOTCOMMA
xx_mcall_statement ::= xx_mcall_expr DOTCOMMA
xx_scall_statement ::= xx_scall_expr DOTCOMMA
xx_unset_statement ::= UNSET xx_common_expr DOTCOMMA
xx_throw_statement ::= THROW xx_common_expr DOTCOMMA
xx_declare_statement ::= TYPE_INTEGER xx_declare_variable_list DOTCOMMA
    | TYPE_UINTEGER xx_declare_variable_list DOTCOMMA
    | TYPE_CHAR xx_declare_variable_list DOTCOMMA
    | TYPE_UCHAR xx_declare_variable_list DOTCOMMA
    | TYPE_LONG xx_declare_variable_list DOTCOMMA
    | TYPE_ULONG xx_declare_variable_list DOTCOMMA
    | TYPE_DOUBLE xx_declare_variable_list DOTCOMMA
    | TYPE_STRING xx_declare_variable_list DOTCOMMA
    | TYPE_BOOL xx_declare_variable_list DOTCOMMA
    | TYPE_VAR xx_declare_variable_list DOTCOMMA
    | TYPE_ARRAY xx_declare_variable_list DOTCOMMA
xx_break_statement ::= BREAK DOTCOMMA
xx_continue_statement ::= CONTINUE DOTCOMMA
xx_while_statement ::= WHILE xx_eval_expr BRACKET_OPEN BRACKET_CLOSE
    | WHILE xx_eval_expr BRACKET_OPEN xx_statement_list BRACKET_CLOSE
xx_do_while_statement ::= DO BRACKET_OPEN BRACKET_CLOSE WHILE xx_eval_expr DOTCOMMA
    | DO BRACKET_OPEN xx_statement_list BRACKET_CLOSE WHILE xx_eval_expr DOTCOMMA
xx_try_catch_statement ::= TRY BRACKET_OPEN BRACKET_CLOSE
    | TRY BRACKET_OPEN xx_statement_list BRACKET_CLOSE
    | TRY BRACKET_OPEN xx_statement_list BRACKET_CLOSE xx_catch_statement_list
xx_switch_statement ::= SWITCH xx_eval_expr BRACKET_OPEN BRACKET_CLOSE
    | SWITCH xx_eval_expr BRACKET_OPEN xx_case_clauses BRACKET_CLOSE
xx_for_statement ::= FOR IDENTIFIER IN xx_common_expr BRACKET_OPEN xx_statement_list BRACKET_CLOSE
    | FOR IDENTIFIER IN xx_common_expr BRACKET_OPEN BRACKET_CLOSE
    | FOR IDENTIFIER IN REVERSE xx_common_expr BRACKET_OPEN xx_statement_list BRACKET_CLOSE
    | FOR IDENTIFIER IN REVERSE xx_common_expr BRACKET_OPEN BRACKET_CLOSE
    | FOR IDENTIFIER COMMA IDENTIFIER IN xx_common_expr BRACKET_OPEN xx_statement_list BRACKET_CLOSE
    | FOR IDENTIFIER COMMA IDENTIFIER IN xx_common_expr BRACKET_OPEN BRACKET_CLOSE
    | FOR IDENTIFIER COMMA IDENTIFIER IN REVERSE xx_common_expr BRACKET_OPEN xx_statement_list BRACKET_CLOSE
    | FOR PARENTHESES_OPEN IDENTIFIER IN xx_common_expr PARENTHESES_CLOSE BRACKET_OPEN xx_statement_list BRACKET_CLOSE
    | FOR PARENTHESES_OPEN IDENTIFIER IN xx_common_expr PARENTHESES_CLOSE BRACKET_OPEN BRACKET_CLOSE
    | FOR PARENTHESES_OPEN IDENTIFIER IN REVERSE xx_common_expr PARENTHESES_CLOSE BRACKET_OPEN xx_statement_list BRACKET_CLOSE
    | FOR PARENTHESES_OPEN IDENTIFIER COMMA IDENTIFIER IN xx_common_expr PARENTHESES_CLOSE BRACKET_OPEN xx_statement_list BRACKET_CLOSE
    | FOR PARENTHESES_OPEN IDENTIFIER COMMA IDENTIFIER IN xx_common_expr PARENTHESES_CLOSE BRACKET_OPEN BRACKET_CLOSE
    | FOR PARENTHESES_OPEN IDENTIFIER COMMA IDENTIFIER IN REVERSE xx_common_expr PARENTHESES_CLOSE BRACKET_OPEN xx_statement_list BRACKET_CLOSE
xx_empty_statement ::= DOTCOMMA
xx_eval_expr ::= xx_common_expr
xx_elseif_statements ::= xx_elseif_statements xx_elseif_statement
    | xx_elseif_statement
xx_elseif_statement ::= ELSEIF xx_eval_expr BRACKET_OPEN BRACKET_CLOSE
    | ELSEIF xx_eval_expr BRACKET_OPEN xx_statement_list BRACKET_CLOSE
xx_case_clauses ::= xx_case_clauses xx_case_clause
    | xx_case_clause
xx_case_clause ::= CASE xx_eval_expr COLON
    | CASE xx_eval_expr COLON xx_statement_list
    | DEFAULT COLON xx_statement_list
xx_catch_statement_list ::= xx_catch_statement_list xx_catch_statement
    | xx_catch_statement
xx_catch_statement ::= CATCH xx_catch_classes_list BRACKET_OPEN xx_statement_list BRACKET_CLOSE
    | CATCH xx_catch_classes_list BRACKET_OPEN BRACKET_CLOSE
    | CATCH xx_catch_classes_list COMMA IDENTIFIER BRACKET_OPEN BRACKET_CLOSE
    | CATCH xx_catch_classes_list COMMA IDENTIFIER BRACKET_OPEN xx_statement_list BRACKET_CLOSE
xx_catch_classes_list ::= xx_catch_classes_list BITWISE_OR xx_catch_class
    | xx_catch_class
xx_catch_class ::= IDENTIFIER
xx_common_expr ::= BITWISE_AND xx_common_expr
    | NOT xx_common_expr
    | BITWISE_NOT xx_common_expr
    | SUB xx_common_expr
    | PLUS xx_common_expr
    | ISSET xx_common_expr
    | REQUIRE xx_common_expr
    | CLONE xx_common_expr
    | EMPTY xx_common_expr
    | LIKELY xx_common_expr
    | UNLIKELY xx_common_expr
    | xx_common_expr EQUALS xx_common_expr
    | xx_common_expr NOTEQUALS xx_common_expr
    | xx_common_expr IDENTICAL xx_common_expr
    | xx_common_expr NOTIDENTICAL xx_common_expr
    | xx_common_expr LESS xx_common_expr
    | xx_common_expr GREATER xx_common_expr
    | xx_common_expr LESSEQUAL xx_common_expr
    | xx_common_expr GREATEREQUAL xx_common_expr
    | PARENTHESES_OPEN xx_common_expr PARENTHESES_CLOSE
    | PARENTHESES_OPEN xx_parameter_type PARENTHESES_CLOSE xx_common_expr
    | LESS IDENTIFIER GREATER xx_common_expr
    | xx_common_expr ARROW IDENTIFIER
    | xx_common_expr ARROW BRACKET_OPEN IDENTIFIER BRACKET_CLOSE
    | xx_common_expr ARROW BRACKET_OPEN STRING BRACKET_CLOSE
    | IDENTIFIER DOUBLECOLON IDENTIFIER
    | IDENTIFIER DOUBLECOLON CONSTANT
    | xx_common_expr SBRACKET_OPEN xx_common_expr SBRACKET_CLOSE
    | xx_common_expr ADD xx_common_expr
    | xx_common_expr SUB xx_common_expr
    | xx_common_expr MUL xx_common_expr
    | xx_common_expr DIV xx_common_expr
    | xx_common_expr MOD xx_common_expr
    | xx_common_expr CONCAT xx_common_expr
    | xx_common_expr AND xx_common_expr
    | xx_common_expr OR xx_common_expr
    | xx_common_expr BITWISE_OR xx_common_expr
    | xx_common_expr BITWISE_AND xx_common_expr
    | xx_common_expr BITWISE_XOR xx_common_expr
    | xx_common_expr BITWISE_SHIFTLEFT xx_common_expr
    | xx_common_expr BITWISE_SHIFTRIGHT xx_common_expr
    | xx_common_expr INSTANCEOF xx_common_expr
    | xx_common_expr INCLUSIVE_RANGE xx_common_expr
    | xx_common_expr EXCLUSIVE_RANGE xx_common_expr
    | xx_fetch_expr
    | TYPEOF xx_common_expr
    | IDENTIFIER
    | INTEGER
    | STRING
    | ISTRING
    | CHAR
    | DOUBLE
    | NULL
    | TRUE
    | FALSE
    | CONSTANT
    | SBRACKET_OPEN SBRACKET_CLOSE
    | SBRACKET_OPEN xx_array_list SBRACKET_CLOSE
    | NEW STATIC
    | NEW STATIC PARENTHESES_OPEN PARENTHESES_CLOSE
    | NEW STATIC PARENTHESES_OPEN xx_call_parameters PARENTHESES_CLOSE
    | NEW IDENTIFIER
    | NEW IDENTIFIER PARENTHESES_OPEN PARENTHESES_CLOSE
    | NEW IDENTIFIER PARENTHESES_OPEN xx_call_parameters PARENTHESES_CLOSE
    | NEW BRACKET_OPEN IDENTIFIER BRACKET_CLOSE
    | NEW BRACKET_OPEN IDENTIFIER BRACKET_CLOSE PARENTHESES_OPEN PARENTHESES_CLOSE
    | NEW BRACKET_OPEN IDENTIFIER BRACKET_CLOSE PARENTHESES_OPEN xx_call_parameters PARENTHESES_CLOSE
    | NEW xx_parameter_type PARENTHESES_OPEN xx_call_parameters PARENTHESES_CLOSE
    | xx_mcall_expr
    | xx_scall_expr
    | xx_fcall_expr
    | xx_common_expr QUESTION xx_common_expr COLON xx_common_expr
    | xx_common_expr QUESTION COLON xx_common_expr
    | FUNCTION PARENTHESES_OPEN PARENTHESES_CLOSE BRACKET_OPEN BRACKET_CLOSE
    | FUNCTION PARENTHESES_OPEN PARENTHESES_CLOSE USE PARENTHESES_OPEN xx_use_parameter_list PARENTHESES_CLOSE BRACKET_OPEN BRACKET_CLOSE
    | FUNCTION PARENTHESES_OPEN PARENTHESES_CLOSE BRACKET_OPEN xx_statement_list BRACKET_CLOSE
    | FUNCTION PARENTHESES_OPEN PARENTHESES_CLOSE USE PARENTHESES_OPEN xx_use_parameter_list PARENTHESES_CLOSE BRACKET_OPEN xx_statement_list BRACKET_CLOSE
    | FUNCTION PARENTHESES_OPEN xx_parameter_list PARENTHESES_CLOSE BRACKET_OPEN BRACKET_CLOSE
    | FUNCTION PARENTHESES_OPEN xx_parameter_list PARENTHESES_CLOSE USE PARENTHESES_OPEN xx_use_parameter_list PARENTHESES_CLOSE BRACKET_OPEN BRACKET_CLOSE
    | FUNCTION PARENTHESES_OPEN xx_parameter_list PARENTHESES_CLOSE BRACKET_OPEN xx_statement_list BRACKET_CLOSE
    | FUNCTION PARENTHESES_OPEN xx_parameter_list PARENTHESES_CLOSE USE PARENTHESES_OPEN xx_use_parameter_list PARENTHESES_CLOSE BRACKET_OPEN xx_statement_list BRACKET_CLOSE
    | IDENTIFIER DOUBLEARROW xx_common_expr
xx_let_assignments ::= xx_let_assignments COMMA xx_let_assignment
    | xx_let_assignment
xx_let_assignment ::= IDENTIFIER xx_assignment_operator xx_assign_expr
    | IDENTIFIER ARROW IDENTIFIER xx_assignment_operator xx_assign_expr
    | IDENTIFIER ARROW BRACKET_OPEN IDENTIFIER BRACKET_CLOSE xx_assignment_operator xx_assign_expr
    | IDENTIFIER ARROW BRACKET_OPEN STRING BRACKET_CLOSE xx_assignment_operator xx_assign_expr
    | IDENTIFIER ARROW IDENTIFIER SBRACKET_OPEN SBRACKET_CLOSE xx_assignment_operator xx_assign_expr
    | IDENTIFIER ARROW IDENTIFIER xx_array_offset_list xx_assignment_operator xx_assign_expr
    | IDENTIFIER ARROW IDENTIFIER xx_array_offset_list SBRACKET_OPEN SBRACKET_CLOSE xx_assignment_operator xx_assign_expr
    | IDENTIFIER DOUBLECOLON IDENTIFIER xx_assignment_operator xx_assign_expr
    | IDENTIFIER DOUBLECOLON IDENTIFIER SBRACKET_OPEN SBRACKET_CLOSE xx_assignment_operator xx_assign_expr
    | IDENTIFIER DOUBLECOLON IDENTIFIER xx_array_offset_list xx_assignment_operator xx_assign_expr
    | IDENTIFIER DOUBLECOLON IDENTIFIER xx_array_offset_list SBRACKET_OPEN SBRACKET_CLOSE xx_assignment_operator xx_assign_expr
    | IDENTIFIER SBRACKET_OPEN SBRACKET_CLOSE xx_assignment_operator xx_assign_expr
    | IDENTIFIER xx_array_offset_list xx_assignment_operator xx_assign_expr
    | IDENTIFIER xx_array_offset_list SBRACKET_OPEN SBRACKET_CLOSE xx_assignment_operator xx_assign_expr
    | IDENTIFIER ARROW IDENTIFIER INCR
    | IDENTIFIER ARROW IDENTIFIER DECR
    | IDENTIFIER INCR
    | IDENTIFIER DECR
    | BRACKET_OPEN IDENTIFIER BRACKET_CLOSE xx_assignment_operator xx_assign_expr
    | BRACKET_OPEN STRING BRACKET_CLOSE xx_assignment_operator xx_assign_expr
xx_assignment_operator ::= ASSIGN
    | ASSIGN_ADD
    | ASSIGN_SUB
    | ASSIGN_MUL
    | ASSIGN_DIV
    | ASSIGN_CONCAT
    | ASSIGN_MOD
    | ASSIGN_BITWISE_AND
    | ASSIGN_BITWISE_OR
    | ASSIGN_BITWISE_XOR
    | ASSIGN_BITWISE_SHIFTLEFT
    | ASSIGN_BITWISE_SHIFTRIGHT
xx_assign_expr ::= xx_common_expr
xx_array_offset_list ::= xx_array_offset_list xx_array_offset
    | xx_array_offset
xx_array_offset ::= SBRACKET_OPEN xx_index_expr SBRACKET_CLOSE
xx_index_expr ::= xx_common_expr
xx_echo_expressions ::= xx_echo_expressions COMMA xx_echo_expression
    | xx_echo_expression
xx_echo_expression ::= xx_common_expr
xx_mcall_expr ::= xx_common_expr ARROW IDENTIFIER PARENTHESES_OPEN xx_call_parameters PARENTHESES_CLOSE
    | xx_common_expr ARROW IDENTIFIER PARENTHESES_OPEN PARENTHESES_CLOSE
    | xx_common_expr ARROW BRACKET_OPEN IDENTIFIER BRACKET_CLOSE PARENTHESES_OPEN xx_call_parameters PARENTHESES_CLOSE
    | xx_common_expr ARROW BRACKET_OPEN IDENTIFIER BRACKET_CLOSE PARENTHESES_OPEN PARENTHESES_CLOSE
    | xx_common_expr ARROW BRACKET_OPEN STRING BRACKET_CLOSE PARENTHESES_OPEN xx_call_parameters PARENTHESES_CLOSE
    | xx_common_expr ARROW BRACKET_OPEN STRING BRACKET_CLOSE PARENTHESES_OPEN PARENTHESES_CLOSE
xx_fcall_expr ::= IDENTIFIER PARENTHESES_OPEN xx_call_parameters PARENTHESES_CLOSE
    | IDENTIFIER PARENTHESES_OPEN PARENTHESES_CLOSE
    | BRACKET_OPEN IDENTIFIER BRACKET_CLOSE PARENTHESES_OPEN xx_call_parameters PARENTHESES_CLOSE
    | BRACKET_OPEN IDENTIFIER BRACKET_CLOSE PARENTHESES_OPEN PARENTHESES_CLOSE
xx_scall_expr ::= IDENTIFIER DOUBLECOLON IDENTIFIER PARENTHESES_OPEN PARENTHESES_CLOSE
    | IDENTIFIER DOUBLECOLON IDENTIFIER PARENTHESES_OPEN xx_call_parameters PARENTHESES_CLOSE
    | STATIC DOUBLECOLON IDENTIFIER PARENTHESES_OPEN xx_call_parameters PARENTHESES_CLOSE
    | STATIC DOUBLECOLON IDENTIFIER PARENTHESES_OPEN PARENTHESES_CLOSE
    | BRACKET_OPEN IDENTIFIER BRACKET_CLOSE DOUBLECOLON IDENTIFIER PARENTHESES_OPEN PARENTHESES_CLOSE
    | BRACKET_OPEN IDENTIFIER BRACKET_CLOSE DOUBLECOLON IDENTIFIER PARENTHESES_OPEN xx_call_parameters PARENTHESES_CLOSE
    | BRACKET_OPEN IDENTIFIER BRACKET_CLOSE DOUBLECOLON BRACKET_OPEN IDENTIFIER BRACKET_CLOSE PARENTHESES_OPEN PARENTHESES_CLOSE
    | BRACKET_OPEN IDENTIFIER BRACKET_CLOSE DOUBLECOLON BRACKET_OPEN IDENTIFIER BRACKET_CLOSE PARENTHESES_OPEN xx_call_parameters PARENTHESES_CLOSE
    | IDENTIFIER DOUBLECOLON BRACKET_OPEN IDENTIFIER BRACKET_CLOSE PARENTHESES_OPEN PARENTHESES_CLOSE
    | IDENTIFIER DOUBLECOLON BRACKET_OPEN IDENTIFIER BRACKET_CLOSE PARENTHESES_OPEN xx_call_parameters PARENTHESES_CLOSE
xx_fetch_expr ::= FETCH IDENTIFIER COMMA xx_common_expr
xx_declare_variable_list ::= xx_declare_variable_list COMMA xx_declare_variable
    | xx_declare_variable
xx_declare_variable ::= IDENTIFIER
    | IDENTIFIER ASSIGN xx_common_expr
xx_array_list ::= xx_array_list COMMA xx_array_item
    | xx_array_item
xx_call_parameters ::= xx_call_parameters COMMA xx_call_parameter
    | xx_call_parameter
xx_call_parameter ::= xx_common_expr
    | IDENTIFIER COLON xx_common_expr
xx_use_parameter_list ::= xx_use_parameter_list COMMA xx_use_parameter
    | xx_use_parameter
xx_use_parameter ::= IDENTIFIER
    | BITWISE_AND IDENTIFIER
    | CONST IDENTIFIER
    | CONST BITWISE_AND IDENTIFIER
xx_array_item ::= xx_array_key COLON xx_array_value
    | xx_array_value
xx_array_key ::= xx_common_expr
xx_array_value ::= xx_common_expr
xx_literal_array_list ::= xx_literal_array_list COMMA xx_literal_array_item
    | xx_literal_array_item
xx_literal_array_item ::= xx_literal_array_key COLON xx_literal_array_value
    | xx_literal_array_value
xx_literal_array_key ::= IDENTIFIER
    | STRING
    | INTEGER
xx_literal_array_value ::= xx_literal_expr

// Tokens

NULL ::= "null"
FALSE ::= "false"
TRUE ::= "true"
NAMESPACE ::= "namespace"
USE ::= "use"
AS ::= "as"
INTERFACE ::= "interface"
CLASS ::= "class"
EXTENDS ::= "extends"
IMPLEMENTS ::= "implements"
INTERNAL ::= "internal"
PUBLIC ::= "public"
PROTECTED ::= "protected"
PRIVATE ::= "private"
STATIC ::= "static"
INLINE ::= "inline"
DEPRECATED ::= "deprecated"
FINAL ::= "final"
ABSTRACT ::= "abstract"
FUNCTION ::= "function"
FUNCTION ::= "fn"
LET ::= "let"
ECHO ::= "echo"
CONST ::= "const"
TYPE_INTEGER ::= "int"
TYPE_UINTEGER ::= "uint"
TYPE_LONG ::= "long"
TYPE_ULONG ::= "ulong"
TYPE_CHAR ::= "char"
TYPE_UCHAR ::= "uchar"
TYPE_DOUBLE ::= "double"
TYPE_DOUBLE ::= "float"
TYPE_BOOL ::= "bool"
TYPE_BOOL ::= "boolean"
TYPE_STRING ::= "string"
TYPE_ARRAY ::= "array"
TYPE_VAR ::= "var"
TYPE_OBJECT ::= "object"
TYPE_CALLABLE ::= "callable"
TYPE_RESOURCE ::= "resource"
IF ::= "if"
ELSE ::= "else"
ELSEIF ::= "elseif"
DO ::= "do"
WHILE ::= "while"
FOR ::= "for"
IN ::= "in"
NEW ::= "new"
RETURN ::= "return"
REQUIRE ::= "require"
CLONE ::= "clone"
EMPTY ::= "empty"
VOID ::= "void"
LOOP ::= "loop"
BREAK ::= "break"
CONTINUE ::= "continue"
TYPEOF ::= "typeof"
INSTANCEOF ::= "instanceof"
LIKELY ::= "likely"
UNLIKELY ::= "unlikely"
ISSET ::= "isset"
UNSET ::= "unset"
THROW ::= "throw"
FETCH ::= "fetch"
SWITCH ::= "switch"
CASE ::= "case"
DEFAULT ::= "default"
REVERSE ::= "reverse"
TRY ::= "try"
CATCH ::= "catch"
PARENTHESES_OPEN ::= "("
PARENTHESES_CLOSE ::= ")"
BRACKET_OPEN ::= "{"
BRACKET_CLOSE ::= "}"
SBRACKET_OPEN ::= "["
SBRACKET_CLOSE ::= "]"
AT ::= "@"
NOT ::= "!"
BITWISE_NOT ::= "~"
AND ::= "&&"
OR ::= "||"
BITWISE_AND ::= "&"
BITWISE_OR ::= "|"
BITWISE_XOR ::= "^"
BITWISE_SHIFTLEFT ::= "<<"
BITWISE_SHIFTRIGHT ::= ">>"
ASSIGN ::= "="
ASSIGN_ADD ::= "+="
ASSIGN_SUB ::= "-="
ASSIGN_MUL ::= "*="
ASSIGN_DIV ::= "/="
ASSIGN_MOD ::= "%="
ASSIGN_BITWISE_AND ::= "&="
ASSIGN_BITWISE_OR ::= "|="
ASSIGN_BITWISE_XOR ::= "^="
ASSIGN_BITWISE_SHIFTLEFT ::= "<<="
ASSIGN_BITWISE_SHIFTRIGHT ::= ">>="
ASSIGN_CONCAT ::= ".="
EQUALS ::= "=="
NOTEQUALS ::= "!="
NOTEQUALS ::= "<>"
IDENTICAL ::= "==="
NOTIDENTICAL ::= "!=="
LESSEQUAL ::= "<="
GREATEREQUAL ::= ">="
LESS ::= "<"
GREATER ::= ">"
ARROW ::= "->"
DOUBLEARROW ::= "=>"
DOUBLECOLON ::= "::"
DOT ::= "."
ADD ::= "+"
SUB ::= "-"
MUL ::= "*"
DIV ::= "/"
MOD ::= "%"
INCR ::= "++"
DECR ::= "--"
INCLUSIVE_RANGE ::= ".."
EXCLUSIVE_RANGE ::= "..."
COLON ::= ":"
DOTCOMMA ::= ";"
COMMA ::= ","
QUESTION ::= "?"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants