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 3275246
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:07:23+00:00 2026-05-17T19:07:23+00:00

I am trying to get the simple expression evaluator example on the ANTLR website

  • 0

I am trying to get the simple expression evaluator example on the ANTLR
website working within ActionScript, I have been able to get the java
version to work. But my ActionScript version is getting the following
error:

   TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at org.antlr.runtime::Lexer/nextToken()[/Users/gscott/antlr/code/antlr/main/runtime/ActionScript/project/src/org/antlr/runtime/Lexer.as:69]
    at org.antlr.runtime::CommonTokenStream/fillBuffer()[/Users/gscott/antlr/code/antlr/main/runtime/ActionScript/project/src/org/antlr/runtime/CommonTokenStream.as:84]
    at org.antlr.runtime::CommonTokenStream/LT()[/Users/gscott/antlr/code/antlr/main/runtime/ActionScript/project/src/org/antlr/runtime/CommonTokenStream.as:227]
    at org.antlr.runtime::CommonTokenStream/LA()[/Users/gscott/antlr/code/antlr/main/runtime/ActionScript/project/src/org/antlr/runtime/CommonTokenStream.as:289]
    at Eval_in_ASParser/prog()[C:\Users\Wayne-VII\Documents\Flex Builder 3\ANTLR_AIR_01\src\Eval_in_ASParser.as:61]
    at ANTLR_AIR_01/runProgram()[C:\Users\Wayne-VII\Documents\Flex Builder 3\ANTLR_AIR_01\src\ANTLR_AIR_01.mxml:11]
    at ANTLR_AIR_01/__bRunSource_click()[C:\Users\Wayne-VII\Documents\Flex Builder 3\ANTLR_AIR_01\src\ANTLR_AIR_01.mxml:20]

Well, since the code is in a SWC file and can not be seen in the debugger, I downloaded
the ActionScript source and tried to run the ant build, which failed.

So, here is my ANTLR grammer:

grammar Eval_in_AS;

options {
    language=ActionScript;
}

@header {
//import java.util.HashMap;
import flash.utils.Dictionary;
}

@members {
/** Map variable name to Integer object holding value */
public var memory:Dictionary = new Dictionary();
public var output:String = new String();

public function getOutput():String
{
return output;
}
}

prog:   stat+ EOF;

stat:   expr NEWLINE {output +="\n" + $expr + ":" + $expr.value;}
    |   ID '=' expr NEWLINE
        {memory[$ID.text] = int($expr.value);}
    |   NEWLINE
    ;

expr returns [int value]
    :   e=multExpr {$value = $e.value;}
        (   '+' e=multExpr {$value += $e.value;}
        |   '-' e=multExpr {$value -= $e.value;}
        )*
    ;

multExpr returns [int value]
    :   e=atom {$value = $e.value;} ('*' e=atom {$value *= $e.value;})*
    ; 

atom returns [int value]
    :   INT {$value = int($INT.text);}
    |   ID
        {
        if ( memory.hasOwnProperty($ID.text)) {$value = memory[$ID.text];}
        else {output +="\nundefined variable:"+$ID.text+"\n";$value = 0;}
        }
    |   '(' expr ')' {$value = $expr.value;}
    ;

ID  :   ('a'..'z'|'A'..'Z')+ ;
INT :   '0'..'9'+ ;
NEWLINE:'\r'? '\n' ;
WS  :   (' '|'\t')+ {skip();} ;

And here is my test rig:

var lexer:Eval_in_ASLexer = new Eval_in_ASLexer(taSource.text as CharStream);
var tokens:CommonTokenStream = new CommonTokenStream(lexer);
var parser:Eval_in_ASParser = new Eval_in_ASParser(tokens);
parser.prog();
taOutput.text = parser.getOutput();

In the above code, taOutput is a displayed textArea. My input is:

a=3
a

Can anyone see what I am doing wrong?

Of course I think there is a bug in this version of ANTLR’s ActionScript target, but I dislike how other people blame tools when it is their code. So first I am asking if there is something wrong in my coding.

  • 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-17T19:07:23+00:00Added an answer on May 17, 2026 at 7:07 pm

    I think the problem is with the new version of ANTLR 3.2.2 and ANTLRWorks not generating the correct code. Read other places where I have to use the command line tools. Closing this question.

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

Sidebar

Related Questions

I have been trying to get more in to TDD. Currently keeping it simple
I have been trying to get a simple spider to run with scrapy, but
I'm trying to get this simple PowerShell script working, but I think something is
I'm trying to get a simple search form working in my RoR site. I've
I am trying to get simple jQuery to execute on my Content page with
I am trying to get a simple demo started with ActiveMQ that will demonstrate
I'm trying to get this sample for AJAX to WCF working, with the following
In a WinApp I am simply trying to get the absolute path from a
I'm trying get values from a GridView using the following code: foreach (GridViewRow row
Trying to get my css / C# functions to look like this: body {

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.