diff --git a/doc/tutorial_episode_7.pod b/doc/tutorial_episode_7.pod index 074545a..1087e7a 100644 --- a/doc/tutorial_episode_7.pod +++ b/doc/tutorial_episode_7.pod @@ -303,21 +303,7 @@ you understand the difference between a "rule" and a "token". Hint: a floating-point constant should produce a value of type 'Float'. -Hint: currently, the Parrot Grammar Engine (PGE), the component that "executes" -the regular expressions (your grammar rules), matches alternative subrules in -order. This means that this won't work: - - rule term { - | - | - ... - } - -because when giving the input C<42.0>, C<42> will be matched by -, and the dot and "0" will remain. Therefore, put the - alternative in rule term before . -At some point, PGE will support I, so that this issue -will disappear. +Note: in Perl 6 regexes, when matching an alternation as in a proto rule, the alternative which matches the most of the string is supposed to match. However, NQP-rx does not yet implement this. As a work-around, NQP-rx specifies that the version of a proto regex with the longest name will match. Since the part of a floating-point constant before the decimal place is the same as an integer constant, unless the token for floating-point constants has a longer name than the token for integer-constants, the latter will match and a syntax error will result. =item * @@ -344,12 +330,18 @@ difference between a C and a C. Hint: a floating-point constant should produce a value of type 'Float'. - token float_constant { +Note: in Perl 6 regexes, when matching an alternation as in a proto rule, the alternative which matches the most of the string is supposed to match. However, NQP-rx does not yet implement this. As a work-around, NQP-rx specifies that the version of a proto regex with the longest name will match. Since the part of a floating-point constant before the decimal place is the same as an integer constant, unless the token for floating-point constants has a longer name than the token for integer-constants, the latter will match and a syntax error will result. + + token term:sym { # longer to work around lack of LTM [ | \d+ '.' \d* | \d* '.' \d+ ] - {*} + } + + # with action method: + method term:sym($/) { # name worksaround lack of LTM + make PAST::Val.new(:value(+$/), :returns); } =item 2 @@ -357,43 +349,38 @@ Hint: a floating-point constant should produce a value of type 'Float'. For sake of completeness (and easy copy-paste for you), here's the list of operator declarations as I wrote them for Squaak: - rule expression is optable { ... } - - proto 'infix:or' is precedence('1') - is pasttype('unless') { ... } - proto 'infix:and' is tighter('infix:or') - is pasttype('if') { ... } - - proto 'infix:<' is tighter('infix:and') { ... } - proto 'infix:<=' is equiv('infix:<') { ... } - proto 'infix:>' is equiv('infix:<') { ... } - proto 'infix:>=' is equiv('infix:<') { ... } - proto 'infix:==' is equiv('infix:<') { ... } - proto 'infix:!=' is equiv('infix:<') { ... } + INIT { + Squaak::Grammar.O(':prec, :assoc', '%unary-negate'); + Squaak::Grammar.O(':prec, :assoc', '%unary-not'); + Squaak::Grammar.O(':prec, :assoc', '%multiplicative'); + Squaak::Grammar.O(':prec, :assoc', '%additive'); + Squaak::Grammar.O(':prec, :assoc', '%relational'); + Squaak::Grammar.O(':prec, :assoc', '%conjunction'); + Squaak::Grammar.O(':prec, :assoc', '%disjunction'); + } - proto 'infix:+' is tighter('infix:<') - is pirop('n_add') { ... } - proto 'infix:-' is equiv('infix:+') - is pirop('n_sub') { ... } + token circumfix:sym<( )> { '(' <.ws> ')' } - proto 'infix:..' is equiv('infix:+') - is pirop('n_concat') { ... } + token prefix:sym<-> { ')> } + token prefix:sym { ')> } - proto 'infix:*' is tighter('infix:+') - is pirop('n_mul') { ... } - proto 'infix:%' is equiv('infix:*') - is pirop('n_mod') { ... } - proto 'infix:/' is equiv('infix:*') - is pirop('n_div') { ... } + token infix:sym<*> { ')> } + token infix:sym<%> { ')> } + token infix:sym { ')> } - proto 'prefix:not' is tighter('infix:*') - is pirop('not') { ... } - proto 'prefix:-' is tighter('prefix:not') - is pirop('neg') { ... } + token infix:sym<+> { ')> } + token infix:sym<-> { ')> } + token infix:sym<..> { ')> } - proto 'term:' is tighter('prefix:-') - is parsed(&term) { ... } + token infix:sym«<» { ')> } + token infix:sym«<=» { ')> } + token infix:sym«>» { ')> } + token infix:sym«>=» { ')> } + token infix:sym«==» { ')> } + token infix:sym«!=» { ')> } + token infix:sym { ')> } + token infix:sym { ')> } =back