Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Added exception trapping section

...

...

ANTLR

C# Syntax

Notes

text

Text

 

start

Start


stop

Stop

 

tree

Tree


st

ST

 

type

Type


line

Line


pos

CharPositionInLine


channel

Channel


$x.size()

$x.Count

size() is no grammar attribute, but still regularly used

Known Issues

Wrong Default Initialization

A problem, you may encounter while using the CSharp target, is that value types are initialized with null in the generated code (happens e.g. while using labels). The cause lies in the following definition of CSharp.stg:

...

As you can see, only the in-built value types are supported (or can be reasonably supported). Since adding value types to this map is an open-ended task, the maintainer does not make any changes in that structure for all users. Any changes have to be done by the user locally (and repeatedly for each new version of ANTLR). It is recommend that users switch to the CSharp2 target (which requires C# v2+ and .NET v2.0 or higher) as the problem has been fixed there in an environment-independent manner.

Exceptions not trapped in Visual Studio

Shawn Poulson noticed that while debugging in VS, exceptions generated in the ANTLR runtime were not trapped by a catch for all Exceptions. He discovered that this is actually a byproduct of a default profile setting in Visual Studio 2005 and 2008. There is a feature that allows you to break on exceptions thrown and handled, regardless if there is a handler to catch the exception and tell you it was unhandled anyway. He found some discussion about this at this page.

This behavior can be disabled two ways:

  • Go to Tools|Options|Debugging|General and uncheck "Enable Just My Code"
  • Go to Debugger|Exceptions and uncheck "User-handled" in the CLR row

He was also missing the Debugger|Exceptions menu item, which has been fixed by adjusting the profile, which had this option disabled by default. This shown here. Once this was sorted out, ANTLR works perfectly when parsing invalid parser/lexer input.

Debugging with ANTLRWorks

...