Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java program: How can I create a scanner (also known as a tokenizer) that will take a sequence of characters (i.e., the source files of

Java program:

How can I create a scanner (also known as a tokenizer) that will take a sequence of characters (i.e., the source files of the LITTLE language) as input and produce a sequence of tokens? I'm using ANTLR.

For example, this is my input:

image text in transcribed

And this is what the java tokenizer output should look like:

image text in transcribed

I'm also using these imports:

import org.antlr.v4.runtime.*; import org.antlr.v4.runtime.tree.*;
PROGRAM fibonacci BEGIN STRING input := "Please input an integer number: "; STRING space :=""; STRING eol := " "; FUNCTION INT F (INT n) BEGIN IF (n>2) RETURN F(n-1)+F(n-2); ELSE RETURN 1; ENDIF END FUNCTION VOID main() BEGIN INT i, end, result; WRITE(input); READ(end); i:= 0; WHILE (i != end) result := F(i); WRITE (i,space); WRITE (result,eol); i:=i+1; ENDWHILE END END Token Type: KEYWORD Value: PROGRAM Token Type: IDENTIFIER Value: fibonacci Token Type: KEYWORD Value: BEGIN Token Type: KEYWORD Value: STRING Token Type: IDENTIFIER Value: input Token Type: OPERATOR Value: := Token Type: STRINGLITERAL Value: "Please input an integer number: Token Type: OPERATOR Value: ; Token Type: KEYWORD Value: STRING Token Type: IDENTIFIER 11 Value: space 11 11 Token Type: OPERATOR Value: := Token Type: STRINGLITERAL Value: Token Type: OPERATOR Value: ; Token Type: KEYWORD Value: STRING Token Type: IDENTIFIER Value: eol Token Type: OPERATOR Value: :=

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Objects And Databases International Symposium Sophia Antipolis France June 13 2000 Revised Papers Lncs 1944

Authors: Klaus R. Dittrich ,Giovanna Guerrini ,Isabella Merlo ,Marta Oliva ,M. Elena Rodriguez

2001st Edition

3540416641, 978-3540416647

More Books

Students also viewed these Databases questions

Question

2. Show the trainees how to do it without saying anything.

Answered: 1 week ago