views:

50

answers:

1

I tried to modify the mini_c example of boost::spirit to match to my existing vocabulary.

I therefore added a operator "NOT that should behave equal as "!":

unary_expr =
        primary_expr
    |   ("NOT" > primary_expr           [op(op_not)]) // This does not work
    |   ('!' > primary_expr             [op(op_not)])
    |   ('-' > primary_expr             [op(op_neg)])
    |   ('+' > primary_expr)
    ;

I can compile the modified source code, but when i try to execute it it fails to parse. How can i solve this?

EDIT: As my want to access external variables, i had made another modification in order to build a list of these variables when compiling:

identifier %=
    raw[lexeme[alpha >> *(alnum | '§' | '_' | '.' | '-' )]]
    ;
variable =
       identifier      [add_var(_1)]
    ;

Where add_var and identifier are defined as

rule<Iterator, std::string(), white_space> identifier;
function<var_adder> add_var;

If i don't use this modification, "NOT" can be used. With the modification, using "NOT" generates a parsing error.

A: 

With your change the small test:

int main()
{
    return NOT 1;
}

parses successfully and returns 0. So it is not obvious to me what doesn't work for you. Could you provide a failing input example as well, please?

hkaiser
I also made other changes. Please see my edited post.
RED SOFT ADAIR
The first change you made (the `identifier %= ...`) is not related to the problems you are seeing. It's the second change (the `variable = ...`) which is problematic. Essentially what you did is to allow implicit variable declarations by blindly adding any encountered identifier into the symbol table. This is not only dangerous, but in your case adds the `NOT` to that table as well, causing the errors at parse time.
hkaiser