grammar

Closure properties of context free languages

一个人想着一个人 提交于 2019-12-31 04:15:39
问题 I have the following problem: Languages L1 = {a^n * b^n : n>=0} and L2 = {b^n * a^n : n>=0} are context free languages so they are closed under the L1L2 so L={a^n * b^2n A^n : n>=0} must be context free too because it is generated by a closure property. I have to prove if this is true or not. So I checked the L language and I don’t think that it is context free then I also saw that L2 is just L1 reversed. Do I have to check if L1, L2 are deterministic? 回答1: L1={a n b n : n>=0} and L2={b n a n

How to match parentheses / brackets in pyparsing

只谈情不闲聊 提交于 2019-12-31 02:00:06
问题 I have a grammar token specified as: list_value = Suppress(oneOf("[ (")) + Group( delimitedList(string_value | int_value))("list") + Suppress(oneOf("] )")) However, this obviously allows (foo, bar] How do I enforce that the lists opening and closing characters must match? 回答1: You make a list a choice between two rules: one for parentheses and one for square brackets. Thanks for bringing up pyparsing. I like it. My answer for your question is: delim_value = Group(delimitedList(string_value |

Examples of Non Context free language in C language?

拟墨画扇 提交于 2019-12-30 12:12:40
问题 What are examples of non - context free languages in C language ? How the following non-CFL exists in C language ? a) L1 = {wcw|w is {a,b}*} b) L2 = {a^n b^m c^n d^m| n,m >=1} 回答1: The question is clumsily worded, so I'm reading between the lines, here. Still, it's a common homework/study question. The various ambiguities [1] in the C grammar as normally presented do not render the language non-context-free. (Indeed, they don't even render the grammars non-context-free.) The general rule "if

Writing XSS Filter for (X)HTML Based on White List

有些话、适合烂在心里 提交于 2019-12-30 10:38:26
问题 I need to implement a simple and efficient XSS Filter in C++ for CppCMS. I can't use existing high quality filters written in PHP because because it is high performance framework that uses C++. The basic idea is provide a filter that have a while list of HTML tags and a white list of options for these tags. For example. typical HTML input can consist of <b> , <i> , tags and <a> tag with href . But straightforward implementation is not good enough, because, even allowed simple links may

HTML5 Speech recognition — is there a way to set what the user is expected to say dynamically? (Using custom Grammars)

断了今生、忘了曾经 提交于 2019-12-30 01:58:10
问题 I am looking for a way to define what you expect the user to say in an <input> tag with the HTML 5 speech attribute set. I know that you can specify a specific grammar to use via the grammar attribute, like this: <input type="text" speech grammar="grammar.grxml" /> ( see http://lists.w3.org/Archives/Public/public-xg-htmlspeech/2011Feb/att-0020/api-draft.html ) but I was hoping for a way to make this dynamic, so that I can specify what I expect the user to say via javascript. For example, if

Efficient Context-Free Grammar parser, preferably Python-friendly

浪子不回头ぞ 提交于 2019-12-29 14:21:59
问题 I am in need of parsing a small subset of English for one of my project, described as a context-free grammar with (1-level) feature structures (example) and I need to do it efficiently . Right now I'm using NLTK's parser which produces the right output but is very slow. For my grammar of ~450 fairly ambiguous non-lexicon rules and half a million lexical entries, parsing simple sentences can take anywhere from 2 to 30 seconds, depending it seems on the number of resulting trees. Lexical

Difference between an LL and Recursive Descent parser?

隐身守侯 提交于 2019-12-29 10:07:12
问题 I've recently being trying to teach myself how parsers (for languages/context-free grammars) work, and most of it seems to be making sense, except for one thing. I'm focusing my attention in particular on LL(k) grammars , for which the two main algorithms seem to be the LL parser (using stack/parse table) and the Recursive Descent parser (simply using recursion). As far as I can see, the recursive descent algorithm works on all LL(k) grammars and possibly more, whereas an LL parser works on

Is there a way to generate unit test to test my grammar

假如想象 提交于 2019-12-29 09:11:15
问题 I created my grammar using antlr4 but I want to test robustess is there an automatic tool or a good way to do that fast Thanks :) 回答1: The only way I found to create unit tests for a grammar is to create a number of examples from a written spec of the given language. This is neither fast, nor complete, but I see no other way. You could be tempted to create test cases directly from the grammar (writing a tool for that isn't that hard). But think a moment about this. What would you test then?

Boost.Spirit SQL grammar/lexer failure

ぐ巨炮叔叔 提交于 2019-12-29 08:03:36
问题 I have two problems with the following SQL grammar: #define BOOST_SPIRIT_QI_DEBUG #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/lex_lexertl.hpp> #include <boost/spirit/include/phoenix.hpp> #include <boost/spirit/include/karma.hpp> #include <boost/fusion/include/adapt_struct.hpp> #include <boost/fusion/include/std_pair.hpp> #include <boost/algorithm/string.hpp> #include <boost/shared_ptr.hpp> #include <boost/make_shared.hpp> #include <boost/lexical_cast.hpp> #include

Boost.Spirit SQL grammar/lexer failure

元气小坏坏 提交于 2019-12-29 08:03:11
问题 I have two problems with the following SQL grammar: #define BOOST_SPIRIT_QI_DEBUG #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/lex_lexertl.hpp> #include <boost/spirit/include/phoenix.hpp> #include <boost/spirit/include/karma.hpp> #include <boost/fusion/include/adapt_struct.hpp> #include <boost/fusion/include/std_pair.hpp> #include <boost/algorithm/string.hpp> #include <boost/shared_ptr.hpp> #include <boost/make_shared.hpp> #include <boost/lexical_cast.hpp> #include