lex yacc
Download
Skip this Video
Download Presentation
Lex & Yacc

Loading in 2 Seconds...

play fullscreen
1 / 14

Lex & Yacc - PowerPoint PPT Presentation


  • 193 Views
  • Uploaded on

Lex & Yacc. COP 3402, Fall 2009. Lex – Symbol Table. When lexer has to recognize many tokens and their number is changing  use a symbol table stores lexemes and info about them, such as type of token

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Lex & Yacc' - jelani-rios


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
lex yacc

Lex & Yacc

COP 3402, Fall 2009

lex symbol table
Lex – Symbol Table
  • When lexer has to recognize many tokens and their number is changing  use a symbol table
    • stores lexemes and info about them, such as type of token
    • use a single pattern to match any word and then consult symbol table which token is found
  • Declaration start with type of token followed by the lexeme(s)
    • e.g:
lex symbol table cont d
Lex – Symbol Table (Cont’d)
  • Symbol table (ST) maintenance routines and variables:
    • func. add_word(): adds a new lexeme into ST
    • func. lookup_word(): looks up a word already in ST
    • var. state: keeps track of whether we are looking up words (state =LOOKUP) or declaring them (state = token type)
slide9
Yacc
  • For simple token recognition a lexer might be sufficient.
  • When specific sequences of tokens have to be recognized, a parser is necessary.
  • Grammar - a description of sequences of tokens and actions associated with them
    • e.g:
slide10
Yacc
  • Provides a general tool for imposing structure on the input to a computer program
  • Takes a grammar specified by the user and writes a parser that recognizes valid “sentences” in that grammar
  • When lex scanner and yacc parser are used together, the parser is the higher level routine
    • parser calls lexeryylex() whenever it needs a token
    • lexer scans through input recognizing tokens
slide11
Yacc
  • Lexer & parser have to decide on tokens codes
ad