public ParseTree LastScript { get; private set; } //the root node of the last executed script #region Constructors public ScriptApp(LanguageData language) { Language = language; var grammar = language.Grammar as InterpretedLanguageGrammar; Runtime = grammar.CreateRuntime(language); DataMap = new AppDataMap(Language.Grammar.CaseSensitive); Init(); }
static void Main(string[] args) { Console.Title = "Irony Console Sample"; Console.WriteLine("Irony Console Sample."); Console.WriteLine(""); Console.WriteLine("Select a grammar to load:"); Console.WriteLine(" 1. Expression Evaluator"); Console.WriteLine(" 2. mini-Python"); Console.WriteLine(" Or press any other key to exit."); Console.WriteLine(""); Console.Write("?"); var choice = Console.ReadLine(); Grammar grammar; switch (choice) { case "1": grammar = new SampleExpressionEvaluatorGrammar(); break; case "2": grammar = new MiniPython.MiniPythonGrammar(); break; default: return; } Console.Clear(); var language = new LanguageData(grammar); var runtime = new LanguageRuntime(language); var commandLine = new CommandLine(runtime); commandLine.Run(); }
public ScriptApp(LanguageRuntime runtime) { Runtime = runtime; Language = Runtime.Language; DataMap = new AppDataMap(Language.Grammar.CaseSensitive); Init(); }
public ScriptInterpreter(LanguageData language) { Language = language; Runtime = Language.Grammar.CreateRuntime(Language); Parser = new Parser(Language); EvaluationContext = new EvaluationContext(Runtime); Status = _internalStatus = InterpreterStatus.Ready; }
} //the root node of the last executed script #region Constructors public ScriptApp(LanguageData language) { Language = language; var grammar = language.Grammar as InterpretedLanguageGrammar; Runtime = grammar.CreateRuntime(language); DataMap = new AppDataMap(Language.Grammar.CaseSensitive); Init(); }
public EvaluationContext(LanguageRuntime runtime) { Runtime = runtime; LanguageCaseSensitive = Runtime.Language.Grammar.CaseSensitive; //Globals = new GlobalValuesTable(100, Symbols, LanguageCaseSensitive); Globals = new ValuesTable(100); CallDispatcher = new DynamicCallDispatcher(this); ThreadId = Thread.CurrentThread.ManagedThreadId; TopFrame = new StackFrame(this, Globals); CurrentFrame = TopFrame; Data = new DataStack(); Data.Init(runtime.Unassigned); //set LastPushedItem to unassigned }
public CommandLine(LanguageRuntime runtime, IConsoleAdaptor console = null) { Runtime = runtime; _console = console ?? new ConsoleAdapter(); var grammar = runtime.Language.Grammar; Title = grammar.ConsoleTitle; Greeting = grammar.ConsoleGreeting; Prompt = grammar.ConsolePrompt; PromptMoreInput = grammar.ConsolePromptMoreInput; App = new ScriptApp(Runtime); App.ParserMode = ParseMode.CommandLine; // App.PrintParseErrors = false; App.RethrowExceptions = false; }
public CommandLine(LanguageRuntime runtime, IConsoleAdapter console = null) { Runtime = runtime; _console = console ?? new SystemConsoleAdapter(); var grammar = runtime.Language.Grammar; Title = grammar.ConsoleTitle; Greeting = grammar.ConsoleGreeting; Prompt = grammar.ConsolePrompt; PromptMoreInput = grammar.ConsolePromptMoreInput; App = new ScriptApp(Runtime); App.ParserMode = ParseMode.CommandLine; // App.PrintParseErrors = false; App.RethrowExceptions = false; }
public CommandLine(LanguageRuntime runtime, IConsoleAdapter adapter) { Runtime = runtime; Adapter = adapter ?? new ConsoleAdapter(); var grammar = runtime.Language.Grammar; Title = grammar.ConsoleTitle; Greeting = grammar.ConsoleGreeting; Prompt = grammar.ConsolePrompt; PromptMoreInput = grammar.ConsolePromptMoreInput; App = new ScriptApp(Runtime) { ParserMode = ParseMode.CommandLine, RethrowExceptions = false }; // App.PrintParseErrors = false; }
/// <summary> /// /// </summary> /// <param name="sceneFile"> /// A <see cref="System.String"/> /// </param> /// <returns> /// A <see cref="System.Boolean"/> /// </returns> public bool Parse(string sceneFile) { Console.WriteLine (" > Invoking Parser:"); Console.WriteLine (" - Reading file {0}", sceneFile); Irony.Parsing.LanguageData languageData = new Irony.Parsing.LanguageData (_grammar); Irony.Parsing.Parser parser = new Irony.Parsing.Parser (languageData); LanguageRuntime runtime = new LanguageRuntime (languageData); System.Text.StringBuilder builder = new System.Text.StringBuilder (); System.IO.StreamReader reader = System.IO.File.OpenText (sceneFile); builder.Append (reader.ReadToEnd ()); Console.WriteLine (" - Parsing contents"); ParseTree tree = parser.Parse (builder.ToString ()); Console.WriteLine (" - Status: {0}", tree.Status); var node = tree.Root.AstNode as AstNode; node.Evaluate (new EvaluationContext (runtime), AstMode.Read); return true; }
public static void Main(string[] args) { Console.Title = "Ftp Irony Console Sample"; Console.WriteLine("Ftp Irony Console Sample."); Console.WriteLine(string.Empty); Grammar grammar = new FtpGrammar(); var language = new LanguageData(grammar); var runtime = new LanguageRuntime(language); Parser parser = new Parser(grammar); // necessário while (true) { Console.Write("AZFTP> "); string input = Console.ReadLine(); ParseTree tree = parser.Parse(input + System.Environment.NewLine); // notajota: the interpretation of the input command must be externalized and uniformized to transform the Ast into service calls // if command was recognized if (tree.ParserMessages.Count == 0) { if (tree.Root.ChildNodes[0].ChildNodes[0].ChildNodes[0].Term.Name == "byeCommand") { return; } } Console.WriteLine("## parser messages: " + tree.ParserMessages.Count); foreach (LogMessage lm in tree.ParserMessages) { Console.WriteLine("## parser messages: " + lm.Message); } Console.WriteLine("## parser time (ms): " + tree.ParseTimeMilliseconds); } }
public DynamicCallDispatcher(EvaluationContext context) { _context = context; _runtime = _context.Runtime; OperatorImplementations = _runtime.CreateOperatorImplementationsTable(); }
public ScriptThread(ScriptApp app) { App = app; Runtime = App.Runtime; CurrentScope = app.MainScope; }
public CommandLine(LanguageRuntime runtime) : this(runtime, null) { }