aboutsummaryrefslogtreecommitdiff
path: root/runtime/CSharp3/Sources/Antlr3.Runtime.Test/Composition
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/CSharp3/Sources/Antlr3.Runtime.Test/Composition')
-rw-r--r--runtime/CSharp3/Sources/Antlr3.Runtime.Test/Composition/Program.cs54
-rw-r--r--runtime/CSharp3/Sources/Antlr3.Runtime.Test/Composition/Reduce.g320
-rw-r--r--runtime/CSharp3/Sources/Antlr3.Runtime.Test/Composition/Simplify.g320
-rw-r--r--runtime/CSharp3/Sources/Antlr3.Runtime.Test/Composition/VecMath.g322
-rw-r--r--runtime/CSharp3/Sources/Antlr3.Runtime.Test/Composition/VecMath_Lexer.g317
-rw-r--r--runtime/CSharp3/Sources/Antlr3.Runtime.Test/Composition/VecMath_Parser.g335
6 files changed, 0 insertions, 168 deletions
diff --git a/runtime/CSharp3/Sources/Antlr3.Runtime.Test/Composition/Program.cs b/runtime/CSharp3/Sources/Antlr3.Runtime.Test/Composition/Program.cs
deleted file mode 100644
index c2aaf02..0000000
--- a/runtime/CSharp3/Sources/Antlr3.Runtime.Test/Composition/Program.cs
+++ /dev/null
@@ -1,54 +0,0 @@
-namespace Antlr3.Runtime.Test.Composition
-{
- using System;
- using Antlr.Runtime;
- using Antlr.Runtime.Tree;
-
- internal class Program
- {
- private static void _Main(string[] args)
- {
- // input "x = 2*(3+3)"
-
- ICharStream input;
- if (args.Length > 0)
- {
- if (args[0].Equals("-i"))
- {
- if (args.Length > 1)
- {
- input = new ANTLRFileStream(args[1]);
- }
- else
- {
- throw new Exception("No input file specified.");
- }
- }
- else
- {
- input = new ANTLRStringStream(args[0]);
- }
- }
- else
- {
- input = new ANTLRInputStream(Console.OpenStandardInput());
- }
-
- var lex = new VecMathLexer(input);
- var tokens = new CommonTokenStream(lex);
- var g = new VecMathParser(tokens);
- IAstRuleReturnScope<CommonTree> r = g.prog();
- CommonTree t = r.Tree;
- Console.WriteLine("Original tree: " + t.ToStringTree());
-
- var simplify = new Simplify(new CommonTreeNodeStream(t));
- t = (CommonTree)simplify.Downup(t);
-
- var reduce = new Reduce(new CommonTreeNodeStream(t));
- t = (CommonTree)reduce.Downup(t);
-
- Console.WriteLine("Simplified tree: " + t.ToStringTree());
- Console.ReadKey();
- }
- }
-}
diff --git a/runtime/CSharp3/Sources/Antlr3.Runtime.Test/Composition/Reduce.g3 b/runtime/CSharp3/Sources/Antlr3.Runtime.Test/Composition/Reduce.g3
deleted file mode 100644
index db61e42..0000000
--- a/runtime/CSharp3/Sources/Antlr3.Runtime.Test/Composition/Reduce.g3
+++ /dev/null
@@ -1,20 +0,0 @@
-tree grammar Reduce;
-
-options
-{
- tokenVocab=VecMath;
- ASTLabelType=CommonTree;
- output=AST;
- filter=true;
- language=CSharp3;
-}
-
-@namespace{Antlr3.Runtime.Test.Composition}
-
-/** Rewrite: x+x to be 2*x, 2*x to be x<<1, x<<n<<m to be x<<(n+m) */
-bottomup
- : ^(PLUS i=INT j=INT {$i.int==$j.int}?) -> ^(MULT["*"] INT["2"] $j)
- | ^(MULT x=INT {$x.int==2}? y=.) -> ^(SHIFT["<<"] $y INT["1"])
- | ^(SHIFT ^(SHIFT e=. n=INT) m=INT)
- -> ^(SHIFT["<<"] $e INT[($n.int+$m.int).ToString()])
- ;
diff --git a/runtime/CSharp3/Sources/Antlr3.Runtime.Test/Composition/Simplify.g3 b/runtime/CSharp3/Sources/Antlr3.Runtime.Test/Composition/Simplify.g3
deleted file mode 100644
index f1c2550..0000000
--- a/runtime/CSharp3/Sources/Antlr3.Runtime.Test/Composition/Simplify.g3
+++ /dev/null
@@ -1,20 +0,0 @@
-tree grammar Simplify;
-
-options {
- tokenVocab=VecMath;
- ASTLabelType=CommonTree;
- output=AST;
- language=CSharp3;
- filter=true;
- //rewrite=true;
-}
-
-@namespace{Antlr3.Runtime.Test.Composition}
-
-topdown
- : ^( MULT INT ^(VEC (e+=.)+) ) -> ^(VEC ^(MULT INT $e)+)
- ;
-
-bottomup
- : ^(MULT a=. b=INT {$b.int==0}?) -> $b // x*0 -> 0
- ;
diff --git a/runtime/CSharp3/Sources/Antlr3.Runtime.Test/Composition/VecMath.g3 b/runtime/CSharp3/Sources/Antlr3.Runtime.Test/Composition/VecMath.g3
deleted file mode 100644
index f61a7f8..0000000
--- a/runtime/CSharp3/Sources/Antlr3.Runtime.Test/Composition/VecMath.g3
+++ /dev/null
@@ -1,22 +0,0 @@
-grammar VecMath;
-
-options
-{
- ASTLabelType=CommonTree;
- output=AST;
- language=CSharp3;
-}
-
-import VecMath_Lexer, VecMath_Parser;
-
-@lexer::namespace{Antlr3.Runtime.Test.Composition}
-@parser::namespace{Antlr3.Runtime.Test.Composition}
-
-public
-main
- : prog
- ;
-
-dummy
- : 'DUMMY' // 1. If the parser or the composite grammar does not contain a token, no lexer is generated.
- ;
diff --git a/runtime/CSharp3/Sources/Antlr3.Runtime.Test/Composition/VecMath_Lexer.g3 b/runtime/CSharp3/Sources/Antlr3.Runtime.Test/Composition/VecMath_Lexer.g3
deleted file mode 100644
index fde3390..0000000
--- a/runtime/CSharp3/Sources/Antlr3.Runtime.Test/Composition/VecMath_Lexer.g3
+++ /dev/null
@@ -1,17 +0,0 @@
-lexer grammar VecMath_Lexer;
-
-
-PRINT : 'print';
-ID : 'a'..'z'+ ;
-INT : '0'..'9'+ ;
-WS : (' '|'\r'|'\n')+ {Skip();} ;
-PLUS : '+';
-MINUS : '-';
-MULT : '*';
-EQUAL : '=';
-DOT : '.';
-OPEN_BRACE : '(';
-OPEN_SQUARE : '[';
-CLOSE_BRACE : ')';
-CLOSE_SQUARE : ']';
-COMMA : ','; \ No newline at end of file
diff --git a/runtime/CSharp3/Sources/Antlr3.Runtime.Test/Composition/VecMath_Parser.g3 b/runtime/CSharp3/Sources/Antlr3.Runtime.Test/Composition/VecMath_Parser.g3
deleted file mode 100644
index 406ec13..0000000
--- a/runtime/CSharp3/Sources/Antlr3.Runtime.Test/Composition/VecMath_Parser.g3
+++ /dev/null
@@ -1,35 +0,0 @@
-parser grammar VecMath_Parser;
-
-options {
- output=AST;
-}
-
-tokens {
- SHIFT;
- VEC;
-}
-
-public
-prog
- : stat+ ;
-
-stat
- : ID EQUAL expr -> ^( EQUAL ID expr )
- | PRINT^ expr
- ;
-
-expr
- : multExpr ( PLUS^ multExpr )*
- ;
-
-multExpr
- : primary ( ( MULT^ | DOT^ ) primary )*
- ;
-
-primary
- : INT
- | ID
- | OPEN_SQUARE expr ( COMMA expr )* CLOSE_SQUARE -> ^( VEC expr+ )
- | OPEN_BRACE expr CLOSE_BRACE -> expr
- ;
-