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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:09:20+00:00 2026-06-11T15:09:20+00:00

I would like to use ParseKit for analyzing some javascript code. I got the

  • 0

I would like to use ParseKit for analyzing some javascript code. I got the framework setup with a javascript grammar, but I can’t really get my head around what route to take to analyze the code. The thing is, i would like in the end to for example get an array of all globally declared var’s (so var’s that are defined outside a function). But i can’t really see how i can get that result! I’ve been reading a lot of questions here on stack overflow, and can see that I somehow probably should use the stack and target of the assembler, but the thing is that the function callback is called when it reaches the functions block end, so all the var definitions get’s callbacked before. How do i know when i get a callback on a var inside a function, that its inside?

var i = 0;
function test(){
   var u = 0;
}

Here i want to find i for example, not u. But the callbacks are

#1  Found var i
#2  Found var u
#3  Found func test

Jonas

  • 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-11T15:09:21+00:00Added an answer on June 11, 2026 at 3:09 pm

    Developer of ParseKit here.

    First, checkout this answer to another, somewhat-related ParseKit question. There’s lots of relevant info there (and in the other answers linked there).

    Then, for your particular example, the key is to set a flag whenever a function begins, and to clear the flag when it ends. So whenever a var decl is matched, just check the flag. If the flag is set, then ignore the var decl. If the flag is not set, then store it.

    It is vitally important that the flag I mentioned be stored on the PKAssembly object which is the argument to your assembler callback functions. You cannot store that flag as an ivar or global var. That won’t work (see prior linked answers for details why).

    Here’s some example callbacks for setting the flag and matching var decls. They should give you an idea of what I’m talking about:

    // matched when function begins
    - (void)parser:(PKParser *)p didMatchFunctionKeyword:(PKAssembly *)a {
        [a push:[NSNull null]]; // set a flag
    }
    
    // matched when a function ends
    - (void)parser:(PKParser *)p didMatchFunctionCloseCurly:(PKAssembly *)a {
        NSArray *discarded = [a objectsAbove:[NSNull null]];
        id obj = [a pop]; // clear the flag
        NSAssert(obj == [NSNull null], @"null should be on the top of the stack");
    }
    
    // matched when a var is declared
    - (void)parser:(PKParser *)p didMatchVarDecl:(PKAssembly *)a {
        id obj = [a pop];
        if (obj == [NSNull null]) { // check for flag
            [a push:obj]; // we're in a function. put the flag back and bail.
        } else {
            PKToken *fence = [PKToken tokenWithTokenType:PKTokenTypeWord stringValue:@"var" floatValue:0.0];
            NSArray *toks = [a objectsAbove:fence]; // get all the tokens for the var decl
            // now do whatever you want with the var decl tokens here.
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possibly really simple question, but I'm new to IronPython. I would like use IronPython
I would like to use the logout function from Django but not sure how
I would like to use the jenkins script console some more. Where do I
I would like to use the MFMailComposeViewController mailComposeDelegate property with completion block syntax, but
i would like use a variable session ($_session) but it doesn't work in Drupal
I would like test code in the lib directory of Rails. I use RubyTest
I currently have some large strings that I would like use as test data
I would like to use a component that exposes the datasource property, but instead
I would like to use client-side Javascript to perform a DNS lookup (hostname to
I would like to use javascript to develop general-purpose GUI applications. Initially these are

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.