I am a total laser and parser newbie, so please have some patience. Ultimately, I want to be able to express LDAP style query strings, e.g. '(Foo = bar)', '(! Foo = bar)', '(& amp; (foo = bar) (! Zip = zap))' and finally a tree that I use to create the actual database Question (or whatever)
So I thought that to parse the foo = bar and expressions (! Foo = bar) in the simplest form, but already understood me There are some problems in this. I just want to express that the fields are separated from '=' by the value, but the ATLR will eat all the characters once Because the identifier looks like a lot of value. What do I have to do to stop this?
Grammar filter expression; Option {language = Java; K = 2; } Token {NOT = '!'; } Word: '(' no 'field' = 'VALUE') '; // Lesser field: NAME; VALUE: CDATA; Piece NAME: Alpha +; Piece CDATA: alpha *; Slice Alpha: ('A' .. 'Z' | 'A' .. 'Z');
OK, you're on the right track here. Just a few things that you need to change, you have to express field names and field values instead of lexer, because lexer can tell the difference between these two There is no way. These two (names and values) are used to parse which one you want more than one laser expression, which uses the same piece, makes them very difficult (impossible!) For the laser. It is very easy to make the determination of this very easy to make the value optional, just make that parser word optional (with '?' Behind it) along with the modified grammar, To see below (hopefully you did so) I've pasted the modified grammar below my reply to you.
Grammar filter expression; Option {language = Java; K = 2; } Token {NOT = '!'; } Word: '(' no, field '=' value '') '; // Lexer Field: ID; Price: ID; ID: Alpha +; Slice Alpha: ('A' .. 'Z' | 'A' .. 'Z');
Comments
Post a Comment