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

  • Home
  • SEARCH
  • 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 8186353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:10:12+00:00 2026-06-07T02:10:12+00:00

I’m building a scripting language in Java for a game, and I’m currently working

  • 0

I’m building a scripting language in Java for a game, and I’m currently working on the parser. The language is to be utilized by players/modders/myself to create custom spells and effects. However, I’m having difficulty imagining how to smoothly implement static typing in the current system (a painful necessity driven by performance needs). I don’t care so much if compilation is fast, but actual execution needs to be as fast as I can get it (within reason, at least. I’m hoping to get this done pretty soon.)

So the parser has next() and peek() methods to iterate through the stream of tokens. It’s currently built of a hierarchy methods that call each other in a fashion that preserves type precedence (the “bottom-most” method returning a constant, variable, etc). Each method returns an IResolve that has a generic type <T> it “resolves” to. For example, here’s a method that handles “or” expressions, with “and” being more tightly coupled:

protected final IResolve checkGrammar_Or() throws ParseException
{
    IResolve left = checkGrammar_And();

    if (left == null)
        return null;

    if (peek().type != TokenType.IDENTIFIER || !"or".equals((String)peek().value))
        return left;

    next();

    IResolve right = checkGrammar_Or();

    if (right == null)
        throwExpressionException();

    return new BinaryOperation(left, right, new LogicOr());
}

The problem is when I need to implement a function that depends on the type. As you probably noticed, the generic type isn’t being specified by the parser, and is part of the design problem. In this function, I was hoping to do something like the following (though this wouldn’t work due to generic types’ erasure…)

protected final IResolve checkGrammar_Comparison() throws ParseException
{
    IResolve left = checkGrammer_Term();

    if (left == null)
        return null;

    IBinaryOperationType op;

    switch (peek().type)
    {
    default:
        return left;

    case LOGIC_LT:

        //This ain't gonna work because of erasure
        if (left instanceof IResolve<Double>)
            op = new LogicLessThanDouble();

        break;

    //And the same for these
    case LOGIC_LT_OR_EQUAL:
    case LOGIC_GT:
    case LOGIC_GT_OR_EQUAL:
    }

    next();

    IResolve right = checkGrammar_Comparison();

    if (right == null)
        throwExpressionException();

    return new BinaryOperation(left, right, op);
}

The problem spot, where I’m wishing I could make the connection, is in the switch statement. I’m already certain I’ll need to make IResolve non-generic and give it a “getType()” method that returns an int or something, especially if I want to support user-defined classes in the future.

The question is:

What’s the best way to achieve static typing given my current structure and the desire for mixed inheritance (user-defined classes and interfaces, like Java and C#)? If there is no good way, how can I alter or even rebuild my structure to achieve it?

Note: I don’t claim to have any idea what I’ve gotten myself into, constructive criticism is more than welcome. If I need to clarify anything, let me know!

Another note: I know you’re thinking “Why static typing?”, and normally I’d agree with you– however, the game world is composed of voxels (it’s a Minecraft mod to be precise) and working with them needs to be fast. Imagine a script that’s a O(n^2) algorithm iterating over 100 blocks twenty times a second, for 30+ players on a cheap server that’s already barely squeaking by… or, a single, massive explosion effecting thousands of blocks, inevitably causing a horrendous lag spike. Hence, backend type checking or any form of duck-typing ain’t gonna cut it (though I’m desperately aching for it atm.) The low level benefits are a necessity in this particular case, painful though it is.

  • 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-06-07T02:10:13+00:00Added an answer on June 7, 2026 at 2:10 am

    The solution I’m going with, as some have suggested in the comments, was to separate parsing and typing into separate phases, along with using an enum to represent type as I originally felt I should.

    While I appreciate Taymon’s answer, I can’t use it if I hope to support user defined classes in the future.

    If someone has a better solution, I’d be more than happy to accept it!

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I am currently running into a problem where an element is coming back from
I have thousands of HTML files to process using Groovy/Java and I need to
I'm trying to create an if statement in PHP that prevents a single post

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.