[antlr-interest] intro..& questions
Robert Hill
rob.hill at blueyonder.co.uk
Tue Jun 7 14:27:22 PDT 2005
Hi all, been lurking for a while, so I thought I'd introduce myself before
asking lots of stupid questions.. :)
Im Rob, Programmer, 20yrs experience, mainly games, but now moved to <ahem>
sensible software (where the companies don't seem to go bankrupt at the rate
of 1 a week...)
I originally used PCCTS a long time ago, and had a problem that I thought I
could solve with it, and hence, I ended up here with antlr instead! :)
I have to say, a stunningly useful bit of software Terrence, Nice one.
Environment : WinXP, antlr 2.7.5, Devstudio, and C#
So on with the daft questions, they're just usage questions really - I'll
probably have more questions as the app I'm writing becomes less trivial :)
hehe
Ok, heres the first one
Q1. How do I get the current line number in a parser rule?
Im in the middle of the rule, checking the semantics and if there's
a problem I want to throw an exception with a new error format that's
DevStudio friendly ie
"Filename.v(25) : error blah blah blah" type of thing.
I can see there's a line number variable in the lexers inputState,
but how do you get at it from the Parser? I know I could make them into
singletons (there will only ever be one of each anyway) and get at the lexer
that way but it just seems .. well, wrong. I cant see any other way at
getting at the lexers inputstate to fetch the line the current token was
found on..
Q2:
Im using the string template to output the transformed source, and
im getting spurious newlines after braces ie...
structDecl(name,variables) ::=<<
struct $name${
$variables:{$it.decl:(it.format)()$}$
};
>>
Outputs
Struct aName
{
Line;
Line;
}
Where is the first newline coming from after the brace? It doesn't seem to
make any difference where I place the $variables$ stuff, I always get a
newline after the brace. Its just a formatting problem, but I thought that's
what the stringtemplate was for.. to help me format stuff how I want ;)
Any help much appreciated!
(and I bet you thought they were going to be difficult questions hehe)
Thanks.
Ps how do I get hold of Antlr V3? Sounds like a monster!
More information about the antlr-interest
mailing list