Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
stack level too deep error
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Moon Ho Hwang  
View profile  
 More options Dec 24 2010, 4:59 pm
From: Moon Ho Hwang <moonho.hw...@gmail.com>
Date: Fri, 24 Dec 2010 16:59:28 -0500
Local: Fri, Dec 24 2010 4:59 pm
Subject: [Q] stack level too deep error
Hi All,
I have a grammar file named simple_graph.tt
=========== simple_graph.tt ==================
# A grammar for defining a Graph
grammar SimpleG
  rule graph
        edge*
        {
        def MakeG(v)
                elements.map { |e| e.MakeG(v) }
        end
        }
  end

  rule edge
           edge "=>" word
        {
                def MakeG(v)
                   elements[2].MakeG(v)
                end
        }
        /
        word "=>" word
        {
                def MakeG(v)
                   elements[0].MakeG(v)
                   elements[2].MakeG(v)
                end
        }
  end

  rule word
        ([\s]* [\w]+ [\s]* / [\s]* quoted_string [\s]*)
        {
                def MakeG(v)
                        v << elements[1].text_value
                end
        }
  end

  rule quoted_string
        ( ["] ( !["] (. / [\n]) )* ["] / # double quoted
          ['] ( !['] (. / [\n]) )* [']   # single quoted
        )
  end
# include Comment
end # of grammar
================ end of simple_graph.tt ============

Here is a Ruby file consuming the above grammar file.
------------------------------------------------------------------------tes t.rb
---
require "treetop"
require "polyglot"
$:.push '.' # push the current directoy path
require "pp"

require "comment" # this one is also needs
require "simple_graph"

str = %q{
   aa  => ba
   cc  => dd

   11  => 22e32

   "P (a) " =>   'P (c ) '

   #xxx => yyy => zzz

}

puts str

p = SimpleGParser.new

v = []
node = p.parse(str)
node.MakeG(v)

puts v.size
puts v
------------------------------------------------------------- end of test.rb

If I commented out the following recursive rule of edge in simple_graph.tt file
#          edge "=>" word
#       {
#               def MakeG(v)
#                  elements[2].MakeG(v)
#               end
#       }
#       /

Above one has no stack level too deep error but I could not parse the
following form of edges.

   xxx => yyy => zzz

Any comments or suggestions will be very helpful for me at this status.

Thank you guys in advance.

--
Moon Ho Hwang
http://moonho.hwang.googlepages.com/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Clifford Heath  
View profile  
 More options Dec 24 2010, 6:03 pm
From: Clifford Heath <clifford.he...@gmail.com>
Date: Sat, 25 Dec 2010 10:03:46 +1100
Local: Fri, Dec 24 2010 6:03 pm
Subject: Re: [Q] stack level too deep error
On 25/12/2010, at 8:59 AM, Moon Ho Hwang wrote:

> I have a grammar file named simple_graph.tt
>  rule edge
>       edge "=>" word
> Above one has no stack level too deep error but I could not parse the
> following form of edges.

Your grammar is left-recursive. PEGs cannot handle left recursion
(at least, without some tweaks that Treetop doesn't have). You're
saying to Treetop "to get an edge, first get an edge".

In this case, it looks easy to refactor like this:

rule edge
   word "=>" edge
/ word
end

or

rule edge
   word ("=>" edge)*
end

I don't like the way you're embedding all your white-space
handling into "word". it might work for now, but it's not a good
pattern. I try to arrange for each invoked rule to skip trailing
whitespace, and then insert any additional skipping where
needed.

Clifford Heath.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Moon Ho Hwang  
View profile  
 More options Dec 25 2010, 10:09 am
From: Moon Ho Hwang <moonho.hw...@gmail.com>
Date: Sat, 25 Dec 2010 10:09:51 -0500
Local: Sat, Dec 25 2010 10:09 am
Subject: Re: [Q] stack level too deep error

Thanks a lot, Cliff!
Let me focus the left-recursive rule of PEG rather than handling white
spaces in this mail.
(I will try out your recommendation of white space handling later).

I changed the "edge" rule as below.
rule edge
        word ('=>' edge)*
        {
                def MakeG(v)
                   elements[0].MakeG(v)
                   elements[2].MakeG(v) if elements[2] != nil
                end
        }
  end

I expected I can get 8 vertices but I can only 4 vertices when I run
test_graph.rb.
Let me attached tt file and rb so you can take a look at them.
Thanks.

Moon

On Fri, Dec 24, 2010 at 6:03 PM, Clifford Heath

--
Moon Ho Hwang
http://moonho.hwang.googlepages.com/

  test_simple_graph.rb
< 1K Download

  comment.tt
< 1K Download

  simple_graph.tt
< 1K Download

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Clifford Heath  
View profile  
 More options Dec 25 2010, 4:45 pm
From: Clifford Heath <clifford.he...@gmail.com>
Date: Sun, 26 Dec 2010 08:45:38 +1100
Local: Sat, Dec 25 2010 4:45 pm
Subject: Re: [Q] stack level too deep error
Sorry Moon, but I'm going on vacation for a week - back on the 4th.
I hope someone else can help you.

You need to iterate through the elements - there are examples on the  
website.

Clifford Heath.

On 26/12/2010, at 2:09 AM, Moon Ho Hwang wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Moon Ho Hwang  
View profile  
 More options Dec 25 2010, 6:38 pm
From: Moon Ho Hwang <moonho.hw...@gmail.com>
Date: Sat, 25 Dec 2010 18:38:02 -0500
Local: Sat, Dec 25 2010 6:38 pm
Subject: Re: [Q] stack level too deep error
Thanks a lot, Cliff.
I will try to search some clue to solve it myself.

Have a good vacation

Moon
On Sat, Dec 25, 2010 at 4:45 PM, Clifford Heath

--
Moon Ho Hwang
http://moonho.hwang.googlepages.com/

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »