Requires the igraph and ggraph packages, which you can install with install.packages(c("igraph", "ggraph")). Draws a simple tree plot of the parse tree, showing parent-child relationships, tokens and types.

The utility functions lexl_edges(), lexl_vertices(), and lexl_igraph() compute each stage in plotting the final graph.

# S3 method for lexl
plot(x, ...)

lexl_edges(x)

lexl_vertices(x)

lexl_igraph(x)

Arguments

x

parse tree from lexl()

...

ignored, for consistency with the base plot() function

See also

lexl::lex_xl(), lexl::demo_lexl()

Examples

x <- lex_xl("MIN(3,MAX(2,A1))") lexl_edges(x)
#> from to #> 1 0 1 #> 2 0 2 #> 3 0 11 #> 4 2 3 #> 5 2 4 #> 6 2 5 #> 7 2 6 #> 8 2 10 #> 9 6 7 #> 10 6 8 #> 11 6 9
lexl_vertices(x)
#> id label type token #> 1 0 root root root #> 2 1 MIN\nfunction function MIN #> 3 2 (\nfun_open fun_open ( #> 4 3 3\nnumber number 3 #> 5 4 ,\nseparator separator , #> 6 5 MAX\nfunction function MAX #> 7 6 (\nfun_open fun_open ( #> 8 7 2\nnumber number 2 #> 9 8 ,\nseparator separator , #> 10 9 A1\nref ref A1 #> 11 10 )\nfun_close fun_close ) #> 12 11 )\nfun_close fun_close )
if (interactive() && require(igraph, quietly = TRUE)) { lexl_igraph(x) } if (interactive() && require(igraph, quietly = TRUE) && require(ggraph, quietly = TRUE)) { plot(x) }