From saptarshi.guha at gmail.com  Wed Nov 25 07:03:17 2009
From: saptarshi.guha at gmail.com (Saptarshi Guha)
Date: Wed, 25 Nov 2009 01:03:17 -0500
Subject: [Rd] Question R's parser : - parsing "x=\n 1"
Message-ID: <1e7471d50911242203t4e610d3bkbfdddd3816f3df6b@mail.gmail.com>

Hello
I was reading the source main/src/gram.y and had one question, how does R parse

x =
  1

According the grammar:

prog	:	END_OF_INPUT			{ return 0; }
	|	'\n'				{ return xxvalue(NULL,2,NULL); }
	|	expr_or_assign '\n'			{ return xxvalue($1,3,&@1); }
	|	expr_or_assign ';'			{ return xxvalue($1,4,&@1); }
	|	error	 			{ YYABORT; }
	;


So this should be of the 3rd form.
Also, the expr_or_assign is of the 2nd form in

expr_or_assign  :    expr                       { $$ = $1; }
                |    equal_assign               { $$ = $1; }
                ;

where equal_assign is

equal_assign    :    expr EQ_ASSIGN expr_or_assign              { $$ =
xxbinary($2,$1,$3); }

When the parser sees 'x' and '=' it expects an expr_or_assign and we
know it will receive an expr. However, the expr cannot be a new
line(according to the defn of expr)

So instead of an expr, the parse gets a newline and should fail.
Q: So how does R parse this?
I think it fails with a Parse_Incomplete and keeps on reading till EOF
(or till an expression is complete).
But this is not really an incomplete expression but if my
interpretation is correct a syntax error, yet R parses it.
So i understood something else or R's engine manages to do things differently
Regards
Saptarshi



[Rd] Question R's parser : - parsing "x=\n 1"
Saptarshi Guha