[antlr-interest] Grammar for Predicate Logic (FOL)

Eric researcher0x00 at gmail.com
Fri Apr 20 09:21:06 PDT 2012


Hi Stephan,


Have you looked at other FOL grammars on the internet?

i.e. https://www.cs.uiowa.edu/~hzhang/c145/notes/08a-fol-4p.pdf

or 140.122.185.120/.../AI2008-Lecture10-First-Order%20Logic.pdf

As a suggestion, you might want to design and test the engine then
concentrate on the grammar. If you start on the grammar you may be tempted
to modify the engine to accommodate the grammar. IMHO the grammar should
accommodate the engine.

Eric


On Fri, Apr 20, 2012 at 10:37 AM, Stephan Opfer <stephan.opfer at gmx.net>wrote:

> Hi,
>
> I think I created a grammar, which accepts prepositional logic and first
> order logic. the only problem I see at the moment, is that quantifiers
> are not the parent, but siblings of their scope.
>
> I have an example input:
>
> Exists ?x (Forall ?y Check(?y) & HasRelation(?x, ?y)) & (Exists ?y
> NoCheck(?y) & HasNoRelation(?x, ?y))<EOF>
>
> Exists ?x is a sibling of the & between the parenthesed formulas, but I
> want ?x to be parent of this &. The problem is at the second alternative
> of the element rule. Here is the grammar:
>
> grammar FOLFUL;
>
> options{
>        language=Java;
>         output=AST;
> }
>
> tokens{
>        LPAREN='(';
>        RPAREN= ')';
>        AND= '&';
>        OR= '|';
>        NOT= '!';
>         FORALL= 'Forall';
>        EXISTS= 'Exists';
> }
>
>
> /*------------------------------------------------------------------
>  * PARSER RULES
>  *------------------------------------------------------------------*/
>
> condition: formula EOF!;
>
> formula: conjunction (OR^ conjunction)*;
>
> conjunction: element (AND^ element)*;
>
> element : NOT^? atom
>        | NOT^? quantifier formula
>        | NOT^? LPAREN! formula RPAREN!
>        ;
>
> quantifier : (FORALL^ | EXISTS^) VARIABLE;
>
> atom    : PREPOSITION^ tuple?;
>
> tuple   : LPAREN! (CONSTANT | VARIABLE) (','!(CONSTANT | VARIABLE))*
> RPAREN! ;
>
>
> /*------------------------------------------------------------------
>  * LEXER RULES
>  *------------------------------------------------------------------*/
>
> VARIABLE: '?' (('a'..'z') | ('0'..'9')) CHARACTER*;
>
> CONSTANT: (('a'..'z') | ('0'..'9')) CHARACTER*;
>
> PREPOSITION: ('A'..'Z') CHARACTER*;
>
> CHARACTER: ('0'..'9' | 'a'..'z' | 'A'..'Z' | '_');
>
> WS : (' ' | '\t' | '\r' | '\n')+ {$channel = HIDDEN;};
>
> Best Regards,
>  Stephan
>
>
>
> On 04/19/2012 11:37 PM, Stephan Opfer wrote:
> > Oh! Thanks Jim! That was easy :)
> >
> > On 04/19/2012 11:16 PM, Jim Idle wrote:
> >> language=Java; // Case sensitive.
> >>
> >> Jim
> >>
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>


More information about the antlr-interest mailing list