[antlr-interest] Grammar for Predicate Logic (FOL)
Stephan Opfer
stephan.opfer at gmx.net
Thu Apr 19 13:41:16 PDT 2012
Hi ANTLR Community,
I need a grammar for first order logic fomulas. I thought I could find
one on the antlr website, but I didnt. So now I started to write one by
myself and got some errors by antlrworks (version 1.4.3, java openjdk7):
[22:39:03] error(10): internal error: /home/user/Desktop/FOL.g :
java.lang.IllegalArgumentException: No such group file:
org/antlr/codegen/templates/java/java.stg
org.stringtemplate.v4.STGroupFile.<init>(STGroupFile.java:69)
org.stringtemplate.v4.STGroupFile.<init>(STGroupFile.java:48)
org.antlr.codegen.CodeGenerator.loadTemplates(CodeGenerator.java:186)
org.antlr.codegen.CodeGenerator.genRecognizer(CodeGenerator.java:283)
org.antlr.Tool.generateRecognizer(Tool.java:655)
org.antlr.Tool.process(Tool.java:468)
org.antlr.works.generate.CodeGenerate.generate(CodeGenerate.java:104)
org.antlr.works.debugger.local.DBLocal.generateGrammar(DBLocal.java:398)
org.antlr.works.debugger.local.DBLocal.generateAndCompileGrammar(DBLocal.java:372)
org.antlr.works.debugger.local.DBLocal.run(DBLocal.java:222)
java.lang.Thread.run(Thread.java:722)
My first order grammar should support everything except quantifiers:
grammar FOL;
options{
language=java;
output=AST;
}
tokens{
LPAREN='(';
RPAREN= ')';
AND= '&';
OR= '|';
NOT= '!';
}
/*------------------------------------------------------------------
* PARSER RULES
*------------------------------------------------------------------*/
condition: formula EOF!;
formula: disjunction (AND^ disjunction)*;
disjunction: element (OR^ element)*;
element : predicate
| NOT^? LPAREN! formula RPAREN!
;
predicate
: ID TUPLE
| NOT^ ID TUPLE
| CONSTANT
| NOT^ CONSTANT;
/*------------------------------------------------------------------
* LEXER RULES
*------------------------------------------------------------------*/
VARIABLE: '?' CHARACTER+;
CONSTANT: ('a'..'z') CHARACTER*;
ID: ('A'..'Z') CHARACTER*;
TUPLE: LPAREN (CONSTANT | VARIABLE) (','(CONSTANT | VARIABLE))* RPAREN;
CHARACTER: ('0'..'9' | 'a'..'z' | 'A'..'Z' | '_');
WS : (' ' | '\t' | '\r' | '\n')+ {$channel = HIDDEN;};
Do someone have a clue, why I get this error? I would provide this
grammar to the community, if it is finished.
Best Regards,
Stephan
More information about the antlr-interest
mailing list