Hi Everyone,
   I am not sure if this is the correct list to post this problem to
but I will try here first.  I am having a problem with understanding
TGE and I was hoping someone might be able to give me some help.  I am
writing a parrot version of 1964 BASIC using the compiler tools and I
have the PGE part nearly complete (there are a few things that I need
to finish though) and I was looking forward to using TGE but I have
become stuck.
   My problem is that when I get through the first two parts of the
tree, I come to a point where things come to a screeching halt because
the node (in Basic64::Grammar::statement) does not seem to be anything
at all or anything that I can identify.  I know from the parse output
that Basic64::Grammar::statement is a ResizablePMCArray (size:1) but I
am not sure how to reflect that in PIR or if that is even significant
here.  Underneath that are the linenumber and statement_type rules but
I cannot seem to access them at all.
   I apologize in advance if this is something simple but any help
would be greatly appreciated.

Sincerely,
Chris Yocum

grammar Basic64::ASTGrammar is TGE::Grammar;

transform past (ROOT) :language('PIR') {
       .local pmc past
       past = new 'PAST::Node'
       past.'init'('node'=>node, 'name'=>'anon')

       .local pmc cnode, cpast
       cnode = node["program"]
       cpast = tree.'get'('past', cnode, 'Basic64::Grammar::statements')
       past.'push'(cpast)
       .return (past)
}

transform past (Basic64::Grammar::statements) :language('PIR') {
       .local pmc result, cnode, cpast
       result = new 'PAST::Node'
       result.'init'('node' => node)

       cnode = node["statement"]
       cpast = tree.'get'('past', cnode, 'Basic64::Grammar::statement')
       result.'push'(cpast)
       .return (result)
}

transform past (Basic64::Grammar::statement) :language('PIR') {
       .local pmc result, cnode
       result = new 'PAST::Node'
       result.'init'('node'=>node)

}

Here is the output when run:
Null PMC access in isa()
current instr.: 'parrot;PAST::Node;node' pc 194 (PAST/Node.pir:175)
called from Sub 'parrot;PAST::Node;init' pc 96 (PAST/Node.pir:91)
called from Sub 'parrot;Basic64::ASTGrammar;_Basic64::Grammar::statement_past' \
pc 14733 (Basic64ASTGrammar.tg:29)
called from Sub 'parrot;TGE::Tree;_eval_cell' pc 282 (TGE/Tree.pir:175)
called from Sub 'parrot;TGE::Tree;get' pc 241 (TGE/Tree.pir:155)
called from Sub 'parrot;Basic64::ASTGrammar;_Basic64::Grammar::statements_past'\
pc 14702 (Basic64ASTGrammar.tg:21)
called from Sub 'parrot;TGE::Tree;_eval_cell' pc 282 (TGE/Tree.pir:175)
called from Sub 'parrot;TGE::Tree;get' pc 241 (TGE/Tree.pir:155)
called from Sub 'parrot;Basic64::ASTGrammar;_Basic64::Grammar::statements_past'\
pc 14702 (Basic64ASTGrammar.tg:21)
called from Sub 'parrot;TGE::Tree;_eval_cell' pc 282 (TGE/Tree.pir:175)
called from Sub 'parrot;TGE::Tree;get' pc 241 (TGE/Tree.pir:155)
called from Sub 'parrot;Basic64::ASTGrammar;_ROOT_past' pc 14655 (Basic64ASTGra\
mmar.tg:10)
called from Sub 'parrot;TGE::Tree;_eval_cell' pc 282 (TGE/Tree.pir:175)
called from Sub 'parrot;TGE::Tree;get' pc 241 (TGE/Tree.pir:155)
called from Sub 'parrot;HLLCompiler;compile' pc 343 (runtime/parrot/library/Par\
rot/HLLCompiler.pir:248)
called from Sub 'parrot;HLLCompiler;eval' pc 500 (runtime/parrot/library/Parrot\
/HLLCompiler.pir:338)
called from Sub 'parrot;HLLCompiler;evalfiles' pc 800 (runtime/parrot/library/P\
arrot/HLLCompiler.pir:472)
called from Sub 'parrot;HLLCompiler;command_line' pc 947 (runtime/parrot/librar\
y/Parrot/HLLCompiler.pir:535)
called from Sub 'parrot;Basic64;main' pc 67 (Basic64Main.pir:24)


Here is the parse output for reference:

"parse" => PMC 'Basic64::Grammar' => "10 let foo = 5;" @ 0 {
   <program> => PMC 'Basic64::Grammar' => "10 let foo = 5;" @ 0 {
       <statements> => PMC 'Basic64::Grammar' => "10 let foo = 5;" @ 0 {
           <statement> => ResizablePMCArray (size:1) [
               PMC 'Basic64::Grammar' => "10 let foo = 5" @ 0 {
                   <linenumber> => PMC 'Basic64::Grammar' => "10" @ 0 {
                       <digit> => ResizablePMCArray (size:2) [
                           PMC 'Basic64::Grammar' => "1" @ 0,
                           PMC 'Basic64::Grammar' => "0" @ 1
                       ]
                   }
                   <statement_type> => PMC 'Basic64::Grammar' => "let foo = 5"\
@ 3 {
                       <let_statement> => PMC 'Basic64::Grammar' => "let foo =\
5" @ 3 {
                           <expr> => PMC 'Basic64::Grammar' => "foo = 5" @ 7 {
                               <expr> => PMC 'PGE::Match' => "=" @ 11 {
                                   <type> => "infix:="
                                   [0] => PMC 'Basic64::Grammar' => "foo" @ 7 \
{
                                       <indent> => PMC 'Basic64::Grammar' => "\
foo" @ 7
                                       <type> => "term:"
                                  }
                                   [1] => PMC 'Basic64::Grammar' => "5" @ 13 {
                                       <integer> => PMC 'Basic64::Grammar' => \
"5" @ 13
                                       <type> => "term:"
                                   }
                               }
                           }
                       }
                   }
               }
           ]
       }
   }
}

Reply via email to