Handling some of the warnings and errors generated by JavaCC

I am currently building a parser using JavaCC. I have used JavaCC in the past, but whenever I use it after a long gap, I have to relearn a few things about it – particularly handling warnings. So I thought this time I would blog about ways to handle some of the frequent warnings that I have seen.

If you are unfamiliar with JavaCC, then it is a parser generator. You create grammer using EBNF (Extended Backus-Naur Form) and feed it to JavaCC. JavaCC then creates Java classes for the parser. I do not want to make this post into JavaCC tutorial. There are some very good tutorials available at JavaCC Documentation page and FAQ. I especially find Lookahead MiniTutorial and Token Manager MiniTutorial very useful. If you use Eclipse IDE, then you would find JavaCC plugin for Eclipse useful – it provides wizard to create JavaCC or JJTree (JJTree creates AST, Abstract Syntax Tree, after parsing the input) files, provides code colorization, outline, code hyper link, syntax checking and compilation. You can also set JavaCC debug options easily using this plugin.

I will use following tokens that are generated by default if you use the wizard provided by JavaCC Eclipse plugin to create a JavaCC grammer file. I have created a .jjt file for examples in this blog.

Continue reading “Handling some of the warnings and errors generated by JavaCC”

My first ever book,Instant Eclipse 4 RCP Development How-to, is published

I am happy to announce that my book titled Instant Eclipse 4 RCP Development How-to has been published by PACKT Publishing. It is a mini-book that describes specific tasks and solutions to build RCP applications using Eclipse 4.

Eclipse 4 has introduced new frameworks, APIs and tools to develop Rich Client Platform (RCP) Applications.  In this book I have taken a sample application and explained how to implement it from start to finish using Eclipse 4 SDK. The book is divided into a number of  focused tasks. Each task builds the sample application incrementally .

Here is the list of tasks covered in the book –

  • Setting up a development environment 
  • Creating a skeleton E4 application
  • Adding menu and toolbar items 
  • Adding views
  • Injecting your own objects using DI
  • Creating a pop-up menu 
  • Creating custom events and handlers 
  • Adding a keyboard shortcut 
  • Creating custom objects using DI 
  • Creating views dynamically 
  • Styling an application using CSS 
  • Customizing and exporting the application

I was contacted to write this book towards the end of last year. Initially it got delayed a bit because I was busy with other things. It was finally published yesterday.

The book is also available on Amazon.

-Ram Kulkarni

 

Installing and configuring Android SDK outside IDE

I have always configured and used Android SDK from Eclipse. In fact, ADT (Android Development Kit) bundle now comes with Eclipse IDE pre-configured for Android development.  This makes using the SDK very easy. Options like configuring SDK manager and virtual device manager are available right from Eclipse menu.

However, I had a requirement where I wanted to run only Android emulator and not IDE. The Android SDK site has all the information to do this, but not in one easy to find place. So I thought I will write about it, for my own reference.

Continue reading “Installing and configuring Android SDK outside IDE”

Sprite Animation Revisited


Last year I had blogged about animating sprite using Kinetic JS.
Code in that post was part of a simple game I had created. So the code specific for animating sprite was explained in snippets. A reader of that post contacted me with a request to provide a complete example. So I created a small demo of sprite animation only. If you are interested, you can download it from here. This demo animates images in the sprite sheet at a fixed location, it does not move the image. So I thought  it would be interesting to add motion to sprite images when they are animated.

First, take a look at the demo. Click on the Walk button to make the person walk. You can stop any time. If the person hits right side wall, then she falls, which is also simulated using sprite animation. I know the ‘walk’ does not look natural, but creating graphics is not my string point and this is the best I could manage.

Walking Speed : (Enter value from 1 to 10)

Continue reading “Sprite Animation Revisited”

Understanding AST created by Mozilla Rhino parser

For an application I am developing, I needed to get all functions and variables declared in JavaScript code. Because the application I am developing is in Java, I started looking for readily available JavaScript parser written in Java. I found Mozilla Rhino to be a good fit for my requirements and decided to use it.

Parsing with Rhino is quite simple and well documented.

private AstRoot parse(String src, int startLineNum)
	throws IOException {

	CompilerEnvirons env = new CompilerEnvirons();
	env.setRecoverFromErrors(true);
	env.setGenerateDebugInfo(true);
	env.setRecordingComments(true);

	StringReader strReader = new StringReader(src);

	IRFactory factory = new IRFactory(env);
	return factory.parse(strReader, null, startLineNum);

}

Continue reading “Understanding AST created by Mozilla Rhino parser”

Creating PhoneGap aware Web Browser

I wanted to create an application which I could use to run my other PhoneGap applications for testing, a kind of wrapper or shell application. When you are developing a PG application, you are changing you code frequently and running the application again and again in the emulator could be time consuming (actually it is very slow for Android, but iOS is quite fast).

So this week I create a PhoneGap application which can take a URL of my PhoneGap application hosted on my development server and run it. The shell application is like a regular web browser where you enter the URL to open the page. However you cannot execute PhoneGap applications in a regular mobile browser (such as Safari and Chrome) because PhoneGap specific native libraries are not available.

So I can now create my PhoneGap applications, deploy it on a web server and open the link in my PhoneGap shell application. If I modify the application, I just refresh the page in the shell application. So testing is faster.

Continue reading “Creating PhoneGap aware Web Browser”

In-place Editing in Eclipse TreeViewer

In an Eclipse RCP application I was working on recently, I had to implement a TreeViewer with in-place editing feature. It was not easy to find all the information required to implement this, so I thought I would explain it here.

First let’s take a simple example, where hierarchical data is displayed in  a tree.
tree_viewer1

When any item in the tree is double clicked, I want to edit the value in-place.

Here is the code to create this tree, without editing support. I will first create a data model using a Map. To simplify the example, I am assuming only one level of hierarchy.

Continue reading “In-place Editing in Eclipse TreeViewer”

Calling Objective-C code from JavaScript in iOS applications

In the last post I described how to Create iOS Application with HTML User Interface . In this post I am going to describe how to access Objective-C code from JavaScript running in the WebView. It is not as easy as it is in Android. There is no direct API in UIWebView to call native code, unlike in Android which provides WebView.addJavascriptInterface function.

However, there is a work-around. We can intercept each URL before it is being loaded in the WebView. So to call the native code, we will have to construct a URL and pass method name and argument as part of the URL. We then set this URL to window.location in the JavaScript and intercept it in our ViewController.
However most examples I have seen (including PhoneGap) create an instance of iframe and set its source to the URL –
Continue reading “Calling Objective-C code from JavaScript in iOS applications”

Creating iOS Application with HTML User Interface

Last year in April, I experimented with iOS development for the first time. I have described details in this post. I wanted to spend more time learning iOS application development then, however could not get around to actually doing that till very recently.

I had written a blog post on creating Android application using HTML user interface back in March last year. I was curious to know how to do the same in an iOS application.  In this post I will describe how to embed web view and set a URL in an iOS app and in the next post I would describe how to access native Objective-C code from JavaScript running in the web view control.

Continue reading “Creating iOS Application with HTML User Interface”

Get/Set local variables of JavaScript function from outside & Dynamic code insertion in JS function

I am working on a JavaScript framework that needs to get list of local function variables and set values of some of them. Unlike Java, JavaScript does not have runtime introspection
support. In Java you can do this using Java Reflection APIs, but I couldn’t think of any way to do this in JavaScript. So I searched on the web and came across two threads of discussions on StackOverflow –

There are some interesting solutions discussed in the above threads. The first one discusses solutions for setting local variable values. The second one interested me because I found the technique useful for injecting code (that will set local variable value) in a function.

Continue reading “Get/Set local variables of JavaScript function from outside & Dynamic code insertion in JS function”

Social