سؤال

I'm working on the follow syntax:

 e   : e T_MINUS e                                              { $$ = mk_app(mk_app(mk_op(MINUS),$1),$3);}
    | T_NUM                            { $$ = mk_int($1);}
    | T_MINUS e                        { $$ = mk_app(mk_app(mk_op(MULT),mk_int(-1)),$2);}
    | T_POP e[l]                           { $$ = mk_app(mk_op(POP),$l);}
    | T_NEXT e[l]                          { $$ = mk_app(mk_op(NEXT),$l);}
    |'{' e[x] ',' e[y] '}'                     { $$ = mk_point($x,$y);} 
    | T_BEZIER '(' e[p1] ',' e[p2] ',' e[p3] ',' e[p4] ')' { $$ = mk_bezier($p1,mk_bezier($p2,mk_bezier($p3,mk_bezier($p4,NULL))));}
    | T_CIRCLE '(' e[c] ',' e[r] ')'                       { $$ = mk_circle($c,$r);}     
    | T_TRANS '(' e[fig] ',' e[vect] ')'                   { $$ = mk_app(mk_app(mk_op(TRANS),$fig),$vect);}    
    | e T_PATH e                                           { $$ = mk_path($1,mk_path($3,NULL));}
    | e T_PLUS e                                           { $$ = mk_app(mk_app(mk_op(PLUS),$1),$3);}
    | e T_DIV e                                            { $$ = mk_app(mk_app(mk_op(DIV),$1),$3);}
    | e T_MULT e                                           { $$ = mk_app(mk_app(mk_op(MULT),$1),$3);}
    | e T_LEQ e                                            { $$ = mk_app(mk_app(mk_op(LEQ),$1),$3) ;}
    | e T_LE e                                             { $$ = mk_app(mk_app(mk_op(LE),$1),$3) ;}
    | e T_GEQ e                                            { $$ = mk_app(mk_app(mk_op(GEQ),$1),$3) ;}
    | e T_GE e                                             { $$ = mk_app(mk_app(mk_op(GE),$1),$3) ;}
    | e T_OR e                                             { $$ = mk_app(mk_app(mk_op(OR),$1),$3) ;}
    | e T_AND e                                            { $$ = mk_app(mk_app(mk_op(AND),$1),$3) ;}
    | T_ID                                                 { $$ = mk_id($1);}/*Reconnaissance d'identificateurs et de variables*/
    | e T_EQ e                                             { $$ = mk_app(mk_app(mk_op(EQ),$1),$3) ;}
    | T_NOT e[expr]                                        { $$ = mk_app(mk_op(NOT),$expr) ;}
    | T_FUN T_ID[var] arg_list[expr]                       { $$ = mk_fun($var,$expr);} /*Définition de fonctions*/
    | T_LET T_ID[x] T_EQUAL e[arg] T_IN e[exp]             { $$ = mk_app(mk_fun($x,$exp),$arg); }/*Fonction IN*/
    | e[exp] T_WHERE T_ID[x] T_EQUAL e[arg]                { $$ = mk_app(mk_fun($x,$exp),$arg); }/*Fonction WHERE*/
    | T_IF e[cond] T_THEN e[then_br] T_ELSE e[else_br]     { $$ = mk_cond($cond, $then_br, $else_br) ;}
    | '[' list[l] ']'                                      { $$ = $l;}/*OP sur Listes*/
    | e[exp] T_PUSH e[l]                                   { $$ = mk_app(mk_app(mk_op(PUSH),$exp),$l);}
    |  e[fun] e[arg] %prec FUNCTION_APPLICATION            { $$ = mk_app($fun,$arg);}/*Exécution de fonctions à plusieurs variables*/
    | '(' e ')'                                            { $$ = $2;}/*Ignorer les parentheses inutiles*/
    ;

and when I use list which is :

list  : e[ex]               {$$ = mk_cell($ex,mk_nil());}
      | e[ex] ',' list[l]               {$$ = mk_cell($ex,$l);}
      |/*empty*/                    {$$ = mk_nil();}
      ;

the parser recognizes the list, but if I use the 'e' T_ID it returns a syntax error

for example:

[1,2,3] ok

[1+2,2-5] ok

but if I have:

a = 2

b = 3

and make a list like:

[a,b]

it returns a syntax error

what I would like to understand is why the expression T_ID is not taken in consideration.


EDIT: debug result:

    Reading a token: [a,b];
    Next token is token T_ID ()
    Shifting token T_ID ()
    Entering state 4
    Reducing stack by rule 26 (line 116):
       $1 = token T_ID ()
    -> $$ = nterm e ()
    Stack now 0 1
    Entering state 21
    Reading a token: Next token is token ',' ()
    syntax error
    Error: popping nterm e ()
    Stack now 0 1
    Error: popping nterm s ()
    Stack now 0
    Cleanup: discarding lookahead token ',' ()
    Stack now 0

EDIT 2:

no that is not the full debug but for example when we use the '{' e ',' e '}' it does shift the '{' token first but for '[' it doesn't and I can't find why I did recheck the flex parser which the rule is :

[(),\[\]{}]         {return yytext[0];}

but nothing happens and for the output report as it is to long here is a link:

parser.output

هل كانت مفيدة؟

المحلول

ok i found the error for some reason that i don't understand the flex rule :

[a-zA-z]+    {yylval.id = strdup (yytext); return T_ID;}

is returning "[a" as a token once it was supposed to return 2 different token once the rule :

[(),\[\]{}]         {return yytext[0];}

come before. changing the rule

[a-zA-z]+    {yylval.id = strdup (yytext); return T_ID;}

for

[[:alpha:]]+    {yylval.id = strdup (yytext); return T_ID;}

solves the problem

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top