[GRASS5] lex/yacc parser help ...

Eric G. Miller egm2 at jps.net
Sun Mar 10 18:09:06 EST 2002


I'm trying to write a lex/yacc parser for reading in reclass rules for a
new s.reclass.  Having zero experience with lex and yacc, I'm having a
little trouble trying to figure out how to have it be in one of three
parse modes.  I'll know when calling the parser, which mode I want.

Basically, the reclass rules will allow sites to be reclass via existing
category values, a decimal (double) attribute or a string attribute.
The rules can be like:

item = cat
item thru item = cat
item item [item ...] = cat
* = cat

The "*" is a default reclass rule, and is a singleton (if it is given).

So, a generic grammer...

rule:  item '=' cat
    |  item "thru" item '=' cat
    |  item_list '=' cat
    |  '*' = cat
    ;

item_list: item
    | item_list item
    ;

item: integer
    | decimal
    | string
    ;

One problem, is this grammar doesn't apparently restrict all items to
be the same type.  So, perhaps I have four rule types (default_rule,
int_rule, decimal_rule, string_rule).  I still need each parse line
to ensure the same type of rule is invoked.  I'm not clear on how
one does that...

And, yes, I could write the parser w/o lex/yacc, but I'd like to use
them...

-- 
Eric G. Miller <egm2 at jps.net>



More information about the grass-dev mailing list