[antlr-interest] Is c# antlr slow
altongoerby
alton.goerby at freenet.de
Tue Dec 30 13:26:46 PST 2003
I ahve the following .g files. It all compiles well.
If i try to parse a short line like in the following c# main it
takes more than 1 second to execute parser.expression(); which of
course is inacceptable. I am not sure what antlr is doing so long???
class Test
{
public static void Main(string[] args)
{
SimpleLexer lexer = new SimpleLexer(new StringReader
("trans1.Position [1 11 0 ](.hy \"hallo\" 12 [[1 2 3] [2 4 8 7]
[3 0 1] [ 4 9 876 12 ] ]) "));
SimpleParser parser = new SimpleParser(lexer);
// Parse the input expression
KernelServer ks = new KernelServer();
Console.WriteLine(ks.TimeServer.Time);
parser.expression();
Console.WriteLine(ks.TimeServer.Time);
CommonAST t = (CommonAST)parser.getAST();
// Print the resulting tree out in LISP notation
Console.Out.WriteLine(t.ToStringTree());
}
}
Btw i use the following geramme:
options {
language = "CSharp";
}
class SimpleParser extends Parser;
options {
buildAST = true; // uses CommonAST by default
k=1;
}
expression : assignment | command
;
assignment : VAR ASSIGN! (command | VAR | literal)
;
command : commandname (parameter)*
;
commandname : IDENT (DOT! IDENT)? | DOT! IDENT
;
parameter : LPAREN! command RPAREN! | VAR | literal
;
literal : affine | STRING | FLOAT
;
affine : LBRACK! (matrix | vector) RBRACK!
;
matrix : LBRACK! vector RBRACK! LBRACK! vector
RBRACK! LBRACK! vector RBRACK! (LBRACK! vector RBRACK!)?
;
vector : FLOAT FLOAT FLOAT (FLOAT)?
;
class SimpleLexer extends Lexer;
options {
k=1;
}
WS : (' '|'\t'|'\r'|'\n')
{ _ttype = Token.SKIP; }
;
LPAREN : '('
;
RPAREN : ')'
;
LBRACK : '['
;
RBRACK : ']'
;
ASSIGN : '='
;
DOT : '.'
;
STRING : '"' (~('"'|'\\'))* '"'
;
IDENT : ('a'..'z'|'A'..'Z'|'_')
('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
;
VAR : '$' IDENT
;
FLOAT : ('0'..'9')+
;
I hope someone can help me with that?
Also why does antlr generate such ugly code, at least in c#
(horrible)?
Bye,
Alton
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