Skip to content

Commit

Permalink
Working on the syntax chapter of the slbook
Browse files Browse the repository at this point in the history
  • Loading branch information
rlaemmel committed Dec 29, 2014
1 parent c9d5f65 commit 7718cdd
Show file tree
Hide file tree
Showing 68 changed files with 381 additions and 280 deletions.
10 changes: 6 additions & 4 deletions docs/fsml/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ssh-user = [email protected]
www-dir = /home/softlang/www/slepro
www-dir = /home/softlang/www

paper.pdf: *.tex *.bib Makefile *.sty
# pdflatex paper
Expand All @@ -11,11 +11,13 @@ clean:
rm -f *.pdf *.toc *.blg *.bbl *.log *.aux *.dvi *.ps *.out *.spl

upload: create-webdir
scp -r -p paper.pdf ${ssh-user}:${www-dir}/fsml.pdf
scp -r -p paper.pdf ${ssh-user}:${www-dir}/slepro/fsml.pdf
make upload-html

upload-html:
# scp -r -p index.html ${ssh-user}:${www-dir}
scp -r -p index.html ${ssh-user}:${www-dir}/fsml

create-webdir:
ssh ${ssh-user} mkdir -p ${www-dir}
ssh ${ssh-user} mkdir -p ${www-dir}/fsml
ssh ${ssh-user} mkdir -p ${www-dir}/slepro

54 changes: 54 additions & 0 deletions docs/fsml/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0"?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<title>Model of a DSL for finite state machines</title>
</head>
<body bgcolor="#99CCFF">
<H1>Model of a DSL for finite state machines</H1>
<dl>
<dt>
<strong>Status</strong>
</dt>
<dd>Published online since October 2013</dd>
<p/>
<dt>
<strong>Author</strong>
</dt>
<dd> <a
href="http://www.uni-koblenz.de/~laemmel/">Ralf
L&#xE4;mmel</a></dd>
<p/>

<dt>
<strong>Downloads and links</strong>
</dt>
<dd>
<ul>
<li> <strong>Published paper: <a href="../slepro/fsml.pdf">[.pdf]</a></strong> </li>
<li> <strong>Paper repo: <a href="https://github.com/slebok/slepro/tree/master/docs/fsml">[GitHub]</a></strong> </li>
<li> <strong>FSML model: <a href="https://github.com/slebok/slepro/tree/master/languages/fsml">[GitHub]</a></strong> </li>
<li> <strong>Python-based FSML
implementation: <a href="https://github.com/slecourse/slecourse/tree/master/projects/fsmlPython">[GitHub]</a></strong> </li>

</ul>
</dd>

<dt>
<strong> Bibtex entry </strong>
</dt>
<dd>
<pre>
@misc{LaemmelFsml,
author = {Ralf L{\"a}mmel},
title = "{Model of a DSL for finite state machines}",
year = {2013-14},
note = "Published at \url{http://softlang.uni-koblenz.de/fsml}"
}
</pre>
</dd>
<p/>
</dl>
</body>
</html>
33 changes: 17 additions & 16 deletions docs/fsml/paper.tex
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@

\begin{frontmatter}

\title{Another DSL primer}
\title{Model of a DSL for finite state machines}

\author{Ralf L\"ammel}

Expand All @@ -90,24 +90,33 @@
\noindent
\textbf{Acknowledgement}: {\small This document and the underlying
development are parts of a broader effort on language modeling and
software language engineering---joint work with \emph{Anya Helene
Bagge}, University of Bergen. Helpful interaction with and
feedback by Andrei Varanovich, University of Koblenz-Landau, is also
gratefully acknowledged.}
software language engineering. Collaboration with and feedback by
Anya Helene Bagge (University of Bergen) and Andrei Varanovich
(University of Koblenz-Landau) are gratefully acknowledged.}

\medskip

\noindent
\textbf{Version}

0.00004 as of 2 October 2014.
0.1 as of 11 November 2014.

\medskip

\noindent
\textbf{Repository location of document}:
\textbf{Website of this document}:

\url{https://github.com/slebok/slepro/tree/master/docs/fsml}.
\smallskip

\url{http://softlang.uni-koblenz.de/fsml/}

\smallskip

\noindent
The page also links to supplementary repository locations. In
particular, the model (code) of this document as well as alternative
implementations of FSML are linked. The FSML model is maintained as
part of the \slepro{} project: \url{https://github.com/slebok/slepro}
\end{abstract}

\end{frontmatter}
Expand Down Expand Up @@ -171,14 +180,6 @@ \section{Introducing FSML}

Various technical details are separated out into the appendix.

The FSML development is part of the \slepro{} project. All software
artifacts of this document and all support infrastructure is available
through the repository of the project:

\begin{center}
\url{https://github.com/slebok/slepro}
\end{center}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{The concrete textual syntax of FSML}
Expand Down
5 changes: 1 addition & 4 deletions languages/bgl/.ueber
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
[

language(bgl(text)),
language(bgl(term)),
membership(bgl(text), elementOfBgl, []),
membership(bgl(term), eslLanguage, ['as.term']),
elementOf('as.esl', esl(text)),
elementOf('as.term', esl(term)),
macro(eslSyntax(bgl)),
function(parser, [bgl(text)], [bgl(term)], parserOfBgl, []),
function(projection, [bgl(term)], [bsl(term)], bglToBsl, [])

Expand Down
33 changes: 18 additions & 15 deletions languages/bgl/accept-bu.pro
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
% Accept input, non-deterministically and bottom-up
acceptBottomUp(
grammar([Root|_], Rules), % rules to interpret
Input % input string of terminals
) :-
acceptBottomUp_(Rules, Root, [], Input).
% Accept input bottom-up
acceptBottomUp(Rules, Input) :-
Rules = [(_, Root, _)|_],
acceptBottomUp(Rules, Root, [], Input).

% Acceptance completed
acceptBottomUp_(_, Root, [n(Root)], []).
acceptBottomUp(_, Root, [n(Root)], []).

% Shift terminal from input to stack
acceptBottomUp_(Rules, Root, Stack, [T|Input0]) :-
acceptBottomUp_(Rules, Root, [t(T)|Stack], Input0).
acceptBottomUp(Rules, Root, Stack0, [T|Input0]) :-
append(Stack0, [t(T)], Stack1),
acceptBottomUp(Rules, Root, Stack1, Input0).

% Reduce prefix of stack to according to rule
acceptBottomUp_(Rules, Root, Stack0, Input0) :-
append(RhsReverse, Stack1, Stack0),
reverse(RhsReverse, Rhs),
member(rule(_, N, Rhs), Rules),
acceptBottomUp_(Rules, Root, [n(N)|Stack1], Input0).
% Reduce prefix on stack to nonterminal
acceptBottomUp(Rules, Root, Stack0, Input0) :-
% Remove a prefix from the stack
append(Stack1, Rhs, Stack0),
% Find the prefix as the RHS of a rule
member((_, N, Rhs), Rules),
% Add LHS nonterminal to the stack
append(Stack1, [n(N)], Stack2),
% Proceed recursively
acceptBottomUp(Rules, Root, Stack2, Input0).
37 changes: 15 additions & 22 deletions languages/bgl/accept-td.pro
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
% Accept input, non-deterministically and top-down
acceptTopDown(
grammar([Root|_], Rules), % rules to interpret
Input % input string of terminals
) :-
acceptTopDown_(Rules, [n(Root)], Input).
% Accept input top-down
acceptTopDown(Rules, Input) :-
Rules = [(_, Root, _)|_],
acceptTopDown(Rules, [n(Root)], Input).

% Acceptance completed
acceptTopDown_(_, [], []).
acceptTopDown(_, [], []).

% Consume terminal at top of stack from input
acceptTopDown_(
Rules,
[t(T)|Stack], % parser stack with terminal at the top
[T|Input] % input with ditto terminal as head
) :-
acceptTopDown_(Rules, Stack, Input).
acceptTopDown(Rules, [t(T)|Stack], [T|Input]) :-
acceptTopDown(Rules, Stack, Input).

% Expand nonterminal at top of stack
acceptTopDown_(
Rules,
[n(N)|Stack0], % parser stack with nonterminal at the top
Input
) :-
member(rule(_, N, Rhs), Rules),
append(Rhs, Stack0, Stack1),
acceptTopDown_(Rules, Stack1, Input).
% Expand nonterminal at the top of stack
acceptTopDown(Rules, [n(N)|Stack0], Input) :-
% Select an alternative with LHS N
member((_, N, Rhs), Rules),
% Add RHS to the stack
append(Rhs, Stack0, Stack1),
% Proceed recursively
acceptTopDown(Rules, Stack1, Input).
3 changes: 1 addition & 2 deletions languages/bgl/api.pro
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ bglImploder(Input, Output)
bglExploder(File, Input, Output)
:-
readTermFile(File, Grammar),
Grammar = grammar([Root|_], _),
explode(Grammar, Root, Input, Output).
explode(Grammar, Input, Output).

% BGL-based top-down parser for token sequences
bglTopDownParser(File, Text, Term)
Expand Down
4 changes: 2 additions & 2 deletions languages/bgl/as.esl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
symbol grammar : nonterminal* x rule* -> grammar ;
symbol rule : label x nonterminal x symbol* -> rule ;
type grammar = rule* ;
type rule = (label, nonterminal, symbol*) ;
symbol t : terminal -> symbol ;
symbol n : nonterminal -> symbol ;
type nonterminal = atom ;
Expand Down
29 changes: 1 addition & 28 deletions languages/bgl/as.term
Original file line number Diff line number Diff line change
@@ -1,28 +1 @@
% The signature of context-free grammars
[

% Grammars as lists of nonterminals and rules
symbol(grammar, [
star(sort(nonterminal)), % list of nonterminals
star(sort(rule)) % list of rules
],
grammar),

% Rules with LHS and RHS as well as a label
symbol(rule, [
sort(label), % label of rule
sort(nonterminal), % LHS nonterminal
star(sort(symbol)) % RHS sequence of symbols
],
rule),

% Classification of grammar symbols
symbol(t, [sort(terminal)], symbol), % terminals are symbols
symbol(n, [sort(nonterminal)], symbol), % nonterminals as well

% Elementary kinds of symbols
type(nonterminal, atom),
type(terminal, atom),
type(label, atom)

].
[type(grammar,star(sort(rule))),type(rule,tuple([sort(label),sort(nonterminal),star(sort(symbol))])),symbol(t,[sort(terminal)],symbol),symbol(n,[sort(nonterminal)],symbol),type(nonterminal,atom),type(terminal,atom),type(label,atom)].
14 changes: 5 additions & 9 deletions languages/bgl/derive-signature.pro
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
% Convert a grammar to a signature
bglToBsl(
grammar(Nonterminals, Rules),
signature(Sorts, STypes)
) :-
Nonterminals = Sorts,
map(rule2sType, Rules, STypes).
bglToBsl(Rules, Profiles) :-
map(rule2profile, Rules, Profiles).

% Convert a rule to a symbol type
rule2sType(
rule(Label, Lhs, Rhs),
% Convert a rule to a profile
rule2profile(
(Label, Lhs, Rhs),
symbol(Symbol, Arguments, Result)
) :-
Label = Symbol,
Expand Down
6 changes: 2 additions & 4 deletions languages/bgl/egl2bgl.pro
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
Map more complex EGL grammar notation to BGL
*/

eglToBgl(Rs1, grammar(Ns2, Rs2)) :-
map(eglToBglLhs, Rs1, Ns1),
list_to_set(Ns1, Ns2),
eglToBgl(Rs1, Rs2) :-
map(eglToBglRule, Rs1, Rs2).

eglToBglLhs((_, Lhs, _), Lhs).

eglToBglRule(
([Label], Lhs, Rhs1),
rule(Label, Lhs, Rhs2)
(Label, Lhs, Rhs2)
) :-
map(eglToBglSymbol, Rhs1, Rhs2).

Expand Down
20 changes: 10 additions & 10 deletions languages/bgl/explode.pro
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
% Explosion
explode(
grammar(_, Rules), % Rules to consult for details
Root, % Assumed root nonterminal
Rules, % Rules to consult for details
ITree, % Imploded (concise) parse tree
ETree % Exploded (detailed) parse tree
) :-
explode_(Rules, [n(Root)], [ITree], [ETree]).
Rules = [(_, Root, _)|_],
explode(Rules, [n(Root)], [ITree], [ETree]).

% Base case; explosion completed
explode_(_, [], [], []).
explode(_, [], [], []).

% Add heading terminal from rule back into exploded form
explode_(
explode(
Rules,
[t(T)|Symbols],
ITrees,
[leaf(T)|ETrees]
) :-
explode_(Rules, Symbols, ITrees, ETrees).
explode(Rules, Symbols, ITrees, ETrees).

% Find a rule for the function symbol at hand
explode_(
explode(
Rules,
[n(N)|Symbols],
[ITree|ITrees1],
[fork(Rule, ETrees1)|ETrees2]
) :-
ITree =.. [L|ITrees2],
Rule = rule(L, N, Rhs),
Rule = (L, N, Rhs),
member(Rule, Rules),
explode_(Rules, Rhs, ITrees2, ETrees1),
explode_(Rules, Symbols, ITrees1, ETrees2).
explode(Rules, Rhs, ITrees2, ETrees1),
explode(Rules, Symbols, ITrees1, ETrees2).
2 changes: 1 addition & 1 deletion languages/bgl/implode.pro
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ implode_(

% Implode subtree recursively
implode_(
[fork(rule(L, _, _), ETrees1)|ETrees2], % nonterminal tree in front
[fork((L, _, _), ETrees1)|ETrees2], % nonterminal tree in front
[ITree|ITrees2] % binarily recursively imploded trees
) :-
implode_(ETrees1, ITrees1),
Expand Down
Loading

0 comments on commit 7718cdd

Please sign in to comment.