DSL是領域專用語言,常見的DSL有SQL,CSS,Shell等等,這些DSL語言有別於其他通用語言如:C++,Java,C#,DSL常在特殊的場景或領域中使用。如下圖:
class Program { static void Main(string[] args) { TestISL(); Console.ReadLine(); } private static void TestISL() { string text = string.Empty; ParseISL(""); } private static void ParseISL(string input) { input = "return (([車速]*10+3)>(200)) && ([企業ID] == \"123\") && ([時間]>1200 && [時間]<1700);"; AntlrInputStream inputStream = new AntlrInputStream(input); ISLLexer lexer = new ISLLexer(inputStream); CommonTokenStream tokens = new CommonTokenStream(lexer); ISLParser parser = new ISLParser(tokens); IParseTree tree = parser.return_statement(); //ISLVisitor visitor = new ISLVisitor(); //object ret = visitor.Visit(tree); ISLVisitor2 visitor = new ISLVisitor2(); Result ret = visitor.Visit(tree); //Console.WriteLine(ret); Console.WriteLine(ret.Value); Console.WriteLine(ret.Text); Console.ReadLine(); } }
最後,點擊這裡下載示例。