-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Working on the syntax chapter of the slbook
- Loading branch information
Showing
68 changed files
with
381 additions
and
280 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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ä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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)]. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.