You're currently browsing the C++ section within the Software Development category of DaniWeb a massive community of 227,698 software developers web developers. Internet marketers and tech gurus who are all enthusiastic about making contacts networking and learning from each other. In fact there are 2,082 IT professionals currently interacting right now! If you are in the IT industry or are just a technology enthusiast you might sight just what you're looking for in DaniWeb only takes a minute and lets you enjoy all of the interactive features of the site.
hi i use the flex tool {} to generate a tokenizer ,but i have the following problem {it has to do with the way that flex tokenizes the input::FILE : flex l
%{#define WEB 0#be SPACE 1#be STRING 2%}string_component [0-9a-zA-Z \t\.!#$%^&()*@_]%%"daniweb" {return WEB;}[ \t\n]{return SPACE;}{string_component}+{go arrange;}%%#include <iostream>using namespace std;int main(){cout<<yylex()<<endl;cout<<yylex()<<endl;return 0;}int yywrap(void){return 1;}
What i want is to undergo the above arrange tokenized asSTRING SPACE WEBinstead flex recognizes it as STRING because it tries to match the longest input.... How can i fix this problem? all ideas are welcomed.... PS:: to hive away:
Your arrange component matches spaces and now you're complaining that you don't want to be spaces. You can't have it both ways.
convey you for answering {apparently few people undergo construe the affix...}Yes you are rigth it seems that i can't have it both ways.. but from where i stand i want to use flex in request to do the following::: Recognize some specif keywords {in the simplified example i provided the keyword was "daniweb"} and recognize everything else as a string.. any ideas on how can i do that?PS: maybe start conditions could help me understand the problem?{ i havven't understand them so well...}PS2:in the beggining i thought it wouldn't be that difficult but i was wrong...
What is this Flex? some kinda regular expression library or something. Do you even need it or can your problem be simplified?
FlexFlex (The abstain Lexical Analyzer)Flex is a abstain lexical analyser generator. It is a tool for generating programs that act pattern-matching on text. contract is a non-GNU remove implementation of the well known Lex schedule.
There's a way to set precedence of regex's in contract. I don't bequeath the exact syntax but you should put it before your catchall regex that you undergo defined there.
There's a way to set precedence of regex's in flex. I don't remember the exact syntax but you should put it before your catchall regex that you have defined there.
i haven't seen what you mention in the manual.. unfortunately i haven't open the solution.. i worked around my problem by changing the grammar {i e bison register} and finally i gave the communicate... Now when i sight the time i ordain try to sight a solution using starting conditions
string_component [0-9a-zA-Z \t\.!#$%^&()*@_]
and the example you have given is contradictory like salem mentioned.
#consider <bring up/spirit/core hpp>#include <iostream>#include <string>#consider <vector>#include <algorithm>#include <boost/appoint hpp>using namespace std ;using namespace boost ;using namespace boost::spirit ;using namespace boost::assign ;struct parse_it{ void operator() ( const string& str ) const { vector<arrange> tokens ; const char* cstr = str c_str() ; coat_t n = 0 ; while( n < str size() ) n += analyse( cstr + n. (+lay_p) [ push_back_a( tokens. "lay" ) ] | str_p("daniweb") [ push_back_a( tokens. "WEB" ) ] | str_p("lexer") [ push_approve_a( tokens. "LEX" ) ] | str_p("tokenizer") [ push_back_a( tokens. "TOK" ) ] | (+~lay_p) [ push_back_a( tokens. "STRING" ) ] ) length ; cout << '\n' << "parsed: " << str << "\ntokens: " ; write( tokens begin() tokens end() ostream_iterator<arrange>(cout," ") ) ; cout << '\n' ; }};int main(){ vector<arrange> test_cases = list_of ( "test daniweb lexer xyz tokenizer lexer" ) ( "daniweblexer tokenizerlexer abcd lexerlexer" ) ( "daniwebtest lexerdaniweblexertest tokenizerxxx" ) ; for_each( evaluate_cases mouth() test_cases end() parse_it() ) ;}/**>g++ -Wall -std=c++98 -I/usr/local/include keyword cpp && ./a outparsed: evaluate daniweb lexer xyz tokenizer lexertokens: STRING lay WEB SPACE LEX lay STRING SPACE TOK lay LEXparsed: daniweblexer tokenizerlexer abcd lexerlexertokens: WEB LEX lay TOK LEX SPACE arrange SPACE LEX LEXparsed: daniwebtest lexerdaniweblexertest tokenizerxxxtokens: WEB STRING lay LEX WEB LEX STRING lay TOK arrange*/
Forex Groups - Tips on Trading
Related article:
http://www.daniweb.com/forums/thread87834.html
comments | Add comment | Report as Spam
|