[DL_PARSER] Going menhir and weighted latent-annotated Datalog
I think I want to settle the syntax for weighted latent-annotated Datalog as follows:
w::A0[h0](...) :- A1[h1](...), ..., An[hn](...).
Typing in a weight w
or a state h
would be optional.
Also, we could keep the arity hint with the slash; preferably closer to the predicate symbol than after the state (so A/n[h]
).
Looking at menhir
documentation, I draft the following .mly
where semantic actions are missing for the moment.
%token <int> WEIGHT
%token DBLCOL
%token <string> PRED
%token SLASH
%token <int> ARITY
%token LBRA
%token <int> STATE
%token RBRA
%token LPAR
%token <string> VAR
%token COMMA
%token <int> CONST
%token RPAR
%token FROM
%token DOT
%token EOI
%token QUEST
%start program
%%
program:
| EOI
| fact; program
| rule; program
;
rule:
| (~=weight; DBLCOL)?;
head=atom;
FROM; body=separated_list(COMMA, atom);
DOT
;
atom: p=PRED; (SLASH; n=ARITY)?; (LBRA; q=STATE; RBRA)?; LPAR; param=separated_list(COMMA, term); RPAR
;
term:
| ~=VAR
| ~=CONST
;
edb: edb=(fact*); EOI
;
fact: p=PRED; (SLASH; n=ARITY)?; (LBRA; q=STATE; RBRA)?; LPAR; param=separated_list(COMMA, CONST); RPAR
;
query: atom; QUEST
;