小编qdw*_*ang的帖子

如何解析上下文敏感的语法?

CSG类似于CFG,但减少符号是多个.

那么,我可以使用CFG解析器解析CSG,减少生产到多个终端或非终端吗?

喜欢

1. S ? a bc
2. S ? a S B c
3. c B ? W B
4. W B ? W X
5. W X ? B X
6. B X ? B c
7. b B ? b b
Run Code Online (Sandbox Code Playgroud)

当我们见面时W X,我们可以减少W XW B吗?

当我们见面时W B,我们可以减少W Bc B吗?

因此,如果CSG解析器基于CFG解析器,那么写起来并不难,是真的吗?

但是当我检查维基时,它说解析CSG,我们应该使用linear bounded automaton.

什么是linear bounded automaton

parsing context-free-grammar context-sensitive-grammar

6
推荐指数
1
解决办法
1881
查看次数

在构造一棵大树时,"thread'<main>'溢出了它的堆栈"

我实现了一个树结构:

use std::collections::VecDeque;
use std::rc::{Rc, Weak};
use std::cell::RefCell;

struct A {
    children: Option<VecDeque<Rc<RefCell<A>>>>
}

// I got thread '<main>' has overflowed its stack
fn main(){
    let mut tree_stack: VecDeque<Rc<RefCell<A>>> = VecDeque::new();

    // when num is 1000, everything works
    for i in 0..100000 {
        tree_stack.push_back(Rc::new(RefCell::new(A {children: None})));
    }

    println!("{:?}", "reach here means we are not out of mem");
    loop {
        if tree_stack.len() == 1 {break;}

        let mut new_tree_node = Rc::new(RefCell::new(A {children: None}));
        let mut tree_node_children: VecDeque<Rc<RefCell<A>>> = VecDeque::new();

        // combine last …
Run Code Online (Sandbox Code Playgroud)

rust

3
推荐指数
1
解决办法
931
查看次数

如何在ggplot2中支持循环绘图?

data <- data.frame(a=1:10, b=1:10 * 2, c=1:10 * 3)

library(ggplot2)

p <- ggplot(NULL, aes(x = 1:10))

# Using for loop will cause the plot only to draw the last line.
for (i in names(data)){
  p <- p + geom_line(aes(y = data[[i]], colour = i))
}

# Lines below works fine.
# p <- p + geom_line(aes(y = data[["a"]], colour = "a"))
# p <- p + geom_line(aes(y = data[["b"]], colour = "b"))
# p <- p + geom_line(aes(y = data[["c"]], …
Run Code Online (Sandbox Code Playgroud)

r ggplot2

2
推荐指数
1
解决办法
56
查看次数