OSDev.org

The Place to Start for Operating System Developers
It is currently Sat Apr 20, 2024 12:15 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Flex analyses the way of Token
PostPosted: Wed Jan 08, 2003 7:05 pm 
Could you tell me when Flex analyses the word(Token) ,it is the disposable reading into its inside buffer area of a lot of characters , Analyse the buffer content of district ,resolve and publish piece of Tokens; If reach the end of buffering area,read into again


Top
  
 
 Post subject: Re:Flex analyses the way of Token
PostPosted: Wed Jan 08, 2003 7:12 pm 
This would be better in the Programming forum....


Top
  
 
 Post subject: Re:Flex analyses the way of Token
PostPosted: Thu Jan 09, 2003 3:52 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 2:31 am
Posts: 5964
Location: In a galaxy, far, far away
the core of Flex is a finite state automaton (check google for some theory about it). every new character is checked against a character table and will lead to a new state where new characters are available.

For instance, imagine you want to translate ":-)" into "joy.gif", ":-(" into "sad.gif", ">:[" in "angry.gif" and "=]" in "l337.gif"

Code:
  state0 : {':' --> state1 , '>' --> state2, '=' --> state3}
  state1 : {'-' --> state4}
  state2 : {':' --> state5}
  state3 : {']' --> accept("l337.gif")}
  state4 : {')' --> accept("joy.gif"), '(' --> accept("sad.gif")}
  state5 : {'-' --> state6}
  state6 : {'[' --> accept("angry.gif")}


that's it ... you start in state0 and try to follow the existing chars. If you can't, just output the first char of the current string and go on with the second one (so that ::-) is translated into :joy.gif)

_________________
Image May the source be with you.


Top
 Profile  
 
 Post subject: Re:Flex analyses the way of Token
PostPosted: Thu Jan 09, 2003 11:26 pm 
Thanks! This my dear friend speaks very much above! Flex is really a method to use finite state, It will get the state transition diagram(Transition disgram) according to Regular Expression, Produce the state and change form(some array forms)s according to this transition diagram afterwards, And cooperate with a corresponding word and discern that the procedure discerns Token.


Top
  
 
 Post subject: Re:Flex analyses the way of Token
PostPosted: Fri Jan 10, 2003 2:52 am 
All there is Look Ahead this concept in morphological analysis and syntactic analysis. Whether Look Ahead in morphological analysis just needs Look Ahead in order to match the longest Pattern , But it need and recognise next Token either,why recognise The Next Token of the yytext among Flex? ? ? ? ?


Top
  
 
 Post subject: Re:Flex analyses the way of Token
PostPosted: Tue Jan 14, 2003 2:17 am 
Thanks a lot! Please give me a forgiveness for my bad english
There is the concept named Look Ahead both parser and Lexer. In order to match the longest Token in all pattern

matching rules in lexer,lexer need looking ahead,but not need get the next Token! why do we get the next Token in yytext in flex?


Top
  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 29 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group