[antlr-interest] Debugging: how? (Why do I get MismatchedTokenException or UnwantedTokenException?) Unhelpful error messages.

Hendrik Maryns qwizv9b02 at sneakemail.com
Tue Oct 28 06:28:33 PDT 2008


Hi all,

I showed you my grammar yesterday.  Now trying it out on some simple
inputs blows me away right away: it doesn’t even parse anything.

For example, if I give “(word x Einführung)” as input to the rule
‘formula’, I get MismatchedTokenException (0!=0).  Strangely enough, I
do not think 0 is not equal to 0, but I have no idea what this is
supposed to tell me.

If I feed it to formulaList, I get an UnwantedTokenException followed by
an EOF, which doesn’t make me any wiser at this point.

Grateful for any suggestions,
H.

This is my current grammar:

grammar fsq;

options {
	language = Java;
	output=AST;
}

tokens {
// LISP
  OPEN = '[';
  CLOSE = ']';
// labels
  FUNCTION = 'fct';
  CATEGORY = 'cat';
  WORD = 'word';
  LEMMA = 'lemma';
  MORPHOLOGY = 'morph';

  SENTENCE = 'sent';
// atomic
  CONTAINMENT = 'in';
  EQUALITY = '=';
  PROPER_DOMINANCE = '>+';
  IMMEDIATE_DOMINANCE = '>';
  DOMINANCE = '>>';
  IMMEDIATE_PRECEDENCE = '.';
  PRECEDENCE = '..';
// unary
  NEGATION = '!';
// binary
  IMPLICATION = '->';
  EQUIVALENCE = '<->';
// n-ary
  DISJUNCTION = '|';
  CONJUNCTION = '&';
// quantification
  SECOND_ORDER_UNIVERSAL = 'A2';
  SECOND_ORDER_EXISTENTIAL = 'E2';
  FIRST_ORDER_UNIVERSAL = 'A1';
  FIRST_ORDER_EXISTENTIAL = 'E1';
}

@header { package de.uni_tuebingen.sfb.lichtenstein.formulas.parsing; }

@lexer::header { package
de.uni_tuebingen.sfb.lichtenstein.formulas.parsing; }

@members {
}

/*------------------------------------------------------------------
 * PARSER RULES
 *------------------------------------------------------------------*/

/**
 * One formula on each line.
 */
formulaList : ( formula )* EOF ;

/**
 * A formula is enclosed by braces.
 */
formula : OPEN body CLOSE ;

body : label | atomic | unary | binary | n_ary | quantor ;

// label formulas
label : labelHead VARIABLE LABEL ;

labelHead : FUNCTION | CATEGORY | WORD | LEMMA | MORPHOLOGY ;

// atomic relations
atomic : atomicHead VARIABLE VARIABLE ;

atomicHead : CONTAINMENT | EQUALITY | PROPER_DOMINANCE |
IMMEDIATE_DOMINANCE | DOMINANCE | IMMEDIATE_PRECEDENCE | PRECEDENCE ;

// unary junctors
unary : unaryHead formula ;

unaryHead : NEGATION ;

// binary junctors
binary : binaryHead formula formula ;

binaryHead : IMPLICATION | EQUIVALENCE ;

// n-ary junctors
n_ary : n_aryHead formula+ ;

n_aryHead : CONJUNCTION | DISJUNCTION ;

// quantors
quantor : quantorHead VARIABLE formula ;

quantorHead : FIRST_ORDER_EXISTENTIAL | FIRST_ORDER_UNIVERSAL |
SECOND_ORDER_EXISTENTIAL | SECOND_ORDER_UNIVERSAL ;

/*------------------------------------------------------------------
 * LEXER RULES
 *------------------------------------------------------------------*/

WHITESPACE  :  (' '|'\r'|'\t'|'\u000C'|'\n') {$channel=HIDDEN;}
    ;

COMMENT
    :   '/*' .* '*/' {$channel=HIDDEN;}
    ;
LINE_COMMENT
    : '//' ~('\n'|'\r')* '\r'? '\n' {$channel=HIDDEN;}
    ;

VARIABLE : ( DIGIT | LETTER )+ ;

fragment DIGIT  : '0'..'9' ;
fragment LETTER : LOWERCASE | UPPERCASE ;
fragment LOWERCASE : 'a'..'z' ;
fragment UPPERCASE : 'A'..'Z' ;

LABEL : ~(')')+ ;

-- 
Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
==================
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 257 bytes
Desc: OpenPGP digital signature
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20081028/6df7c8fa/attachment.bin 


More information about the antlr-interest mailing list