[antlr-interest] Question on embedding other languages (grammars)

Jim Idle jimi at temporal-wave.com
Sun Jun 24 21:00:44 PDT 2012

Look up "Island grammars" and follow the example in the downloadable
examples. That should get you going.


-----Original Message-----
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Dean Sheehan
Sent: Monday, June 25, 2012 1:56 AM
To: antlr-interest at antlr.org
Subject: [antlr-interest] Question on embedding other languages (grammars)

Hi ANTLR Interest,

I was wondering how I would go about embedding one language within

For example, if I have a grammar developed for language X but I want to be
able to embed segments of another language that I do not want to be parsed
or processed by ANTLR at this stage, basically just receive a string of
unprocessed text for passing off to something else to look at, how might I
go about that?

Consider the classic case of wanting to embedded some SQL in a piece of
Javav code (just an example). I have the grammar for Java and all of the
parsing and processing behind that but I also have a SQL interpreter. I
want to be able to write something like:

void foo ( ) {
	int a = 5;
	sql {
		insert into table x ...
	} sql

The 'sql {' and '} sql' start and end tokens would be part of the
'extended' Java grammar but the stuff between is just text that I want to
extract to pass off to a SQL interpreter.

Obviously I could do simple things like define a grammar than has 'sql {'
STRING '} sql' but that wouldn't account for the STRING having newlines,
white space etc.

Thanks for any pointers.

- Dean

List: http://www.antlr.org/mailman/listinfo/antlr-interest

More information about the antlr-interest mailing list