[antlr-interest] C++ generation doesn't work :( (Or I'm lost)
Philippe Lavoie
philippe.lavoie at cactus.ca
Tue Jan 28 12:09:55 PST 2003
I'm using the following grammar. When I try to run it, it crash and
burns. My test program is simply
#k1 = disk(10);
Please help
Phil
PS I posted regarding this project earlier, I decided to add actions to
my grammars and nothing is working :( Not that the grammar is complete
anyway... :)
The grammar follows and I'm including the main.cpp file too
======================================
options {
language="Cpp";
}
{
#include <string>
#include <iostream>
}
class MorphyParser extends Parser;
options {
buildAST=true;
}
program: (statement)* EOF!;
statement
: kernelStatement SEMI!
| assignment SEMI!
;
kernelStatement
: kernelOperation
| LPAREN! kernelOperation RPAREN!
;
assignment
: KERNELIDENT EQUAL^ kernel;
kernelOperation
: DISK^ LPAREN! INT RPAREN!
;
kernel
: KERNELIDENT | kernelStatement;
{
#include <string>
}
class MorphyLexer extends Lexer;
options {
exportVocab=Morphy;
testLiterals=false;
k=4;
}
tokens {
DISK="disk";
}
WS : ( ' '
| '\t'
| '\f'
// handle newlines
| ( options {generateAmbigWarnings=false;}
: "\r\n" // Evil DOS
| '\r' // Macintosh
| '\n' // Unix (the right way)
)
{ newline(); }
)+
{ $setType(ANTLR_USE_NAMESPACE(antlr)Token::SKIP); }
;
IDENT
options {testLiterals=true;}
: ('a'..'z'|'A'..'Z'|'_'|'$')
('a'..'z'|'A'..'Z'|'_'|'0'..'9'|'$')*
;
KERNELIDENT
: '#' IDENT
;
SEMI: ";";
LPAREN: "(" ;
RPAREN: ")" ;
protected DIGIT: '0'..'9';
INT: (DIGIT)+;
{
#include <string>
#include <iostream>
}
class MorphyTreeParser extends TreeParser;
options {
importVocab = Morphy;
}
kernelOperation
:
#(DISK a:INT) { std::cerr << "disk of size " << a << std::endl; }
;
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: morphy.cpp
Type: application/octet-stream
Size: 1009 bytes
Desc: morphy.cpp
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20030128/5f77dd15/morphy.obj
More information about the antlr-interest
mailing list