Re: [Flex-help] How to scan for token with no predefined value?
flex is a tool for generating scanners
Brought to you by:
wlestes
From: J. L. T. <jl...@ce...> - 2009-06-01 03:53:09
|
On Wednesday 27 May 2009 01:39:41 Virgil Palanciuc wrote: > Hi, > So, if I get it straight, your lexer should be something like this: > > <INITIAL>{command} { BEGIN(OPTIONAL_DELIMITER); /* do something for the > command */ } > <OPTIONAL_DELIMITER>{whitespace} { /* do nothing */ } > <OPTIONAL_DELIMITER>. { // I'm using '.', assuming that the delimiter > must be a single char; you can replace it with any other rule > BEGIN(MORE_SPECIFICATIONS); // delimiter is optional, so > we enter "MORE_SPECIFICATIONS" state regardless on whether this is indeed a > delimiter char > if( !isUserDelimiter(yytext) ) yyless(0); // if the char > is not delimiter, then don't consume it > else return TOK_DELIMITER; // if it is a > delimiter, return the appropriate token to the parser. > } > > <MORE_SPECIFICATIONS>{something} { /*.....*/; BEGIN(INITIAL) } > > Does this help/did I understand correctly what you are trying to do? > Virgil. > Virgil, Something like that is what I'm looking for. The switch to <OPTIONAL_DELIMITER> can be triggered when the endchar keyword is recognized, so it would look something like <INITIAL>"endchar" {BEGIN(OPTIONAL_DELIMITER) <OPTIONAL_DELIMITER>[^[[:ALPHANUM:]]] // tell the parser to save this value as endchar How do I tell the parser to associate the value with the token for endchar? Leslie > On Wed, May 27, 2009 at 7:40 AM, J. L. Turriff <jl...@ce...> wrote: > > I'm setting up flex definitions for a scripting language, and I've > > come > > across an issue that is not addressed in the flex manual. The language > > definition allows the user to define the value of an optional delimiter > > token > > at execution-time; the token has no default value. How do I handle this > > in the flex definitions? > > > > Here's an example of the usage: > > > > command (endchar ?) more specifications... > > > > The value of endchar has no default (its use is optional in /more > > specifications/) but whatever value is supplied by the user (in this > > case "?") must be recognized by the scanner. > > > > Leslie > > > > > > ------------------------------------------------------------------------- > >----- Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT > > is a gathering of tech-side developers & brand creativity professionals. > > Meet > > the minds behind Google Creative Lab, Visual Complexity, Processing, & > > iPhoneDevCamp as they present alongside digital heavyweights like > > Barbarian Group, R/GA, & Big Spaceship. > > http://p.sf.net/sfu/creativitycat-com > > _______________________________________________ > > Flex-help mailing list > > Fle...@li... > > https://lists.sourceforge.net/lists/listinfo/flex-help |