I am using treetop to construct a grammar but am having problems with
what seems to be a circular dependency.
Consider the following structure:
And the sources for the files
require File.dirname(__FILE__) + "/lib/all"
require File.dirname(__FILE__) + '/A'
require File.dirname(__FILE__) + '/B'
require File.dirname(__FILE__) + '/AB'
It's very obvious that I've introduced a circular dependency.
Now when I run test.rb
I receive the following error:
compiler/grammar_compiler.rb:42:in `class_eval': uninitialized
constant A::AB (NameError)
meaning that it could not include the 'AB' grammar in the 'A' grammar
since it's after it in the 'all.rb' file.
However, this circular dependency is necessary.
Consider this pseudo-grammar where it would be applicable:
# Statement file
statement -> for_statement / switch_statement / other_statement
# ForStatement file
for_statement -> 'for (' expr ')' statement
As you can see, the for loop can contain other statements inside it.
But I cannot accomplish this unless all the rules are in the same
Can someone please point me in the right direction on how to
accomplish this if it's even possible?