Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: 005d78573d
Fetching contributors…

Cannot retrieve contributors at this time

127 lines (95 sloc) 2.791 kB
/* ADB Project. Datalog intepreter. */
/* Source: X. Leroy, J. Cohen and G. Raschia */
%{ (* OCaml preamble *)
open Expr ;;
(* end preamble *)
%}
/* tokens declaration */
%token <int> VAL /* token with int value */
%token <string> RELNAME /* token with string value */
%token <string> VARNAME /* token with string value */
%token QMARK DOT IMPLIEDBY
%token AND NOT
%token EQ
%token LPAREN RPAREN SEP
%token EOP
%token ANON /* fake token to stop the grammar in the fact rule */
%token TESTCOMM RECONNECT QUITCOMM UNKNOWNCOMM
%token <string> ANYNAME /* mytoken with string value */
%token <string> PASSNAME /* mytoken with string value */
/* associativity and precedence when needed */
%nonassoc IMPLIEDBY
%start main /* entry point */
%type <Expr.expr> main
%%
/* Grammar */
main: EOP { failwith "main: where's my program?!"}
| program EOP { Prog $1 }
| commlist EOP { Comm $1 }
;
program:
| exprlist { $1 }
;
commlist:
| command { $1 (*:: [] *) }
/* | commlist command { $2 :: $1 } */
;
exprlist:
| expr { $1 :: [] }
| exprlist expr { $2 :: $1 }
;
expr:
| rule { $1 }
| query { $1 }
| fact { failwith "fact: to be implemented" }
;
command:
| TESTCOMM RELNAME { TestComm $2 }
| RECONNECT reconn_param VAL reconn_param pass_param reconn_param { ReconnComm ($2,$3,$4,$5,$6) } /* host port user password db_name*/
| QUITCOMM { QuitCommand }
| UNKNOWNCOMM { UnknownCommand }
;
reconn_param:
| ANYNAME { $1 }
| RELNAME { $1 }
| VARNAME { $1 }
;
pass_param:
| ANYNAME { $1 }
| RELNAME { $1 }
| VARNAME { $1 }
| PASSNAME { $1 }
;
fact: ANON { }
rule:
head IMPLIEDBY body DOT { Rule ($1,$3) }
;
head:
predicate { $1 }
;
body:
litlist { $1 }
;
query:
| QMARK predicate DOT { Query $2 }
;
litlist: /* empty */ { [] }
| literal { $1 :: [] }
| litlist AND literal { $3 :: $1 }
;
literal:
| predicate { Rel $1 }
| NOT predicate { Not (Rel $2) }
| equality { $1 }
| NOT equality { Not $2 }
;
predicate:
RELNAME LPAREN termlist RPAREN { Pred ($1, $3) }
;
equality:
VARNAME EQ VAL { Equal ($1, $3) }
termlist: /* empty */ { [] }
| term { $1 :: [] }
| term SEP termlist { $1 :: $3 } /* \!/ rec. on the right */
term:
VARNAME { $1 }
Jump to Line
Something went wrong with that request. Please try again.