Question
If i am creating an arithmetic lexer, such that the tokens would be NUMBER, ADD, TIMES, DIVIDE, MINUS and EndOfLine(spaces, i believe). I have created
If i am creating an arithmetic lexer, such that the tokens would be NUMBER, ADD, TIMES, DIVIDE, MINUS and EndOfLine(spaces, i believe). I have created the enum class with tokens. how would i Lex it? with switch statement and also take into affect decimals and negative numbers. The input will be read in another file. This is JAVA.
file must be called Lexer.java. The Lexer class must contain a lex method that accepts a single string and returns a collection (array or list) of Tokens. The lex method must use one or more state machine(s) to iterate over the input string and create appropriate Tokens. Any character not allowed by your state machine(s) should throw an exception.
Input an empty line 5 5.23 -8.5 + 3 8*-4 +99999 7431 +-*/ Output EndOfLine NUMBER (5) EndOfLine NUMBER(5.23) MINUS NUMBER(8.5) PLUS NUMBER(3) EndOfLine NUMBER (8) TIMES NUMBER (-4) PLUS NUMBER (99999) EndOfLine NUMBER(7) NUMBER(4) NUMBER(3) NUMBER(1) EndOfLine PLUS MINUS TIMES DIVIDE EndOfLine Input an empty line 5 5.23 -8.5 + 3 8*-4 +99999 7431 +-*/ Output EndOfLine NUMBER (5) EndOfLine NUMBER(5.23) MINUS NUMBER(8.5) PLUS NUMBER(3) EndOfLine NUMBER (8) TIMES NUMBER (-4) PLUS NUMBER (99999) EndOfLine NUMBER(7) NUMBER(4) NUMBER(3) NUMBER(1) EndOfLine PLUS MINUS TIMES DIVIDE EndOfLine
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started