本文整理汇总了C#中Irony.Parsing.LanguageData类的典型用法代码示例。如果您正苦于以下问题:C# LanguageData类的具体用法?C# LanguageData怎么用?C# LanguageData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LanguageData类属于Irony.Parsing命名空间,在下文中一共展示了LanguageData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetUp
public void SetUp()
{
var grammar = new CustomDslGrammar();
var language = new LanguageData(grammar);
_parser = new Parser(language);
_visitor = new CSharpExpressionBuilder();
}
示例2: ScriptApp
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();
}
示例3: ExpressionEvaluator
//Default constructor, creates default evaluator
public ExpressionEvaluator(ExpressionEvaluatorGrammar grammar) {
Grammar = grammar;
Language = new LanguageData(Grammar);
Parser = new Parser(Language);
Runtime = Grammar.CreateRuntime(Language);
App = new ScriptApp(Runtime);
}
示例4: Parser
/// <summary>
/// Initializes a new instance of the <see cref="Parser"/> class.
/// </summary>
/// <param name="language">The language.</param>
/// <param name="scanner">The scanner.</param>
/// <param name="root">The root.</param>
/// <exception cref="Exception">
/// </exception>
public Parser(LanguageData language, Scanner scanner, NonTerminal root)
{
Language = language;
Context = new ParsingContext(this);
Scanner = scanner ?? language.CreateScanner();
if (Scanner != null)
{
Scanner.Initialize(this);
}
else
{
Language.Errors.Add(GrammarErrorLevel.Error, null, "Scanner is not initialized for this grammar");
}
CoreParser = new CoreParser(this);
Root = root;
if (Root == null)
{
Root = Language.Grammar.Root;
InitialState = Language.ParserData.InitialState;
}
else
{
if (Root != Language.Grammar.Root && !Language.Grammar.SnippetRoots.Contains(Root))
{
throw new Exception(string.Format(Resources.ErrRootNotRegistered, root.Name));
}
InitialState = Language.ParserData.InitialStates[Root];
}
}
示例5: Parse
public static ParseTreeNode Parse(string src)
{
if (IsValid(src, new KISGrammer()))
{
var x = GetRoot(src, new KISGrammer());
// DispTree(x, 100);
return x;
}
else
{
LanguageData language = new LanguageData(new KISGrammer());
Parser parser = new Parser(language);
ParseTree parseTree = parser.Parse(src);
foreach (var i in parseTree.ParserMessages)
{
ErrorStack.Add(i.Message + " on line: " + (i.Location.Line + 1) + " Column: " + (i.Location.Column + 1) + " at Position: " + (i.Location.Position + 1));
}
return null;
}
}
示例6: Setup
public void Setup()
{
_grammar = new TestGrammar();
_language = new LanguageData(_grammar);
_parser = new Parser(_language);
_context = _parser.Context;
}
示例7: ScriptInterpreter
public ScriptInterpreter(LanguageData language) {
Language = language;
Runtime = Language.Grammar.CreateRuntime(Language);
Parser = new Parser(Language);
EvaluationContext = new EvaluationContext(Runtime);
Status = _internalStatus = InterpreterStatus.Ready;
}
示例8: Apply
public override void Apply(LanguageData language, LRItem owner) {
var state = owner.State;
var conflicts = state.BuilderData.Conflicts;
if (conflicts.Count == 0) return;
switch (ActionType) {
case PreferredActionType.Shift:
var currTerm = owner.Core.Current as Terminal;
if (currTerm == null || !conflicts.Contains(currTerm)) return; //nothing to do
//Current term for shift item (hint owner) is a conflict - resolve it with shift action
var newState = owner.ShiftedItem.State;
var shiftAction = new ShiftParserAction(owner);
state.Actions[currTerm] = shiftAction;
conflicts.Remove(currTerm);
return;
case PreferredActionType.Reduce:
if (!owner.Core.IsFinal) return; //we take care of reduce items only here
//we have a reduce item with "Reduce" hint. Check if any of lookaheads are in conflict
ReduceParserAction reduceAction = null;
foreach (var lkhead in owner.Lookaheads)
if (conflicts.Contains(lkhead)) {
if (reduceAction == null)
reduceAction = new ReduceParserAction(owner.Core.Production);
state.Actions[lkhead] = reduceAction;
conflicts.Remove(lkhead);
}
return;
}//switch
}//method
示例9: PrintTerminals
public static string PrintTerminals(LanguageData language)
{
var termList = language.GrammarData.Terminals.ToList();
termList.Sort((x, y) => string.Compare(x.Name, y.Name));
var result = string.Join(Environment.NewLine, termList);
return result;
}
示例10: InternCreateScriptApp
protected static MtCompiler InternCreateScriptApp(Stream output, Stream debugStream)
{
var grammar = new MtGrammar();
var lang = new LanguageData(grammar);
var parser = new Parser(grammar);
var runtime = grammar.CreateRuntime(lang) as MultiTasksRuntime;
if (output != null)
{
runtime.OutputStream = output;
}
#if DEBUG && !SILVERLIGHT
if (debugStream != null)
{
// Add as a listener to debug
var listener = new TextWriterTraceListener(debugStream);
Debug.Listeners.Add(listener);
}
#endif
var app = new ScriptApp(runtime);
// Add constants
app.Globals.Add("TRUE", MtResult.True);
app.Globals.Add("FALSE", MtResult.False);
#if DEBUG && !SILVERLIGHT
MultiTasksRuntime.DebugDisplayInfo();
#endif
return new MtCompiler(app);
}
示例11: Main
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();
}
示例12: BuildAst
public override void BuildAst(LanguageData language, ParseTree parseTree) {
var opHandler = new OperatorHandler(language.Grammar.CaseSensitive);
Util.Check(!parseTree.HasErrors(), "ParseTree has errors, cannot build AST.");
var astContext = new InterpreterAstContext(language, opHandler);
var astBuilder = new AstBuilder(astContext);
astBuilder.BuildAst(parseTree);
}
示例13: Setup
public void Setup()
{
var grammar = new XamlMarkupExtensionGrammar();
var language = new LanguageData(grammar);
_parser = new Parser(language) {Context = {TracingEnabled = true}};
}
示例14: LanguageRuntime
public LanguageRuntime(LanguageData language)
{
Language = language;
NoneValue = NoneClass.Value;
BuiltIns = new BindingSourceTable(Language.Grammar.CaseSensitive);
Init();
}
示例15: AssemblyBlock
public bool AssemblyBlock(eBLOCK200_BLOCKTYPES blockType, int blockNr, eBLOCK200_OB_VERSIONS blockVer,
bool forceExpandedFormat, bool bNoWizardInfo, bool bUseChineseOpcode,
string source, out byte[] dest)
{
dest = null;
var server = new CoMsSig200Lib.Sig200ServerClass();
Sig200SignatureList InsList = null;
server.CreateInstructionSignatures(null);
server.SetMnemonic(eSIG200_MNEMONICS.eSIG200_MNEMONIC_SIMATIC);
server.GetInstructionSignatureList(ref InsList);
var grammar = new STLCompiler.STLGrammar();
LanguageData language = new LanguageData(grammar);
Parser parser = new Parser(language);
ParseTree parseTree = parser.Parse(source);
ParseTreeNode root = parseTree.Root;
var project = new STLCompiler.S7Project(root.AstNode as Block, server);
var builder = new CoMsBlock200Lib.Block200Class() as IBlock200Fix;
int pnOBSize, pnOBSizeNoWiz, pnDBArea3Size;
builder.CalcBlockSizes(project, server,
(int)eBLOCK200_OB_VERSIONS.eBLOCK200_OB_VERSION_2ND_GEN_5,
2, /* Must 2, from reverse */
out pnOBSize,
out pnOBSizeNoWiz,
out pnDBArea3Size);
IntPtr ppbyDestBlock = Marshal.AllocCoTaskMem(pnOBSize);
IntPtr ppbyEdgeData = IntPtr.Zero;
int nDestBytes = pnOBSize, nEdges = 0;
try
{
builder.AssembleBlock(project,
server,
(int)eBLOCK200_BLOCKTYPES.eBLOCK200_BLOCKTYPE_OB,
1,
(int)eBLOCK200_OB_VERSIONS.eBLOCK200_OB_VERSION_2ND_GEN_5,
0,
1,
1,
out ppbyDestBlock,
out nDestBytes,
out ppbyEdgeData,
out nEdges);
dest = new byte[nDestBytes];
Marshal.Copy(ppbyDestBlock, dest, 0, nDestBytes);
}
catch(COMException e)
{
Console.Write(e.Message);
return false;
}
return true;
}