Wednesday, June 27, 2012

Tokens, patterns and lexemes


Token:  Token is a sequence of characters that can be treated as a single logical entity. Typical tokens are,                                                                                       
1) Identifiers 2) keywords 3) operators 4) special symbols 5)constants
Pattern: A set of strings in the input for which the same token is produced as output. This set of strings is described by a rule called a pattern associated with the token.
Lexeme: A lexeme is a sequence of characters in the source program that is matched by the pattern for a token.
Example:          
                              Description of token 

Token lexeme pattern
const const   const  
if if if
relation <,<=,= ,< >,>=,>    
< or <= or = or < > or >= or  letter
followed by  letters & digit   
i pi any numeric constant
nun 3.14    any character b/w “and “except"
literal "core" pattern
                                                                  
 A patter is a rule describing the set of lexemes that can represent a particular token in source program.

25 comments:

  1. good but need more explanation......

    ReplyDelete
  2. Nic but need more explanation

    ReplyDelete
  3. PATTERN = REGULAR EXPRESSION OR AUTOMATA
    LEXEME = A WORD
    TOKEN = TYPE OF WORD
    LEXEME = TOKEN

    ReplyDelete
  4. This is nice blog. Contents over here are so informative. Want to grab more on Lexeme (Lexicon) and word forms | Cognitive Science

    ReplyDelete
  5. define the terms of lexeme,token and pattern.

    ReplyDelete
    Replies
    1. Tokens are the terminal symbols in the grammar.
      Patterns are description of a class of tokens.
      Lexemes are words in the source program

      Delete
  6. Tokens are the terminal symbols in the grammar.
    Patterns are description of a class of tokens.
    Lexemes are words in the source program

    ReplyDelete
  7. thats a nice one ...but you need to improve your subject nasty fellow

    ReplyDelete
  8. Lexeme is smallest logical unit of program, token is the unique element of program, pattern is the formal and informal description of token

    ReplyDelete
  9. This comment has been removed by the author.

    ReplyDelete
  10. A token is a pair consisting of a token name and an optional attribute value. The token name is an abstract symbol representing a kind of lexical unit, e.g., a particular keyword, or a sequence of input characters denoting an identifier. The token names are the input symbols that the parser processes. In what follows, we shall generally write the name of a token in boldface. We will often refer to a token by its token name.
    • A pattern is a description of the form that the lexemes of a token may take. In the case of a keyword as a token, the pattern is just the sequence of characters that form the keyword. For identifiers and some other tokens, the pattern is a more complex structure that is matched by many strings.
    • A lexeme is a sequence of characters in the source program that matches the pattern for a token and is identified by the lexical analyzer as an instance of that token.

    ReplyDelete
  11. This comment has been removed by the author.

    ReplyDelete