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

From: Simon Urbanek <simon.urbanek_at_r-project.org>
Date: Wed, 25 Nov 2009 01:09:51 -0500

On Nov 25, 2009, at 1:03 AM, Saptarshi Guha wrote:

> 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

It is. "x=" is incomplete -- try it in R and you'll see that you get a continuation prompt because it's incomplete:

 > x=
+ 1

Cheers,
S

> 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
>
> ______________________________________________
> R-devel_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Wed 25 Nov 2009 - 06:12:32 GMT

This archive was generated by hypermail 2.2.0 : Wed 25 Nov 2009 - 09:10:45 GMT