아이러니는 C # 문법을 제공 한 아이러니를 사용하여 C #을 파싱하지 않습니다.

StackOverflow https://stackoverflow.com//questions/9646213

  •  10-12-2019
  •  | 
  •  

문제

그래서, 아이러니를 사용하는 방법을 배우기 위해 간단한 C # 코드를 구문 분석하려고합니다.나는 아이러니 샘플에 포함 된 C # 문법을 사용하고 거기에서 샘플 어셈블리 로딩 코드를 사용하고 있습니다.아이러니에 대한 문서화가 거의없는 것 같습니다.여기에 내가 구문 분석하려고하는 전체 소스가 있습니다.

using System;

namespace N
{
    class Test
    {
       public int A(int x)
       {
           return x+1;
       }
    }
    class Test2
    {
        public string hello = "world";
        private int _T = 0;
        private Test _actor = new Test();
        public void B()
        {
            Console.WriteLine(hello+": "+_actor.A(_T++));
        }
    }
}
.

및 구문 분석 코드 :

 string src = File.ReadAllText("testcs.cs");
 LanguageData language = new LanguageData(g);
 Parser parser = new Parser(language);
 ParseTree parseTree = parser.Parse(src);
 ParseTreeNode root = parseTree.Root;
 Console.WriteLine((root==null?"Parse tree unsuccessful!":"Parse tree created!"));
.

... g는 아이러니에서 C # 문법입니다.이전에는 아이러니의 문법과 함께 C #을 구문 분석하는 데이 문제를 경험 한 사람이 있습니까?더 이상 정보를 제공 할 수는 없습니다.excep 가 아닙니다

도움이 되었습니까?

해결책

When I tried your code, the parsing indeed was unsuccessful. And the error (in parseTree.ParserMessages) was on the end of the first line with the error message Invalid character: ''., where the character between the quotes is \r.

Hmm, it seems \r is not considered whitespace, so we need to modify the grammar. In the grammar, there is a method SkipWhitespace(), that contains a list of whitespace characters in a switch. If you just add case '\r': there, the parsing should succeed.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top