[antlr-interest] Re: function call and expressions in C++

Tarun Khanna tarunkhanna at gmail.com
Wed Jul 27 13:52:25 PDT 2005


Hi David,

Thanks for your response. Actually, I misunderstood the grammar, so it was 
my mistake.

I was talking about the function_call subrule in the rule 
postfix_expression. Since I saw the LPAREN expression? RPAREN, I thought it 
could also be used for simple grouping of expressions using parenthesis to 
enforce a precedence order. However I realized later that within the 
postfix_expression rule it can only be a function call as it would be 
prefixed with some expression/identifier.

And yes the grammar is pretty good and it has been of great help to me. It 
is very close to the C++ draft that I have refering to so far. I only need 
to parse C++ expressions. ( no need for anything else like statements, 
declarations, comments).
Thanks again.
Tarun

On 7/27/05, David Wigg <wiggjd at lsbu.ac.uk> wrote:
> 
> Hello Tarun,
> 
> I think you must be looking at our CPP_parser.g grammar so I
> think I should take an interest in your problem.
> 
> Forgive me, but I am not clear what (a,b) represents on its own.
> 
> I can see that a(a,b) represents a function (though I would
> prefer to say a(x,y) so we don't duplicate symbols).
> 
> I believe that the version you have is quite good and should
> parse most C++ statements quite well. However, I should just
> mention that I am working on an updated version which has been
> updated in various ways, some following comments and problems
> submitted by different users, and I hope to publish it next
> month (but as with all IT deadlines treat this with caution!).
> 
> I look forward to hearing from you.
> 
> David.
> 
> Original message in Digest, Vol 8, Issue 45.
> 
> Message: 1
> Date: Tue, 26 Jul 2005 11:49:25 -0400
> From: Tarun Khanna <tarunkhanna at gmail.com>
> Subject: [antlr-interest] function call and expressions in C++
> grammar
> To: ANTLR Interest <antlr-interest at antlr.org>
> Message-ID: <dbcf4c2c05072608496117ed29 at mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
> 
> I am trying to parse C++ expressions. From the grammar on the
> ANTLR website
> I can see this rule (simplified here, I removed the other
> alternatives)
> 
> postfix_expression
> {TypeSpecifier ts;
> DeclSpecifier ds = dsInvalid; // Purpose ?
> }
> :
> primary_expression
> (options {warnWhenFollowAmbig = false;}:
> LSQUARE expression RSQUARE
> | LPAREN (expression_list)? RPAREN
> | DOT id_expression
> | POINTERTO id_expression
> | PLUSPLUS
> | MINUSMINUS
> )*
> ) ;
> 
> Although it would parse a C++ expression just fine, I don't know
> how would
> it differentiate between the following. I want to create
> different root
> nodes in the following two situations. However with the above
> grammar I
> can't find a way to do so.
> 
> a(a, b) and
> (a, b)
> 
> -- Tarun Khanna -------------- next part --------------
> 
> 


-- 
Tarun Khanna
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20050727/5ec10868/attachment.html


More information about the antlr-interest mailing list