help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem in grammar


From: Luca
Subject: Re: Problem in grammar
Date: Sun, 20 Feb 2011 11:46:54 +0100
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.9.2.13) Gecko/20101207 Thunderbird/3.1.7

Il 15/02/2011 12.06, Godeau Julien ha scritto:
Hello,

I have a problem with my grammar that I don't manage to solve and a
little help would really be greatful :o)

Here is the situation : I use Bison for a command interpreter. I deal
with variables (float values) and signals (object that contains
informations and a tab of float values that can be plotted).

Here is 2 examples of common use :



My_var = 3. + 1.

My_signal = 4. + My_other_signal

Mysignal = My_other_signal + 4.



Let's assume that My_var and My_signal are new identifiers, my problem
is that in the second example the command "Mysignal = 4." is recognized
by Bison as an integer variable assignment (with parsing error because
of "My_other_signal") while what should have been done is to recognize
that "4. + My_other_signal" is a signal (and process it) and then do a
signal assignment. In the third example, it works fine.



I don't manage to tell Bison that the priority is to process what is at
the right of the '=' before assigning the result using the good rule



*       Here are the precedence and priority used :



%right '='

%left OPERATOR1        /* '+' '-' */

%left OPERATOR2        /* '*' '/' */

%left '(' ')'

%left UNARY            /* for '-3' */



*       Here are the rules used



base : /* empty */

      | var_asgn

      | signal_asgn

;



new_id_equal : IDENTIFIER '=' { $$ = $1; }

;



var_asgn : new_id_equal float_val { $$ = $2; }

;



signal_asgn : new_id_equal signal { $$ = $2;}

;



float_value : FLOAT_VALUE                         { $$ = $1; }

             | float_value OPERATOR1 float_value   { $$ = ... }

             | float_value OPERATOR2 float_value   { $$ = ... }


             | '(' float_value ')'                 { $$ = $2; }

             | OPERATOR1 float_value %prec UNARY   { $$ = -$2; }

;



signal : '(' signal ')'                  { $$ = $2; }

        | full_function_call              { $$ = $1; }

        | OPERATOR1 signal %prec UNARY    { $$ = ... }

        | signal OPERATOR1 signal         { $$ = ... }

        | signal OPERATOR2 signal         { $$ = ... }


        | signal OPERATOR1 float_value    { $$ = ... }

        | float_value OPERATOR1 signal    { $$ = ... }

        | signal OPERATOR2 float_value    { $$ = ... }

        | float_value OPERATOR2 signal    { $$ = ... }


;



full_function_call : ...

;



Do you have any information that could help me ?

Best regards,



Julien

_______________________________________________
address@hidden http://lists.gnu.org/mailman/listinfo/help-bison

Just a little suggestion:
do you recognize "4. " as a single token in your lexer?
Perhaps flex can help you.

Bye,
Luca





reply via email to

[Prev in Thread] Current Thread [Next in Thread]