I'm new to PEGs (but I've been parsing for a while) and I don't understand
why this..

E->XYE|ZE|

..doesn't parse "1+1-2" the way I expect (it fails):

i've tried using PackCC and I now in leg (it's more likely you know leg
than pcc)

$ ./leg g.peg -o g.c && cc g.c -o g && ./g
+fail

$ cat g.peg
#leg g.peg -o g.c && cc g.c -o g && ./g
%{
char*in="1+1-2";
#define YY_INPUT(b,r,m) *in?*(b)=*in++,putchar(*in),1:0
%}
S=E '\n';
E=x:X y:Y z:E {printf("%c%c%c\n",x,y,z);$$='E';}
 |x:Z y:E     {printf("%c%c\n",x,y);$$='E';}
 |''          {printf("''");$$='E';}
 ;
Z=x:X         {$$=x}
 |x:Y         {$$=x}
 ;
X= < [0-9] >  {$$=*yytext;};
Y= < [-+]  >  {$$=*yytext;};
%%
#include <stdio.h>
int main()
{
 return yyparse()?printf("success\n"),0:printf("fail\n");
}

thanks,
jack
_______________________________________________
PEG mailing list
PEG@lists.csail.mit.edu
https://lists.csail.mit.edu/mailman/listinfo/peg

Reply via email to