[antlr-interest] Segmention Fault in antlr c++ examples under linux

Juan Felipe Osorio jfosorio at eel.upc.es
Sun Mar 28 13:06:52 PST 2004


Hello, 
I am trying to run the c++ examples in the antlr getting started web
page using c++ under linux (g++). I have done successfully the
compilation process, but the result program produce a segmentation fault
just when the main routing try to parse the input (parser.expr() in the
code below, part of the John Merrells example of a simple calculator). I
think that the problem is something related with the way the main
rutting pass the cin stream to the parser routing but I am not sure. Any
Idea ?


//main.cpp
#include <iostream>
#include "CalcLexer.hpp"
#include "CalcParser.hpp"

using namespace std;
using namespace antlr;

int main()
{
try {
CalcLexer lexer(cin);
CalcParser parser(lexer);
parser.expr();
RefAST t = parser.getAST();
cout << t->toStringList() << endl;
} catch(exception& e) {
cerr << "exception: " << e.what() << endl;
}
}



// calc.g
options
{
language="Cpp";
}
class CalcLexer extends Lexer;
public
INTEGER: (DIGIT)+;
LPAREN: '(';
RPAREN: ')';
PLUS: '+';
protected
DIGIT: '0'..'9';


class CalcParser extends Parser;
options
{
buildAST=true;
}
expr: LPAREN INTEGER (PLUS INTEGER)* RPAREN;






 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
     antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/
 



More information about the antlr-interest mailing list