English 中文(简体)
在C#中实施“顶级”
原标题:Implementing a Top Down Parser in C#
  • 时间:2011-11-11 17:02:07
  •  标签:
  • c#
  • nlp

我是学生,我想在我的C#语言翻译项目中执行一个自上而下的教区。 例如,如果我需要为“我们的名字是Husni,我是学生”这一句修建一个树冠树,那么我怎么能用C#。

最佳回答

在该书之后,你还可以发现有兴趣阅读一个编辑发电机,作为,帮助您撰写汇编者(也在C# )并浏览该汇编。

问题回答

我高度推荐这本书:

《设计书》()

你可以免费下载PDF。 它以全面的方式涵盖教区(上下层和下层),而没有就你的背景作出太多的假设。

很好。

如何在C#中做到这一点? 就像使用C# syntax一样,你以任何其他语言这样做。 学习理论和守则自然出现。

页: 1

一种大型的汇编式建筑工具,从正式制图规格中产生自上而下游的留级。

你们收到Terrance Parr书:

另一种选择是铁丝网:

Irony is a development kit for implementing languages on .NET platform. Unlike most existing yacc/lex-style solutions Irony does not employ any scanner or parser code generation from grammar specifications written in a specialized meta-language. In Irony the target language grammar is coded directly in c# using operator overloading to express grammar constructs. Irony s scanner and parser modules use the grammar encoded as c# class to control the parsing process.

这里有一幅带有讽刺意味的言论图形:

using System;
using System.Collections.Generic;
using System.Text;
using Irony.Parsing;
using Irony.Ast;

namespace Irony.Samples
{
  // This grammar describes programs that consist of simple expressions and assignments
  // for ex:
  // x = 3
  // y = -x + 5
  //  the result of calculation is the result of last expression or assignment.
  //  Irony s default  runtime provides expression evaluation. 
  //  supports inc/dec operators (++,--), both prefix and postfix,
  //  and combined assignment operators like +=, -=, etc.

  [Language("ExpressionEvaluator", "1.0", "Multi-line expression evaluator")]
  public class ExpressionEvaluatorGrammar : Irony.Parsing.Grammar
  {

    public ExpressionEvaluatorGrammar()
    {

      // 1. Terminals
      var number = new NumberLiteral("number");

      //Let s allow big integers (with unlimited number of digits):
      number.DefaultIntTypes = new TypeCode[] { TypeCode.Int32, TypeCode.Int64, NumberLiteral.TypeCodeBigInt };
      var identifier         = new IdentifierTerminal("identifier");
      var comment            = new CommentTerminal("comment", "#", "
", "
"); 

      //comment must to be added to NonGrammarTerminals list; it is not used directly in grammar rules,
      // so we add it to this list to let Scanner know that it is also a valid terminal. 
      base.NonGrammarTerminals.Add(comment);

      // 2. Non-terminals
      var Expr           = new NonTerminal("Expr");
      var Term           = new NonTerminal("Term");
      var BinExpr        = new NonTerminal("BinExpr", typeof(BinExprNode));
      var ParExpr        = new NonTerminal("ParExpr");
      var UnExpr         = new NonTerminal("UnExpr", typeof(UnExprNode));
      var UnOp           = new NonTerminal("UnOp");
      var BinOp          = new NonTerminal("BinOp", "operator");
      var PostFixExpr    = new NonTerminal("PostFixExpr", typeof(UnExprNode));
      var PostFixOp      = new NonTerminal("PostFixOp");
      var AssignmentStmt = new NonTerminal("AssignmentStmt", typeof(AssigmentNode));
      var AssignmentOp   = new NonTerminal("AssignmentOp", "assignment operator");
      var Statement      = new NonTerminal("Statement");
      var ProgramLine    = new NonTerminal("ProgramLine");
      var Program        = new NonTerminal("Program", typeof(StatementListNode));

      // 3. BNF rules
      Expr.Rule           = Term | UnExpr | BinExpr | PostFixExpr;
      Term.Rule           = number | ParExpr | identifier;
      ParExpr.Rule        = "(" + Expr + ")";
      UnExpr.Rule         = UnOp + Term;
      UnOp.Rule           = ToTerm("+") | "-" | "++" | "--";
      BinExpr.Rule        = Expr + BinOp + Expr;
      BinOp.Rule          = ToTerm("+") | "-" | "*" | "/" | "**";
      PostFixExpr.Rule    = Term + PostFixOp;
      PostFixOp.Rule      = ToTerm("++") | "--";
      AssignmentStmt.Rule = identifier + AssignmentOp + Expr;
      AssignmentOp.Rule   = ToTerm("=") | "+=" | "-=" | "*=" | "/=";
      Statement.Rule      = AssignmentStmt | Expr | Empty;
      ProgramLine.Rule    = Statement + NewLine;
      Program.Rule        = MakeStarRule(Program, ProgramLine);
      this.Root           = Program;       // Set grammar root

      // 4. Operators precedence
      RegisterOperators(1, "+", "-");
      RegisterOperators(2, "*", "/");
      RegisterOperators(3, Associativity.Right, "**");

      // 5. Punctuation and transient terms
      RegisterPunctuation("(", ")");
      RegisterBracePair("(", ")"); 
      MarkTransient(Term, Expr, Statement, BinOp, UnOp, PostFixOp, AssignmentOp, ProgramLine, ParExpr);

      //automatically add NewLine before EOF so that our BNF rules work correctly when there s no final line break in source
      this.LanguageFlags = LanguageFlags.CreateAst | LanguageFlags.NewLineBeforeEOF | LanguageFlags.CanRunSample; 

    }

  }

}//namespace

更多关于摩纳迪特神父的作者:

你试图用一种模糊不清的自然语言。 这意味着,贵族长会允许多 trees树服刑。 因此,我不认为像新南半球那样的常规语言设计工具会有所帮助。

I m using PEP a up-down Dynamic CFG parser. 文章在 Java撰写。 将其赶上车牌将比从头开始写出新车更容易。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签