[antlr-interest] problem with parsing valid input
OJAY78 at gmx.de
OJAY78 at gmx.de
Fri Oct 5 01:19:08 PDT 2007
Hallo @ all,
I working on a small domain specific language with antlr but now I stuck and do not know how I can solve this problem.
I defined the lexer tokens and my grammar without any action because I want to test first if any input is valid, there I stuck now.
First you have to know what I want to have.
My DSL should handle boolean expression which are combined with and, or , not and xor.
The funcions should have a given structure
' '* COMMAND_TYPE ' '* '(' ' '* PARAMETER_LIST ' '* ')'
for the beginning I have three command types which I want to implement but I think that
the language is easy extendablewith this structure . The language should be able to
answer such a request
not(IsSet(value,Ftddmmyy) and not IsSet(value,RaftInternal.2))
but there I get a EarlyException.
So I tried the following input
IsSet(value,Ftddmmyy)
with the interpreter of ANTLRWorks. When I started the interpreter at the prog rule it returns a FailedPredicateException only when
I start the interpreter at the rule primaryexception or function it will show the correct tree.
On the rule term it returns the FailedPrediacteException(term,(synpred5)?)
Does anyone see where my problem is?
I am thankful for every advise
Here is my grammar:
grammar FEL;
options {
backtrack=true;
memooize=true;
greedy=false;
}
@header {
import java.util.HashMap;
import de.srs.pen.dao.base.*;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Session;
import de.srs.pen.dao.DAOSessionFactory;
import org.apache.log4j.Logger;
}
@members {
HashMap memory = new HashMap();
private static Logger log = Logger.getLogger(FELParser.class);
private FormInstance formInstance;
public void setInstance(FormInstance instance) {
formInstance = instance;
}
}
@rulecatch{
catch (RecognitionException er){
throw er;
}
}
//lexer
COMMAND_TYPE
: ISSET | ISEQUAL | ISSMALLER
;
PARAMETER_LIST_SEP_CHAR
: ' '
;
PARAMETER_SEP_CHAR
: ','
;
ALPHA_NO_SPACE_NO_QUOT
: CHAR+
;
ATTRIB_DESC_TYPE
: 'instattrib' | 'formattrib'
;
INSTANCE_ATTRIBUTE
: 'instanceId' |'instanceKey' | 'firstpenId' | 'lastpenId' | 'lastUpdate' | 'started'
;
FORM_ATTRIBUTE
: 'formId' |'formKey' | 'lastUpdate'
;
META_ATTRIBUTE
: 'date' | 'datetime'
;
ISSET: 'IsSet';
ISEQUAL : 'IsEqual';
ISSMALLER: 'IsSmaller';
AND : ('and');
OR : ('or');
XOR : ('xor');
NOT : ('not');
FLOAT
: ('0'..'9')+ '.' ('0'..'9')+
;
INTEGER
: ('0'..'9')+
;
CHAR : ('a'..'z'|'A'..'Z'|'0'..'9'|'_'|'.'|','|'+'|'-'|'#'|'@');
WS : (' '|'\t'|'\n'|'\r')+ {skip();}
;
COMMAND
: ' '* COMMAND_TYPE ' '* '(' ' '* PARAMETER_LIST ' '* ')'
;
PARAMETER_LIST
: PARAMETER (' '+ PARAMETER)* ' '*
;
PARAMETER
: PARAMETER_DESC | CONST_DESC
;
PARAMETER_DESC
: VALUE_DESC | ATTRIB_DESC | INSTANCE_DESC | FORM_DESC | META_DESC
;
VALUE_DESC
: VALUE_CMD PARAMETER_SEP_CHAR VALUE_NAME
;
VALUE_CMD
: 'value'
;
VALUE_NAME
: ALPHA_NO_SPACE_NO_QUOT | STRING_CONST;
ATTRIB_DESC
: ATTRIB_DESC_TYPE PARAMETER_SEP_CHAR ATTRIB_DESC_PARAM
;
ATTRIB_DESC_PARAM
: MODULE_ID'#'ATTRIB_NAME
;
MODULE_ID
: MODULE_NAME_CHARS | STRING_CONST
;
ATTRIB_NAME
: ATTRIB_NAME_CHARS | STRING_CONST
;
MODULE_NAME_CHARS
: ('a'..'z' | 'A'..'Z' | '0'..'9' | '_' | '-' )+
;
ATTRIB_NAME_CHARS
: MODULE_NAME_CHARS
;
INSTANCE_DESC
: 'instance' PARAMETER_SEP_CHAR INSTANCE_ATTRIBUTE
;
FORM_DESC
: 'form' PARAMETER_SEP_CHAR FORM_ATTRIBUTE
;
META_DESC
: 'meta' PARAMETER_SEP_CHAR META_ATTRIBUTE
;
CONST_DESC
: STRING_CONST | NUMERIC_CONST ;
STRING_CONST
: '"' ( CHAR | '\\'('"' | '\\'))* '"'
;
NUMERIC_CONST
: INTEGER | FLOAT
;
//TODO für jede Aktion die Java Actions definieren
prog
: stat+
;
stat
: expr ( OR expr | XOR expr )*
;
expr
: term (AND term)*
;
term
: primaryexpr
|NOT primaryexpr
;
primaryexpr
: '(' stat ')' | function
;
function
: COMMAND
;
--
GMX FreeMail: 1 GB Postfach, 5 E-Mail-Adressen, 10 Free SMS.
Alle Infos und kostenlose Anmeldung: http://www.gmx.net/de/go/freemail
--
Psssst! Schon vom neuen GMX MultiMessenger gehört?
Der kanns mit allen: http://www.gmx.net/de/go/multimessenger
More information about the antlr-interest
mailing list