Path Querying with Conjunctive Grammars by Matrix Multiplication

  • 26 Accesses


Problems in many areas can be reduced to one of the formal-languages-constrained path problems. Conjunctive grammars are more expressive than context-free grammars and are used, for example, in static analysis to describe an interleaved matched-parentheses language, which is not context-free. Path querying with conjunctive grammars is known to be undecidable. There is an algorithm for path querying with linear conjunctive grammars which provides an over-approximation of the result, but there is no algorithm for arbitrary conjunctive grammars. We propose the first algorithm for path querying with arbitrary conjunctive grammars. The proposed algorithm is matrix-based and allows us to efficiently apply GPGPU (General-Purpose computing on Graphics Processing Units) computing techniques and other optimizations for matrix operations.

This is a preview of subscription content, log in to check access.

Access options

Buy single article

Instant unlimited access to the full article PDF.

US$ 39.95

Price includes VAT for USA

Fig. 1.
Fig. 2.
Fig. 3.
Fig. 4.
Fig. 5.
Fig. 6.
Fig. 7.
Fig. 8.
Fig. 9.


  1. 1.

    GitHub repository of the YaccConstructor project: https://

  2. 2.

    The Math.Net Numerics WebSite:

  3. 3.

    GitHub repository of the managedCuda library:


  1. 1

    Barrett, Ch., Jacob, R., and Marathe, M., Formal-language-constrained path problems, SIAM J. Comput., 2000, vol. 30, no. 3, pp. 09–837.

  2. 2

    Bastani, O., Anand, S., and Aiken, A., Specification inference using context-free language reachability, ACM SIGPLAN Notices, ACM, 2015, vol. 50, pp. 553–566.

  3. 3

    Xu, G., Rountev, A., and Sridharan, M., Scaling c-reachability-based points-to analysis using context-sensitive must-not-alias analysis, ECOOP, Springer, 2009, vol. 9, pp. 98–122.

  4. 4

    Reps, T., Program analysis via graph reachability, Inf. Software Technol., 1998, vol. 40, no. 11, pp. 701–726.

  5. 5

    Zhang, Q. and Su, Z., Context-sensitive data-dependence analysis via linear conjunctive language reachability, Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages, ACM, 2017, pp. 344–358.

  6. 6

    Hellings, J., Conjunctive Context-Free Path Queries, 2014.

  7. 7

    Azimov, R. and Grigorev, S., Context-free path querying by matrix multiplication, Proceedings of the 1st ACM SIGMOD Joint International Workshop on Graph Data Management Experiences and Systems (GRADES) and Network Data Analytics (NDA), ACM, 2018, p. 5.

  8. 8

    Grigorev, S. and Ragozina, A., Context-free path querying with structural representation of result, Proceedings of the 13th Central and Eastern European Software Engineering Conference in Russia, ACM, 2017, p. 10.

  9. 9

    Sevon, P. and Eronen, L., Subgraph queries by context-free grammars, J. Integrative Bioinformatics, 2008, vol. 5, no. 2, p. 100.

  10. 10

    Zhang, X., Feng, Z., Wang, X., Rao, G., and Wu, W., Context-free path queries on rdf graphs, International Semantic Web Conference, Springer, 2016, pp. 632–648.

  11. 11

    Okhotin, A., Conjunctive and boolean grammars: the true general case of the context-free grammars, Comput. Sci. Rev., 2013, vol. 9, pp. 27–59.

  12. 12

    Okhotin, A., Conjunctive grammars, J. Automata, Languages,Combinatorics, 2001, vol. 6, no. 4, pp. 519–535.

  13. 13

    Abiteboul, S. and Vianu, V., Regular path queries with constraints, Proceedings of the Sixteenth ACM SIGACT-SIGMOD-SIGART Symposium on Principles of Database Systems, ACM, 1997, pp. 122–133.

  14. 14

    Fan, W., Li, J., Ma, Sh., Tang, N., and Wu, Y., Adding regular expressions to graph reachability and pattern queries, Data Engineering (ICDE),2011IEEE 27th International Conference on, IEEE, 2011, pp. 39–50.

  15. 15

    Nolé, M. and Sartiani, C., Regular path queries on massive graphs, Proceedings of the 28th International Conference on Scientific and Statistical Database Management, ACM, 2016, p. 13.

  16. 16

    Reutter, J.L., Romero, M., and Vardi, M.Y., Regular queries on graph databases, Theory Comput. Systems, 2017, vol. 61, no. 1, pp. 31–83.

  17. 17

    Kasami, T., An efficient recognition and syntax analysis algorithm for context-free languages, Technical report, DTIC Document, 1965.

  18. 18

    Younger, D.H., Recognition and parsing of context-free languages in time n3, Information and Control, 1967, vol. 10, no. 2, pp. 189–208.

  19. 19

    Grune, D. and Jacobs, C.J.H., Parsing Techniques (Monographs in Computer Science), NJ, USA, Secaucus: Springer-Verlag-New York, Inc., 2006.

  20. 20

    Hellings, J., Querying for paths in graphs using context-free path queries, arXiv preprint arXiv:1502.02242, 2015.

  21. 21

    Scott, E. and Johnstone, A., Gll parsing, Electronic Notes in Theoretical Computer Science, 2010, vol. 253, no. 7, pp. 177–189.

  22. 22

    Syme, D., Granicz, A., and Cisternino, A., Expert F# 3.0, Springer, 2012.

  23. 23

    Mendez-Lojo, M., Burtscher, M., and Pingali, K., A gpu implementation of inclusion-based points-to analysis, ACM SIGPLAN Notices, 2012, vol. 47, no. 8, pp. 107–116.

  24. 24

    Yu Su, Ding Ye, and Jingling Xue, Accelerating inclusion-based pointer analysis on heterogeneous cpu-gpu systems, High Performance Computing (HiPC),201320th International Conference on, IEEE, 2013, pp. 149–158.

  25. 25

    Yu Su, Ding Ye, Jingling Xue, and Xiang-Ke Liao, An efficient gpu implementation of inclusion-based pointer analysis, IEEE Transactions on Parallel and Distributed Systems, 2016, vol. 27, no. 2, pp. 353–366.

Download references

Author information

Correspondence to R. Azimov or S. Grigorev.

Rights and permissions

Reprints and Permissions

About this article

Verify currency and authenticity via CrossMark

Cite this article

Azimov, R., Grigorev, S. Path Querying with Conjunctive Grammars by Matrix Multiplication. Program Comput Soft 45, 357–364 (2019) doi:10.1134/S0361768819070041

Download citation


  • conjunctive grammars
  • path querying
  • graphs
  • transitive closure
  • static analysis
  • matrix multiplication