【问题标题】:how to identify the next possible node from grammar using tokenStream?如何使用 tokenStream 从语法中识别下一个可能的节点?
【发布时间】:2019-03-21 10:47:32
【问题描述】:

我正在创建一个文本区域,它像大多数 IDE 一样具有智能感知功能。我的方法是使用earley解析器算法。

我正在使用early-parser-js library

下面是语法:

S -> NP VP
VP -> VP PP | V NP | V
PP -> P NP
NP -> Det N | N | Pn | Det A N | A NP
A -> Adv A | A A
Adv -> too | very | quite
Pn -> she | he
A -> fresh | tasty | silver
N -> fish | fork | apple
V -> eats 
Det -> a | an | the
P -> with

现在,如果我在 textarea 中写“she”,我的代码应该会建议下一个可能的节点,例如“eats”、“fish”、“fork”等。

【问题讨论】:

    标签: javascript jquery parsing context-free-grammar earley-parser


    【解决方案1】:

    我使用下面的代码实现了这一点

     var results = [];
            var lastColumn = this.chart.length -1 ;
            for(var j in this.chart[lastColumn])
            {
             if(!this.chart[lastColumn][j].expectedNonTerminal(grammar))
             {
            results.push(this.chart[lastColumn][j].rhs.toString());
             }
            }
    
            return results;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-07-30
      • 1970-01-01
      • 2014-05-10
      • 2021-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多