Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: sanpie
Fetching contributors…

Cannot retrieve contributors at this time

184 lines (142 sloc) 4.448 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 <string> BOOLPRED /* token with string value */
%token QMARK DOT IMPLIEDBY
%token AND NOT ANON_VAR
%token SELECT JOIN WHERE WHERENOT UNION ISODD ISEVEN /*token for help parameters*/
%token EQ LE GR LQ GQ NE
%token LPAREN RPAREN SEP
%token EOP
%token ANON /* fake token to stop the grammar in the fact rule */
%token TESTCOMM RECONNECT QUITCOMM CHANGEOUT READSCR HELPCOMM UNKNOWNCOMM TABINFOCOMM GETTABLECOMM GETDBCOMM
%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 "Empty command or query!"}
| 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*/
| CHANGEOUT file_name { ChangeOutComm $2 }
| READSCR file_name { ReadScriptComm $2 }
| QUITCOMM { QuitCommand }
| UNKNOWNCOMM { UnknownCommand }
| GETTABLECOMM { GettablesCommand }
| GETDBCOMM { GetdbCommand }
| HELPCOMM help_param { HelpCommand $2 }
| TABINFOCOMM VARNAME { TabinfoCommand $2} /*table name*/
;
help_param:
| SELECT { Select }
| JOIN { Join }
| WHERE { Where }
| WHERENOT { WhereNot }
| ISODD { IsOdd }
| ISEVEN { IsEven }
| VARNAME { Other }
;
file_name:
| reconn_param DOT reconn_param { $1 ^ "." ^ $3 }
| reconn_param { $1 }
reconn_param:
| ANYNAME { $1 }
| RELNAME { $1 }
| VARNAME { $1 }
;
pass_param:
| ANYNAME { $1 }
| RELNAME { $1 }
| VARNAME { $1 }
| PASSNAME { $1 }
| BOOLPRED { $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:
| bodypredicate { Rel $1 }
| NOT bodypredicate { Not (Rel $2) }
| comparison { $1 }
| NOT comparison { Not $2 }
| booleanpredicate { $1 }
| NOT booleanpredicate { Not $2 }
;
predicate:
RELNAME LPAREN termlist RPAREN { Pred ($1, $3) }
;
bodypredicate:
RELNAME LPAREN bodytermlist RPAREN { Pred ($1, $3) }
;
booleanpredicate:
BOOLPRED LPAREN termlist RPAREN { BPred ($1, $3) }
;
comparison:
term compsym term { Comp ($1, $2, $3) }
;
compsym:
| LE { "<" }
| GR { ">" }
| LQ { "<=" }
| GQ { ">=" }
| NE { "<>" }
| EQ { "=" }
;
termlist: /* empty */ { [] }
| term { $1 :: [] }
| term SEP termlist { $1 :: $3 } /* \!/ rec. on the right */
bodytermlist: /* empty */ { [] }
| bodyterm { $1 :: [] }
| bodyterm SEP bodytermlist { $1 :: $3 } /* \!/ rec. on the right */
term:
| VARNAME { ParamS $1 }
| VAL { ParamI $1 }
bodyterm:
| VARNAME { ParamS $1 }
| VAL { ParamI $1 }
| ANON_VAR { ParamS "_ANONVAR_" }
Jump to Line
Something went wrong with that request. Please try again.