[grammarians] ambiguity with method call?

daz rubygrammar at d10.karoo.co.uk
Tue Nov 29 19:20:07 EST 2005


From: mental
>
> The discriminator is whether foo is determined to be a local
> variable or a method.
>

... and <space seen> matters (for a method call)


daz


============================= meth no spc
def foo
  [a,b]
end

foo[1]      # sees foo.[](1)
-----------------------------------------

NODE_BLOCK:
  NODE_NEWLINE:  [rb8233.TMP:1]
    NODE_DEFN:  method 9713 (foo)
      NODE_SCOPE:
        NODE_BLOCK:
          NODE_ARGS:  count = 0
            additional default values:
          NODE_NEWLINE:  [rb8233.TMP:2]
            NODE_ARRAY:  size = 2
              NODE_VCALL:  self.a
              NODE_VCALL:  self.b
  NODE_NEWLINE:  [rb8233.TMP:5]
    NODE_CALL:  to method: 331 ([])   <--  CALL
    Receiver:
      NODE_VCALL:  self.foo           <-- VCALL
      Parameters:
        NODE_ARRAY:  size = 1
          NODE_LIT:  Fixnum: 1

================================ meth spc
def foo
  [a,b]
end

foo [1]      # sees foo([1])
-----------------------------------------

NODE_BLOCK:
  NODE_NEWLINE:  [rb8233.TMP:1]
    NODE_DEFN:  method 9713 (foo)
      NODE_SCOPE:
        NODE_BLOCK:
          NODE_ARGS:  count = 0
            additional default values:
          NODE_NEWLINE:  [rb8233.TMP:2]
            NODE_ARRAY:  size = 2
              NODE_VCALL:  self.a
              NODE_VCALL:  self.b
  NODE_NEWLINE:  [rb8233.TMP:5]
    NODE_FCALL:  to function: 9713 (foo)   <-- FCALL
      Parameters:
        NODE_ARRAY:  size = 1              <-- []
          NODE_ARRAY:  size = 1            <-- [[]]
            NODE_LIT:  Fixnum: 1           <-- [[1]]







============================== var no spc
foo = [a,b]
foo[1]
-----------------------------------------

NODE_BLOCK:
  NODE_NEWLINE:  [rb8233.TMP:1]
    NODE_LASGN:
      NODE_ARRAY:  size = 2
        NODE_VCALL:  self.a
        NODE_VCALL:  self.b
      Assign to LV 2 (foo)
  NODE_NEWLINE:  [rb8233.TMP:2]
    NODE_CALL:  to method: 331 ([])   <--
    Receiver:
      NODE_LVAR:  LV 2 (foo)
      Parameters:
        NODE_ARRAY:  size = 1
          NODE_LIT:  Fixnum: 1

================================= var spc
foo = [a,b]
foo [1]
-----------------------------------------

NODE_BLOCK:
  NODE_NEWLINE:  [rb8233.TMP:1]
    NODE_LASGN:
      NODE_ARRAY:  size = 2
        NODE_VCALL:  self.a
        NODE_VCALL:  self.b
      Assign to LV 2 (foo)
  NODE_NEWLINE:  [rb8233.TMP:2]
    NODE_CALL:  to method: 331 ([])   <--
    Receiver:
      NODE_LVAR:  LV 2 (foo)
      Parameters:
        NODE_ARRAY:  size = 1
          NODE_LIT:  Fixnum: 1



ruby 1.8.0 (2003-08-30) [i586-bccwin32]
http://www.ruby-lang.org/cgi-bin/cvsweb.cgi/rough/ext/nodedump/








More information about the Rubygrammar-grammarians mailing list