Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7042891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:13:22+00:00 2026-05-28T02:13:22+00:00

This is supposed to be part of a simple interpreter with several keywords, which

  • 0

This is supposed to be part of a simple interpreter with several keywords, which I made into different classes. The program is supposed to iterate over the ArrayList, tokenize the Strings and parse them into KEYWORD + instructions. I’m using a hashmap to map all these keywords to an interface which has classes, where the rest of the processing takes place. Currently testing out one of these keyword classes, but when I try to compile the compiler throws “identifier expected” and “illegal start of type” messages. The line throwing all the error messages is line 18. Where is the code going wonky? I can’t tell since I’ve never used a HashTable before. Thanks for the help!

import java.util.*;

public class StringSplit
{
interface Directive //Map keywords to an interface
{
    public void execute (String line);
}
    abstract class endStatement implements Directive
    {
        public void execute(String line, HashMap DirectiveHash)
        {   
            System.out.print("TPL finished OK [" + " x lines processed]");
            System.exit(0);
        }
    }
    private Map<String, Directive> DirectiveHash= new HashMap<String, Directive>();
    DirectiveHash.put("END", new endStatement());

    public static void main (String[]args)
    {
        List <String> myString= new ArrayList<String>();
        myString.add(new String("# A TPL HELLO WORLD PROGRAM"));
        myString.add(new String("STRING myString"));
        myString.add(new String("INTEGER myInt"));
        myString.add(new String("LET myString= \"HELLO WORLD\""));
        myString.add(new String("PRINTLN myString"));
        myString.add(new String("PRINTLN HELLO WORLD"));
        myString.add(new String("END"));


        for (String listString: myString)//iterate across arraylist
        {   
                String[] line = listString.split("[\\s+]",2);
                for(int i=0; i<line.length; i++)
                {
                    System.out.println(line[i]);
                    Directive DirectiveHash=DirectiveHash.get(listString[0]);
                    DirectiveHash.execute(listString);

                }

        }

    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:13:23+00:00Added an answer on May 28, 2026 at 2:13 am

    To get past your current compiler error, you’ll need to put the DirectiveHash.put("END", new endStatement()); call inside a block of some kind. If you want it in the instance initializer, try this:

    {
    DirectiveHash.put(“END”, new endStatement());
    }

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is part of my code which reads an http response. It's supposed to
This program is supposed to determine how many units are stored in the value
I have some simple code for popping up a dialog-like thing over part of
I've got kind of strange problem. I was working on a simple program which
I am writing this small code which is part of my Django application. It
This is supposed to work yet just says no stocks table - supposed lost
I'm trying to return json content read from MySQL server. This is supposed to
This code is supposed to be able to sort the items in self.array based
This code is supposed to read postfix problems from a file and and write
My apologies if you think this question is supposed to be on the Math

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.