0
변환하는 법을 배우려고합니다. EBNF ~ C# 코드로 변환하려고합니다.EBNF를 컴파일러 용 C#으로 변환하십시오.
샘플 : 나는 그것은 "변수 (답하라)를 말하고 이해 int <ident> = <expr>
이 데이터 유형의(int)를이 (=)에 걸리는 정수 (EXPR),하지만, 내가 이해하지 못하는 것은이로 변환하는 방법입니다 : AST 클래스에서
CODEGEN 클래스 파서 클래스
#region INTEGER VARIABLE
else if (this.tokens[this.index].Equals("int"))
{
this.index++;
Int Integer = new Int();
if (this.index < this.tokens.Count &&
this.tokens[this.index] is string)
{
Integer.Ident = (string)this.tokens[this.index];
}
else
{
throw new System.Exception("expected variable name after 'int'");
}
this.index++;
if (this.index == this.tokens.Count ||
this.tokens[this.index] != Scanner.EqualSign)
{
throw new System.Exception("expected = after 'int ident'");
}
this.index++;
Integer.Expr = this.ParseExpr();
result = Integer;
}
#endregion
에서
public class Int : Stmt { public string Ident; public Expr Expr; }
0
#region INTEGER
else if (stmt is Int)
{
// declare a local
Int integer = (Int)stmt;
this.symbolTable[integer.Ident] = this.il.DeclareLocal(this.TypeOfExpr(integer.Expr));
// set the initial value
Assign assign = new Assign();
assign.Ident = integer.Ident;
assign.Expr = integer.Expr;
this.GenStmt(assign);
}
#endregion
사람이 제대로이를 변환하는 방법을 이해하는 방법에 관한 올바른 방향으로 날 포인트?
방금 라이브러리를 체크 아웃 한 결과 2.0까지만 표시되는 것처럼 보입니까? – SpicyWeenie
여기에 누군가가 같은 질문을 던졌습니다. http://stackoverflow.com/questions/1194584/what-is-a-good-c-sharp-compiler-compiler-parser-generator – LueTm
Im가 금으로 붙어 있습니다. 입력을위한 Thx! :) – SpicyWeenie