[antlr-interest] Re: ANTLR 2.7.2 portability
iank at bearcave.com
iank at bearcave.com
Wed Jun 4 09:31:55 PDT 2003
> It's in the C++ docs as well.. at least in the ones in the repository this
> is documented.
I confess that I did not RTFM. I rebuilt my old example and it
crashed on an uninitialized object (e.g., this == 0). So I looked
at the examples.
> > However there seem to be grammar based problems as well (no grammar errors
> > or warnings, but the grammer works differently now). So the transition
> > has not been as painless as I had hoped.
>
> Could you elaborate on this?
The example I've tried to rebuild is from my simple expression
parser. This is on my web page
http://www.bearcave.com/software/antlr/antlr_examples.html
I have not updated the "main.C" with my new code that properly
initializes the AST Factory, so the supporting C++ which prints the
tree is out of date. I'm using the default AST construction. The
grammar is shown below. The parser processes the left hand side
identifier, the assignment and then nothing else. I'm note sure why
this is. As I note on the web page, this used to work. If it is
not something blazingly obvious, please don't spend time on this.
After all, I have not read the recent documentation changes and one
should RTFM before asking for help.
Ian
options {
language="Cpp";
}
class MyExprParser extends Parser;
options {
k = 2;
exportVocab=MyExpr;
buildAST = true;
}
exprlist
: ( assignment_statement )* EOF!
;
assignment_statement
: assignment SEMICOLON!
;
assignment
: (IDENT ASSIGN )? expr
;
primary_expr
: IDENT
| constant
| (LPAREN! expr RPAREN! )
;
sign_expr
: (MINUS)? primary_expr
;
mul_expr
: sign_expr (( TIMES | DIVIDE | MOD ) sign_expr)*
;
expr
: mul_expr (( PLUS | MINUS ) mul_expr)*
;
constant
: (ICON | CHCON)
;
class MyExprLexer extends Lexer;
options {
k = 2;
exportVocab=MyExpr;
}
WS_ : (' '
| '\t'
| '\n'
| '\r')
{ _ttype = Token::SKIP; }
;
IDENT
options {
paraphrase = "identifier";
}
: ('a'..'z' | 'A'..'Z' | '_' ) ( ('a'..'z' | 'A'..'Z' | '_') |
('0'..'9' ))*
;
ICON
options {
paraphrase = "integer constant";
}
: '0'..'9' ('0'..'9')*
;
CHCON
options {
paraphrase = "character constant";
}
: "'" '\0'..'\255' "'"
;
COMMA
options {
paraphrase = ",";
}
: ','
;
SEMICOLON
options {
paraphrase = ";";
}
: ';'
;
LPAREN
options {
paraphrase = "(";
}
: '('
;
RPAREN
options {
paraphrase = ")";
}
: ')'
;
LCURL
options {
paraphrase = "{";
}
: '{'
;
RCURL
options {
paraphrase = "}";
}
: '}'
;
PLUS
options {
paraphrase = "+";
}
: '+'
;
MINUS
options {
paraphrase = "-";
}
: '-'
;
TIMES
options {
paraphrase = "*";
}
: '*'
;
DIVIDE
options {
paraphrase = "/";
}
: '/'
;
MOD
options {
paraphrase = "%";
}
: '%'
;
ASSIGN
options {
paraphrase = "=";
}
: '='
;
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list