Skip to content

Commit

Permalink
parsing a really simple "cons" attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
ellisonch committed Jan 6, 2018
1 parent 7f4198c commit ae138c8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
1 change: 1 addition & 0 deletions ConsolePlayground/Program.cs
Expand Up @@ -192,6 +192,7 @@ class Program {
}
var ms1 = sw.Elapsed.TotalMilliseconds;
Console.WriteLine("Parse: {0:0.#}ms", ms1);
DotRunner.Run(DotBuilder.GetRawDot(sppf), "annotations");

var traversal = new Traversal(sppf, grammar);
var resCollection = traversal.Traverse();
Expand Down
10 changes: 5 additions & 5 deletions Grammars/Annotated/Arithmetic.ebnf
@@ -1,7 +1,7 @@
Exp = Exp, '+', Exp;
Exp = Exp, '-', Exp;
Exp = Exp, '*', Exp;
Exp = Exp, '/', Exp;
Exp = '(', Exp, ')';
Exp = Exp, '+', Exp (cons("Plus"));
Exp = Exp, '-', Exp (cons("Minus"));
Exp = Exp, '*', Exp (cons("Times"));
Exp = Exp, '/', Exp (cons("Divide"));
Exp = '(', Exp, ')' (cons("Paren"));
Number = Digit | Digit, Number;
Digit = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9';
32 changes: 30 additions & 2 deletions Grammars/Ebnf.cs
Expand Up @@ -52,7 +52,9 @@ public class Ebnf {
.Concat(Terminals())
.Concat(FinalPart())
.Concat(MetaIdentifiers())
.Concat(SpecialSequences());
.Concat(SpecialSequences())
.Concat(Annotations())
;
var g = new Grammar(productions, start);
return g;
}
Expand All @@ -66,7 +68,33 @@ public class Ebnf {

// return retval;
//}

private static IEnumerable<Production> Annotations() {
return new List<Production> {
new Production("SyntacticTerm", new Sentence {
Nonterminal.Of("SyntacticFactor"),
Nonterminal.Of("Annotations"),
}),
new Production("Annotations", new Sentence {
Terminal.Of("("),
Nonterminal.Of("AnnotationList0"),
Terminal.Of(")"),
}),
new Production("Annotation", new Sentence {
Nonterminal.Of("Cons")
}),
new Production("Cons", new Sentence {
Terminal.Of("c"),
Terminal.Of("o"),
Terminal.Of("n"),
Terminal.Of("s"),
Terminal.Of("("),
Nonterminal.Of("TerminalString"),
Terminal.Of(")")
}),
}.Concat(
MakeList<object>("Annotation", 0)
);
}
private static IEnumerable<Production> BasicSymbols() {
return new List<Production> {
new Production("ConcatenateSymbol", Terminal.Of(",")),
Expand Down

0 comments on commit ae138c8

Please sign in to comment.