[antlr-interest] Problem building AST.

Arik Ter-Galstyan arik_tg at yahoo.com
Mon Oct 6 05:53:59 PDT 2008


Recently downloaded the Verilog grammar file from ANTLR website, generated the corresponding lexer and parser files and compiled them successfully with VS2008. Even wrote a small driver for the generated lexer and parser and successfully parsed a couple of verilog files. When setting the BuilsAST=1 in the options section, the generated lexer and parser files compile successfully however this time the same driver fails to parse the verilog files. It just crashes and brings the standard Microsoft error window to send an error report. Please note that in both cases it has been used the same driver. Besides, I have tried it with ANTLR 2.7.5, 2.7.6 and 2.7.7. Result is the same in all cases. Please share any ideas what I did wrong.

Below is given the driver code:

#include "stdafx.h"

#include "iostream"
#include "fstream"
#include "VerilogLexer.hpp"
#include "VerilogParser.hpp"

using namespace std;
using namespace antlr;


void parseFile(istream& s) {
	
	try {
	       // Create scanner that reads from input stream passed to us.
		VerilogLexer lexer(s);						

		// Create parser that reads from scanner.
		VerilogParser parser(lexer);

		// start parsing at the source_text rule.
		parser.source_text();				
	}
	catch (exception& e) {
		cerr << "parser exception: " << e.what() << endl;
	}
}

int _tmain(int argc, _TCHAR* argv[])
{
try {
		if (argc > 1 ) {
			
			cerr << "Parsing..." << endl;
			for(int i=1; i< argc;i++) {
				ifstream file(argv[i]);
				parseFile(file);
			}
		}
		else
			cerr << "Usage: VerilogParser <file names>" << endl;
	}
	catch(exception& e) {
		cerr << "exception: " << e.what() << endl;
	}

	return 0;
}


Thanks
Arik


      


More information about the antlr-interest mailing list