Hi all, I have a grammar here that is giving me a null pointer
exception when I try to use the ANTLR tool on it. It's too large, and
there's so much going on, that I don't know where to begin debugging
it. I assume I may have some common problem that I need to fix
throughout.

The grammar is based off the book here:
http://www.daimi.au.dk/~beta/Books/index.html#betabook_download

My (very straightforward) implementation of it is here:
http://paste-it.net/public/qac33be/

Here's the full text in case that link dies:

grammar Beta;
options {
    output=AST;
    ASTLabelType=CommonTree; // type of $stat.tree ref etc...
}

//BetaForm:   ( stat {System.out.println($stat.tree.toStringTree());} )+ ;
Beta:   ( BetaForm {System.out.println($BetaForm.tree.toStringTree());} )+ ;
BetaForm:       DescriptorForm
        |       AttributesForm
        ;
DescriptorForm
        :       ObjectDescriptor
        ;
AttributesForm
        :       Attributes
        ;
ObjectDescriptor
        :       SuperPatternOpt MainPart
        ;
MainPart:       '(#' Attributes ActionPart '#)'
        ;
Attributes
        :       (AttributeDeclOpt)+
        ;
SuperPatternOpt
        :       (SuperPattern)?
        ;
SuperPattern
        :       AttributeDenotation
        ;
AttributeDeclOpt:       (AttributeDecl)?
        ;
AttributeDecl
        :       PatternDecl
        |       SimpleDecl
        |       RepetitionDecl
    ;

PatternDecl
        :       Names ':' ObjectDescriptor -> Names ':' ObjectDescriptor
        ;

SimpleDecl
        :       Names ':' ReferenceSpecification -> Names ':' 
ReferenceSpecification
        ;

RepetitionDecl
        :       Names ':' '[' Index ']' ReferenceSpecification
        ;

ReferenceSpecification
        :       StaticItem
        |       DynamicItem
        |       StaticComponent
        |       DynamicComponent
        ;
StaticItem
        :       '@' ObjectSpecification -> '@' ObjectSpecification
        ;
DynamicItem
        :       '^' AttributeDenotation
        ;
StaticComponent
        :       '@'
        |       ObjectSpecification
        ;
DynamicComponent
        :       '^'
        |       AttributeDenotation
        ;
ObjectSpecification
        :       ObjectDescriptor
        |       AttributeDenotation
        ;
Index   :       SimpleIndex
        |       NamedIndex
        ;
NamedIndex
        :       NameDcl ':' Evaluation
        ;
ActionPart
        :       EnterPartOpt DoPartOpt ExitPartOpt
        ;
EnterPartOpt
        :       (EnterPart)?
        ;
EnterPart
        :       'enter' Evaluation
        ;
DoPartOpt
        :       (DoPart)?
        ;
DoPart  :       'do' Imperatives
        ;
ExitPartOpt
        :       (ExitPart)?
        ;
ExitPart:       'exit' Evaluation;
Imperatives
        :       (ImpOpt ';')+
        ;
ImpOpt  :       (Imp)?
        ;
Imp     :       LabelledImp
        |       LabelledCompoundImp
        |       ForImp
        |       IfImp
        |       LeaveImp
        |       RestartImp
        |       InnerImp
        |       SuspendImp
        |       Evaluation
        ;
LabelledImp
        :       NameDcl ':' Imp
        ;
LabelledCompoundImp
        :       '(' NameDcl Imperatives NameDcl ')'
        ;
ForImp  :       '(for' Index 'repeat' Imperatives 'for)'
        ;
IfImp   :       '(if' Evaluation Alternatives ElsePartOpt 'if)'
        ;
Alternatives
        :       (Alternative)+
        ;
Alternative
        :       Selections 'then' Imperatives
        ;
Selections
        :       Selection
        ;
Selection
        :       CaseSelection
        ;
CaseSelection
        :       '//' Evaluation
        ;
ElsePartOpt
        :       (ElsePart)?
        ;
ElsePart:       'else' Imperatives
        ;
LeaveImp:       'leave' NameApl
        ;
RestartImp
        :       'restart' NameApl
        ;
InnerImp:       'inner' NameAplOpt
        ;
NameAplOpt
        :       (NameApl)?
        ;
SuspendImp
        :       'suspend'
        ;
Evaluations
        :       (Evaluation ',')+
        ;
Evaluation
        :       Expression
        |       AssignmentEvaluation
        ;
AssignmentEvaluation
        :       Evaluation '->' Transaction
        ;
Transaction
        :       ObjectEvaluation
        |       ComputedObjectEvaluation
        |       ObjectReference
        |       EvalList
        |       StructureReference
        ;
ObjectEvaluation
        :       InsertedItem
        |       Reference
        ;
Reference
        :       ObjectDenotation
        |       DynamicObjectGeneration
        ;
DynamicObjectGeneration
        :       DynamicItemGeneration
        |       DynamicComponentGeneration
        ;
InsertedItem
        :       ObjectDescriptor
        ;
ObjectDenotation
        :       AttributeDenotation
        ;
ComputedObjectEvaluation
        :       ObjectEvaluation '!'
        ;
ObjectReference
        :       Reference '[]'
        ;
StructureReference
        :       AttributeDenotation '##'
        ;
EvalList:       '(' Evaluations ')'
        ;
DynamicItemGeneration
        :       '&' ObjectSpecification
        ;
DynamicComponentGeneration
        :       '&' | ObjectSpecification;
AttributeDenotation
        :       NameApl
        |       Remote
        |       ComputedRemote
        |       Indexed
        |       ThisObject
        ;
Remote  :       AttributeDenotation '.' NameApl
        ;
ComputedRemote
        :       '(' Evaluations ')' '.' NameApl
        ;
Indexed :       AttributeDenotation '[' Evaluation ']'
        ;
ThisObject
        :       'this' '(' NameApl ')'
        ;
Expression
        :       RelationalExpr
        |       SimpleExp
        ;
RelationalExpr
        :       EqExp
        |       LtExp
        |       LeExp
        |       GtExp
        |       GeExp
        |       NeExp
        ;
SimpleExp
        :       AddExp
        |       SignedTerm
        |       Term
        ;
AddExp  :       PlusExp
        |       MinusExp
        |       OrExp
        ;
SignedTerm
        :       UnaryPlusExp
        |       UnaryMinusExp
        ;
Term    :       MulExp
        |       Factor
        ;
MulExp  :       TimesExp
        |       DivExp
        |       ModExp
        |       AndExp
        ;
EqExp   :       SimpleExp '=' SimpleExp;
LtExp   :       SimpleExp '<' SimpleExp;
LeExp   :       SimpleExp '<=' SimpleExp;
GtExp   :       SimpleExp '>' SimpleExp;
GeExp   :       SimpleExp '>=' SimpleExp;
NeExp   :       SimpleExp '<>' SimpleExp;
PlusExp :       SimpleExp '+' Term;
MinusExp:       SimpleExp '-' Term;
OrExp   :       SimpleExp 'or' Term;
UnaryPlusExp
        :       '+' Term;
UnaryMinusExp
        :       '-' Term;
TimesExp:       Term '*' Factor;
DivExp  :       Term 'div' Factor;
ModExp  :       Term 'mod' Factor;
AndExp  :       Term 'and' Factor;
Factor  :       TextConst
        |       IntegerConst
        |       NotExp
        |       NoneExp
        |       RepetitionSlice
        |       Transaction
        ;
RepetitionSlice
        :       AttributeDenotation '[' Evaluation ':' Evaluation ']'
        ;
NotExp  :       'not' Factor;
NoneExp :       'none';
Names   :       (NameDcl)+;
NameDcl :       NameDecl;
NameApl :       NameAppl;
SimpleEntry
        :       (TextConst)?
        ;
TextConst
        :       String
        ;
IntegerConst
        :       Int
        ;
SimpleIndex
        :       Evaluation
        ;
NameAppl:       NameDecl;
NameDecl:       (Letter|'_')+(Digit|Letter|'_')*
        ;

String  :       '\''Char*'\''
        ;
//           where <char> can be any char except "'" and newline.
//                        "'" are allowed in <String>, iff preceeded with "\".
//                        "\n", "\t", etc. are allowed in <String> to
//                        represent non-printable chars - see Compiler
//                        manual (mia91-02) for details.

Const   :       (Int|Based)//|Real)
        ;
//        where
Int     :        (Digit)+
        ;
Based   :       Int('X'|'x')BasedNum
        ;
BasedNum:       (Digit|Letter)+
        ;
//Real  :       Int['.' Int][('E'|'e')[('+'|'-')]Int]
//      ;

Letter  :       'a'..'z'|'A'..'Z'
        ;
Digit   :       '0'..'9'
        ;
Char    :       
'0'..'9'|'a'..'z'|'A'..'Z'|'!'|'@'|'#'|'$'|'%'|'^'|'&'|'*'|'('|')'|'-'|'='|'_'|'+'|'['|']'|'{'|'}'|'|'|'\\'|';'|':'|'\''|'<'|'>'|','|'.'|'/'|'?'
        ;
        
WS  :   (' '|'\t'|'\r'|'\n')+ {skip();} ;

Sincere thanks for any tips,

Kyle

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to