Weitere ähnliche Inhalte
Ähnlich wie Personal Perl 6 compiler (20)
Mehr von Andrew Shitov (20)
Kürzlich hochgeladen (20)
Personal Perl 6 compiler
- 4. How to speed up
your Perl 6 app
and make it
10 000 times faster
- 29.
sub_body
struct
p6grammar:
public
grammar<p6grammar>
{
argument
=
ch_p('{')[&a_sub_def_body_start]
template<typename
ScannerT>
struct
definition
{
=
expression >>
!statement_list
>>
ch_p('}');
definition(p6grammar
const&
self)
{
|
variable;
program
statement_control
=
statement_list
>>
end_p;
variable
=
for_cycle
=
array
|
conditional_block;
statement_list
|
scalar;
=
*statement;
conditional_block
scalar
=
(str_p("if")
|
str_p("unless"))
statement
=
constant [&a_condition_start]
>>
expression[&a_condition_end]
=
statement_code
>>
!
|
ch_p('$')
>>
identifier[&a_scalar] >>
code_block[&a_conditional_block_end];
statement_separator[&a_statement];
|
array_element;
code_block
statement_code
array
=
ch_p('{')
>>
statement_list
>>
=
comment
=
simple_array ch_p('}');
|
statement_control
|
global_array;
|
sub_def
for_cycle
//|
(sub_call[&a_sub_call_start]
simple_array
=
str_p("for")[&a_for_cycle_start]
>>
!statement_modifier)[&a_sub_call_end]
=
ch_p('@')
>>
(identifier
>>
>>
(range
>>
!(str_p("‐>")
>>
|
sub_call
~eps_p('['))[&a_array]; ch_p('$')
>>
identifier[&a_for_cycle_variable]))
|
expression;
[&a_for_cycle_range]
global_array
>>
comment
=
str_p("@*")
>>
(identifier
>>
for_cycle_body[&a_for_cycle_body];
=
ch_p('#')
>>
~eps_p('['))[&a_global_array];
lexeme_d[*~ch_p('n')];
range
array_element
=
ch_p('(')
>>
range_content
>>
statement_separator
=
simple_array_element ch_p(')')
=
ch_p(';');
|
global_array_element;
|
range_content;
sub_call
simple_array_element
range_content
=
(sub_name
>>
!sub_arguments)
=
(ch_p('@')
>>
=
expression
>>
str_p("..")
[&a_sub_called];
array_element_name_and_index)[&a_array_element]; [&a_range_sep]
>>
expression;
sub_name
global_array_element
expression
=
builtin_sub_name
=
(str_p("@*")
>>
=
ch_p('(')[&a_paren]
>>
|
identifier[&a_sub_name]
array_element_name_and_index) expression_content
>>
ch_p(')')[&a_paren]
[&a_sub_calling];
[&a_global_array_element];
|
expression_content;
builtin_sub_name
array_element_name_and_index
expression_content
=
str_p("say")[&a_builtin_say]
=
=
scalar
>>
*(math_op[&a_math_op]
>>
|
str_p("print")[&a_builtin_print]
identifier[assign_a(array_element_name)] expression)
|
str_p("return")
>>
ch_p('[')
>>
array_index
|
sub_call;
[&a_builtin_return];
>>
ch_p(']');
math_op
identifier
array_index
=
ch_p('+')
=
lexeme_d[+(alpha_p
|
'_')
>>
=
|
ch_p('‐')
>>
eps_p(~ch_p('>'))
*(alnum_p
|
'_')];
int_p[assign_a(array_element_index)];
|
ch_p('*')
|
ch_p('/')
sub_arguments
constant
|
ch_p('%');
=
ch_p('(')
>>
!argument_list
>>
=
real_p[&a_constant];
ch_p(')')
for_cycle_body
|
argument_list;
sub_def
=
sub_body;
=
str_p("sub")[&a_sub_def_start]
argument_list
>>
sub_name
statement_modifier
=
list_p(argument,
ch_p(',')
>>
!
=
(str_p("unless")
|
str_p("if"))
>>
[&a_argument_list_sep]);
sub_arguments[&a_sub_def_arguments_end] expression;
>>
sub_body[&a_sub_def_end];
- 57. a) Write Perl 6 programme
I’d like to have in production
b) Implement that part
of the compiler
- 58. a) Write Perl 6 programme
I’d like to have in production
b) Implement that part
of the compiler
(following STD.pm)