Hi

I am currently working on a language translation. So, I have created a
template and the tree grammar. But, the template is not executing. It
is giving a Null Pointer Exception. I have the following grammars:
m.g is the main input grammar from which tree grammar g.g and finally,
I'm creating template t.g as the output.

My Java entry program:

import java.io.*;
import org.antlr.runtime.*;
import org.antlr.runtime.tree.*;
import org.antlr.stringtemplate.*;

public class Main {
   public static StringTemplateGroup templates;
   public static void main(String[] args) throws Exception {

               //Read the template file
               String stg = null;
               int a = 0;
               if ( args.length<=1 )
               {
                       stg = "sal_prog_template.stg";
               }
               else
               {
                       stg = args[a];
                       a++;
               }
               templates = new StringTemplateGroup(new FileReader(stg));

               //Parse input and build AST
               ANTLRInputStream input = new ANTLRInputStream(System.in);
               mLexer lexer = new mLexer(input);
               CommonTokenStream tokens = new CommonTokenStream(lexer);
               mParser parser = new mParser(tokens);
               mParser.program_return r1 = parser.program();
               CommonTree tree1 = (CommonTree)r1.getTree();
               if (r1 != null)
                 System.out.println(tree1.toStringTree());

               //Build the tree grammar g
               CommonTreeNodeStream nodes = new CommonTreeNodeStream(tree1);
               nodes.setTokenStream(tokens);
               g grammar = new g(nodes);
               g.program_return r2 = grammar.program();
               CommonTree tree2 = (CommonTree)r2.getTree();
               if (r2 != null)
                 System.out.println(tree2.toStringTree());

               //Build the template
               CommonTreeNodeStream nodes2 = new CommonTreeNodeStream(tree2);
               nodes2.setTokenStream(tokens);
               t grammar2 = new t(nodes2);
               grammar2.setTemplateLib(templates);
               t.program_return r3 = grammar2.program();
               StringTemplate output = (StringTemplate)r3.getTemplate();
               System.out.println(output.toString());

   }
}

The error is coming at the line:
               System.out.println(output.toString());
If I am removing this line, there is no error but I am not able to
print the output. I have attached the grammar files, template file and
the input file.
Please help to me to solve the error.

Thanks a lot.
Swathy
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

Attachment: g.g
Description: Binary data

Attachment: m.g
Description: Binary data

Attachment: t.g
Description: Binary data

Attachment: input.mapcode
Description: Binary data

Attachment: sal_prog_template.stg
Description: Binary data

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to