Example #1
0
 public int ParseToken(KToken KeyToken, ArrayList<KToken> TokenList, int BeginIdx, int EndIdx) {
   this.KeyToken = KeyToken;
   KSyntax Syntax = KeyToken.ResolvedSyntax;
   int NextIdx = NoMatch;
   while (Syntax != null) {
     this.Syntax = Syntax;
     KonohaDebug.P(
         "(^^;) trying matching.. : " + Syntax.SyntaxName + ":" + Syntax.ParseMethod.getName());
     NextIdx =
         Syntax.InvokeParseFunc(
             this,
             TokenList,
             BeginIdx,
             EndIdx,
             (Syntax.ParentSyntax == null) ? 0 : HasNextPattern);
     if (NextIdx != NoMatch) {
       KonohaDebug.P("(^^;) Matched: " + Syntax.SyntaxName + ":" + Syntax.ParseMethod.getName());
       return NextIdx;
     }
     this.Syntax = null;
     this.NodeList = null;
     Syntax = Syntax.ParentSyntax;
   }
   ReportError(KeyToken, "undefined syntax: " + KeyToken.ParsedText, 0);
   return EndIdx;
 }
Example #2
0
  public static UntypedNode ParseNewNode2(
      KNameSpace ns,
      UntypedNode PrevNode,
      ArrayList<KToken> TokenList,
      int BeginIdx,
      int EndIdx,
      int ParseOption) {
    UntypedNode LeftNode = null;
    KToken.DumpTokenList(0, "ParseNewNode2", TokenList, BeginIdx, EndIdx);
    while (BeginIdx < EndIdx) {
      int NextIdx = BeginIdx;
      KToken KeyToken = TokenList.get(NextIdx);
      KSyntax Syntax = KeyToken.ResolvedSyntax;
      // KonohaDebug.P("nextIdx="+NextIdx+",Syntax="+Syntax);
      if (LeftNode == null) {
        if (Syntax.IsDelim()) { // A ; B
          NextIdx++;
        } else {
          LeftNode = new UntypedNode(ns, KeyToken);
          NextIdx = LeftNode.ParseToken(KeyToken, TokenList, NextIdx, EndIdx);
        }
      } else {
        if (Syntax.IsDelim()) { // A ; B
          ParseNewNode2(ns, LeftNode, TokenList, NextIdx, EndIdx, AllowEmpty);
          break;
        } else if (Syntax.IsBinaryOperator()) { // A + B
          UntypedNode RightNode = ParseNewNode2(ns, null, TokenList, NextIdx + 1, EndIdx, 0);
          LeftNode = BinaryNode(ns, LeftNode, KeyToken, RightNode);
          break;
        } else if (Syntax.IsSuffixOperator()) { // A []
          NextIdx = LeftNode.ParseToken(KeyToken, TokenList, NextIdx, EndIdx);
        } else {

        }
      }
      if (!(BeginIdx < NextIdx)) {
        KonohaDebug.P("Panic ** " + Syntax + " BeginIdx=" + BeginIdx + ", NextIdx=" + NextIdx);
        break;
      }
      BeginIdx = NextIdx;
    }
    if (LeftNode == null) {}

    if (PrevNode != null && LeftNode != null) {
      PrevNode.LinkNode(LeftNode);
    }
    return LeftNode;
  }