Exemplo n.º 1
0
 public TreeNode getTree(String filePath)
 {
     TokenList = SNLScanner.getTokenList(filePath);
     if (SNLScanner.error.isError == true)
     {
         if (SNLScanner.error.Type == ErrorType.errorType.LexicalError)
         {
             output = SNLScanner.lexString(filePath);
         }
         return(null);
     }
     else
     {
         TreeNode root = new TreeNode();
         cur  = 0;
         root = match(nonTerminals.Program, null);
         //Console.WriteLine(TokenList[cur].LexType);
         if (TokenList[cur].LexType != LexType.DOT)
         {
             error.Type = ErrorType.errorType.SyntaxError;
             error.Line = TokenList[cur].Line;
             error.Row  = TokenList[cur].Row;
         }
         if (error.isError == true)
         {
             int line;
             line = error.Line / 2;
             if (error.Line / 2 == 0)
             {
                 line = 1;
             }
             if (error.Line == 3)
             {
                 line = 2;
             }
             output = "行: " + line + " 列: " + error.Row + "			"+ "语法错误";
             return(null);
         }
         return(root);
     }
 }