develooper Front page | perl.cvs.parrot | Postings from December 2008

[svn:parrot] r33837 - trunk/languages/ecmascript/src/parser

From:
tewk
Date:
December 12, 2008 08:31
Subject:
[svn:parrot] r33837 - trunk/languages/ecmascript/src/parser
Message ID:
20081212163117.6E21ACB9AF@x12.develooper.com
Author: tewk
Date: Fri Dec 12 08:31:16 2008
New Revision: 33837

Modified:
   trunk/languages/ecmascript/src/parser/actions.pm
   trunk/languages/ecmascript/src/parser/grammar.pg

Log:
[js] fixes for member_expression and optable assignment ops


Modified: trunk/languages/ecmascript/src/parser/actions.pm
==============================================================================
--- trunk/languages/ecmascript/src/parser/actions.pm	(original)
+++ trunk/languages/ecmascript/src/parser/actions.pm	Fri Dec 12 08:31:16 2008
@@ -430,7 +430,7 @@
     make $( $/{$key} );
 }
 
-method assignment_expression($/) {
+method assignment_expression_X($/) {
     my $past := $( $<conditional_expression> );
 
     ## get number of lhs_expressions
@@ -547,7 +547,7 @@
 }
 
 method member_expression($/) {
-    my $member := $( $<member> );
+    my $member := $( $<member_prefix> );
 
     ## if there are any arguments, $member is invoked with these arguments.
     if $<arguments> {
@@ -563,14 +563,14 @@
     }
 }
 
-method member($/) {
+method member_expression($/) {
     my $past := $( $<member_prefix> );
 
     ## for each index, $past acts as the invocant or main object on
     ## which some operation is executed; therefore $past must be the
     ## first child, so unshift it. Then, $past is assigned this result
     ## preparing for either the next index or as argument for 'make'.
-    for $<index> {
+    for $<member_suffix> {
         my $idx := $( $_ );
         $idx.unshift($past);
         $past := $idx;
@@ -583,7 +583,7 @@
     make $( $/{$key} );
 }
 
-method index($/, $key) {
+method member_suffix($/, $key) {
     ## get the index expression
     my $idx := $( $/{$key} );
 
@@ -737,7 +737,8 @@
     make $( $/{$key} );
 }
 
-method logical_or_expression($/, $key) {
+#method logical_or_expression($/, $key) {
+method assignment_expression($/, $key) {
     ## Handle the operator table
     ##
     if ($key eq 'end') {

Modified: trunk/languages/ecmascript/src/parser/grammar.pg
==============================================================================
--- trunk/languages/ecmascript/src/parser/grammar.pg	(original)
+++ trunk/languages/ecmascript/src/parser/grammar.pg	Fri Dec 12 08:31:16 2008
@@ -59,9 +59,9 @@
     | <while_statement> {*}       #= while_statement
     | <do_while_statement> {*}    #= do_while_statement
     | <for1_statement> {*}        #= for1_statement
-    #| <for2_statement> {*}        #= for2_statement
-    #| <for3_statement> {*}        #= for3_statement
-    #| <for4_statement> {*}        #= for4_statement
+    | <for2_statement> {*}        #= for2_statement
+    | <for3_statement> {*}        #= for3_statement
+    | <for4_statement> {*}        #= for4_statement
     | <continue_statement> {*}    #= continue_statement
     | <break_statement> {*}       #= break_statement
     | <return_statement> {*}      #= return_statement
@@ -171,6 +171,11 @@
     {*}
 }
 
+rule variable_declaration_list {
+    <variable_declaration> [',' <variable_declaration>]*
+    {*}
+}
+
 rule variable_declaration {
     <identifier> ['=' <assignment_expression>]?
     {*}
@@ -187,7 +192,7 @@
 }
 
 token return_statement {
-    'return' \N <expression>?  ';'
+    'return' [\N <expression>]?  ';'
     {*}
 }
 
@@ -426,25 +431,40 @@
     {*}
 }
 
-rule assignment_expression {
-    [<lhs_expression> <assignop>]* <conditional_expression>
-    {*}
-}
+#rule assignment_expression {
+#   [<lhs_expression> <assignop>]* <conditional_expression>
+#    {*}
+#}
 
-token assignop {
-    $<op>=['='|'*='|'/='|'%='|'+='|'-='|'<<='|'>>='|'>>>='|'&='|'^='|'|=']
-}
+#token assignop {
+#    $<op>=['='|'*='|'/='|'%='|'+='|'-='|'<<='|'>>='|'>>>='|'&='|'^='|'|=']
+#}
 
-rule conditional_expression {
-    <logical_or_expression>
-    ['?' $<then>=<assignment_expression>
-     ':' $<else>=<assignment_expression>]?
-    {*}
-}
+#rule conditional_expression {
+#    <logical_or_expression>
+#    ['?' $<then>=<assignment_expression>
+#     ':' $<else>=<assignment_expression>]?
+#    {*}
+#}
 
-rule 'logical_or_expression' is optable { ... }
+rule 'assignment_expression' is optable { ... }
 
-proto 'infix:||'  is precedence('1') is pasttype('unless') { ... }
+proto 'infix:=' is precedence('1') is pasttype('copy') is lvalue(1)     { ... }
+
+proto 'infix:+=' is equiv('infix:=') { ... } 
+proto 'infix:-=' is equiv('infix:=') { ... } 
+proto 'infix:/=' is equiv('infix:=') is pirop('div')        { ... } 
+proto 'infix:*=' is equiv('infix:=') is pirop('mul')        { ... } 
+proto 'infix:%=' is equiv('infix:=') is pirop('mul')        { ... } 
+proto 'infix:|=' is equiv('infix:=')    { ... } 
+proto 'infix:&=' is equiv('infix:=')    { ... } 
+proto 'infix:~=' is equiv('infix:=')    { ... } 
+proto infix:«>>=» is equiv('infix:=') is pirop('rsh')       { ... } 
+proto infix:«<<=» is equiv('infix:=') is pirop('lsh')       { ... } 
+proto infix:«>>>=» is equiv('infix:=') is pirop('rsh')       { ... } 
+proto 'ternary:? :' is tighter('infix:=') is pirop('if')      { ... } 
+
+proto 'infix:||'  is tighter('ternary:? :') is pasttype('unless') { ... }
 
 proto 'infix:&&'  is tighter('infix:||') is pasttype('if') { ... }
 
@@ -454,23 +474,23 @@
 
 proto 'infix:&'   is tighter('infix:^')  { ... }
 
-proto 'infix:=='  is tighter('infix:&')  { ... }
-proto 'infix:!='  is equiv('infix:==')   { ... }
-proto 'infix:===' is equiv('infix:==')   { ... }
-proto 'infix:!==' is equiv('infix:==')   { ... }
-
-proto 'infix:<'   is tighter('infix:==') { ... }
-proto 'infix:>'   is equiv('infix:<')    { ... }
-proto 'infix:<='  is equiv('infix:<')    { ... }
-proto 'infix:>='  is equiv('infix:<')    { ... }
-proto 'infix:instanceof' is equiv('infix:<') { ... }
-proto 'infix:in'  is equiv('infix:<')    { ... }
-
-proto 'infix:<<'  is tighter('infix:<')  { ... }
-proto 'infix:>>'  is equiv('infix:<<')   { ... }
-proto 'infix:>>>' is equiv('infix:<<')   { ... }
+proto 'infix:!='  is tighter('infix:&')  { ... }
+proto 'infix:=='  is equiv('infix:!=')   { ... }
+proto 'infix:===' is equiv('infix:!=')   { ... }
+proto 'infix:!==' is equiv('infix:!=')   { ... }
+
+proto infix:«<»   is tighter('infix:!=') { ... }
+proto infix:«>»   is equiv(infix:«<»)    { ... }
+proto infix:«<=»  is equiv(infix:«<»)    { ... }
+proto infix:«>=»  is equiv(infix:«<»)    { ... }
+proto 'infix:instanceof' is equiv(infix:«<») { ... }
+proto 'infix:in'  is equiv(infix:«<»)    { ... }
+
+proto infix:«<<»  is tighter(infix:«<»)  { ... }
+proto infix:«>>»  is equiv(infix:«<<»)   { ... }
+proto infix:«>>>» is equiv(infix:«<<»)   { ... }
 
-proto 'infix:+' is tighter('infix:<<') is pirop('add') { ... }
+proto 'infix:+' is tighter(infix:«<<») is pirop('add') { ... }
 proto 'infix:-' is equiv('infix:+')    is pirop('sub') { ... }
 
 proto 'infix:*' is tighter('infix:+')  is pirop('mul') { ... }
@@ -500,18 +520,20 @@
 }
 
 rule new_expression {
-    [$<sym>='new']* <member_expression>
+    [$<sym>='new']* <member_expression> <arguments>?
     {*}
 }
 
 rule member_expression {
-    [ 'new' <member> <arguments>
-    | <member>
-    ]
-    {*}
+    <member_prefix> <member_suffix>* {*}
 }
 
-rule index {
+rule member_prefix {
+    | <primary_expression> {*}      #= primary_expression
+    | <function_expression> {*}     #= function_expression
+}
+
+rule member_suffix {
     | '[' <expression> ']' {*} #= expression
     | <identifier_field> {*}   #= identifier_field
 }
@@ -520,24 +542,14 @@
     '.' <identifier> {*}
 }
 
-rule member {
-    <member_prefix> <index>*
-    {*}
-}
-
-rule member_prefix {
-    | <primary_expression> {*}      #= primary_expression
-    | <function_expression> {*}     #= function_expression
-}
-
 rule call_expression {
     <member_expression> <arguments> <post_call_expr>*
     {*}
 }
 
 rule post_call_expr {
-    | <arguments> {*}   #= arguments
-    | <index> {*}       #= index
+    | <arguments>     {*}   #= arguments
+    | <member_suffix> {*}   #= member_suffix
 }
 
 



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About