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.

If i am creating an arithmetic lexer, such that the tokens would

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!