[antlr-interest] Bison-> Antlr 3 help

Jim Idle jimi at intersystems.com
Fri Oct 20 08:33:24 PDT 2006


The heap space is a n issue on larger grammars and there are some issues with it getting bigger and bigger etc. However, I am sure these will go away over time. 

In order to circumvent the error (but not the memory use ;-), I start works with:

java.exe -Xmx1000M ...

It is really useful for graphically seeing why your grammar has ambiguities that need various additions to solve them.

As a rule of thumb, do this:

1) See if you can think of a way to express the formation without needing to parse ahead in some way (write it such that the minimum number of tokens are required to distinguish one rule from another);
2) After doing 1, if you still have ambiguities, then you need to start adding predicates of one sort or another, preferably again with the minimum number of tokens in the predicate to make a decision.

Using your grammar, we can take:

add_column_clause_ss :
	table_element_ss
	(BEFORE identifier)?
	;

This has ambiguity because the BEFORE should always belong to table_element_ss but can also be skipped and BEFORE used as an indentifer it seems (works will show you the circuitous route by which this can happen).

So, it seems first that you need to solve the identifier issues perhaps, but you can solve this particular issue by:

add_column_clause_ss :
	table_element_ss
	( options {k=1;} : (BEFORE)=>(BEFORE identifier))?
	;

Now, remember that I have not looked at the grammar itself to see if you could formulate this differently by left factoring other rules and so on, which is better if you can do it. You could also turn on backtracking, which might help this complex grammar. You have quite a lot of contructs that complain about recursive calls for instance. k options might deal with these.

Your lexer also complains that it cannot reach many of your tokens. IN many cases this seems to be because you are trying to construct the parser within the lexer:

CLOSE_SESSION:
       'CLOSE' 'SESSION'
     ;

This is really just looking for one word 'CLOSESESSION'. You need to make the lexer rules much simpler placing the keywords and string definitions and identifiers etc in the order in which they should be seen. So the Id rule probably comes after your keywords, which would otherwise clash with the ID rule.


Then you have a parser rule:

close_session:

	CLOSE SESSION ;

Solving any ambiguities there.

I hope this helps to put you on the right track?

Jim







-----Original Message-----
From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Terence Parr
Sent: Thursday, October 19, 2006 9:54 AM
To: ANTLR Interest
Subject: Re: [antlr-interest] Bison-> Antlr 3 help


On Oct 19, 2006, at 9:48 AM, Mike Aubury wrote:

> yeah...
> it runs out of heap space :) - but apart from that - it  
> (antlrworks) looks like a great tool for grammar development...

I run from command line with more ram and it's cool.  ANTLR is a  
pig ;)  'course so is swing.

> I could really do with knowing whats actually wrong and whats  
> needed to fix it.

Try more ram.
Ter

-- 
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.408 / Virus Database: 268.13.8/489 - Release Date: 10/20/2006
 

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.408 / Virus Database: 268.13.8/489 - Release Date: 10/20/2006
 


More information about the antlr-interest mailing list