Skip to content

Commit

Permalink
the first and the most simple step in enhancing BGF to work with Bool…
Browse files Browse the repository at this point in the history
…ean grammars: changing the BGF grammar in Rascal
  • Loading branch information
grammarware committed Dec 23, 2012
1 parent 08157f2 commit 6983851
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 7 additions & 1 deletion shared/rascal/src/normal/BGF.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public list[BGFProduction] normalise([L1*,BGFProduction X1,L2*,X1,L3*])
public list[BGFProduction] normalise(list[BGFProduction] prods)
= [normalise(p) | p <- prods];

// the following is kinda useful, but breaks some code if normalisations are not done after each step
// the following is very useful, but breaks some code if normalisations are not done after each step
public BGFProduction normalise(production ("", str lhs, selectable(str label,BGFExpression rhs)))
= production (label, lhs, normalise(rhs));

Expand All @@ -34,6 +34,7 @@ public BGFExpression normalise(BGFExpression e)
case choice([]) => empty()
case choice([BGFExpression e]) => e
case optional(epsilon()) => epsilon()
case optional(empty()) => epsilon() // not present in Prolog
case plus(epsilon()) => epsilon()
case star(epsilon()) => epsilon()
case sepliststar(X,epsilon()) => star(X)
Expand All @@ -46,6 +47,11 @@ public BGFExpression normalise(BGFExpression e)
case choice([L1*,choice(L),L2*]) => choice(L1+L+L2)
case choice([L1*,empty(),L2*]) => choice(L1+L2)
case choice([L1*,X1,L2*,X1,L3*]) => choice([*L1,X1,*L2,*L3])
// normalisations on Boolean grammars
case all([L1*,all(L),L2*]) => all(L1+L+L2)
case all([L1*,anything(),L2*]) => all(L1+L2)
case all([L1*,X1,L2*,X1,L3*]) => all([*L1,X1,*L2,*L3])
case all([L1*,empty(),L2*]) => empty()
};
}

Expand Down
2 changes: 2 additions & 0 deletions shared/rascal/src/syntax/BGF.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ data BGFExpression =
| selectable(str selector, BGFExpression expr)
| sequence(BGFExprList exprs)
| choice(BGFExprList exprs)
| all(BGFExprList exprs) // to cover conjunctive grammars
| marked(BGFExpression expr)
| optional(BGFExpression expr)
| not(BGFExpression expr) // to cover Boolean grammars
| plus(BGFExpression expr)
| star(BGFExpression expr)
| seplistplus(BGFExpression expr, BGFExpression sep)
Expand Down

0 comments on commit 6983851

Please sign in to comment.