Link to home
Start Free TrialLog in
Avatar of Autkast
Autkast

asked on

Java Lexical Analyzer

I need assistance in wrapping my head around the development of a lexical analyzer in Java.  It has been a little bit since I have taken my last java course, however am fairly familiar with the language.  In the class I am taking we are working with BNF grammars and using recursive descent parsing to traverse these grammars and verify that a user input string is valid according to the rules of the grammar.  I have a decent pseudo code design for the grammar and have pieced most of it together, however the design of the lexical analyzer is eluding me to read the user input string.  
There are only 3 letters I am concerned with a, b and c.  I am trying to stay with the book here and declare the tokens separate as an enumerated type (i.e. {NONE, LETTER, ERROR, END_OF_FILE}).
My initial question:
Is this basic idea correct for the lexer?
•      Start with character NONE
•      Look at next character
    o          if character = a, b, or c
¿              Add character to lexeme
¿              Look at Next character
              •       Continue until end of user input string
    o          If there is no character
¿              Return lexeme
    o          If character != a, b, or c
¿              Return ERROR token
ASKER CERTIFIED SOLUTION
Avatar of dpearson
dpearson

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial