grammar

C++ Template Ambiguity

半城伤御伤魂 提交于 2019-12-19 02:18:27
问题 A friend and I were discussing C++ templates. He asked me what this should do: #include <iostream> template <bool> struct A { A(bool) { std::cout << "bool\n"; } A(void*) { std::cout << "void*\n"; } }; int main() { A<true> *d = 0; const int b = 2; const int c = 1; new A< b > (c) > (d); } The last line in main has two reasonable parses. Is 'b' the template argument or is b > (c) the template argument? Although, it is trivial to compile this, and see what we get, we were wondering what resolves

Parse comment line

十年热恋 提交于 2019-12-18 21:18:22
问题 Given the following basic grammar I want to understand how I can handle comment lines. Missing is the handling of the <CR><LF> which usually terminates the comment line - the only exception is a last comment line before the EOF, e. g.: # comment abcd := 12 ; # comment eof without <CR><LF> grammar CommentLine1a; //========================================================== // Options //========================================================== //=================================================

Programmatically derive a regular expression from a string

倾然丶 夕夏残阳落幕 提交于 2019-12-18 17:09:02
问题 I would like to input a string and return a regular expression that can be used to describe the string's structure. The regex will be used to find more strings of the same structure as the first. This is intentionally ambiguous because I will certainly miss a case that someone in the SO community will catch. Please post any and all possible ways to do this. 回答1: The trivial answer, and probably not what you want, is: return the input string (with regex special characters escaped). That is

Programmatically derive a regular expression from a string

你说的曾经没有我的故事 提交于 2019-12-18 17:07:11
问题 I would like to input a string and return a regular expression that can be used to describe the string's structure. The regex will be used to find more strings of the same structure as the first. This is intentionally ambiguous because I will certainly miss a case that someone in the SO community will catch. Please post any and all possible ways to do this. 回答1: The trivial answer, and probably not what you want, is: return the input string (with regex special characters escaped). That is

Converting grammar to Chomsky Normal Form?

倾然丶 夕夏残阳落幕 提交于 2019-12-18 15:19:01
问题 Convert the grammar below into Chomsky Normal Form. Give all the intermediate steps. S -> AB | aB A -> aab|lambda B -> bbA Ok so the first thing I did was add a new start variable S0 so now I have S0 -> S S -> AB | aB A -> aab|lambda B -> bbA then I removed all of the lambda rules: S0 -> S S -> AB | aB | B A -> aab B -> bbA | bb Then I checked for S->S and A->B type rules which did not exist. And that was the answer I came up with, do I need to do anything further or did I do anything wrong?

Converting grammar to Chomsky Normal Form?

时光毁灭记忆、已成空白 提交于 2019-12-18 15:18:37
问题 Convert the grammar below into Chomsky Normal Form. Give all the intermediate steps. S -> AB | aB A -> aab|lambda B -> bbA Ok so the first thing I did was add a new start variable S0 so now I have S0 -> S S -> AB | aB A -> aab|lambda B -> bbA then I removed all of the lambda rules: S0 -> S S -> AB | aB | B A -> aab B -> bbA | bb Then I checked for S->S and A->B type rules which did not exist. And that was the answer I came up with, do I need to do anything further or did I do anything wrong?

ANTLR Parse tree modification

三世轮回 提交于 2019-12-18 13:16:13
问题 I'm using ANTLR4 to create a parse tree for my grammar, what I want to do is modify certain nodes in the tree. This will include removing certain nodes and inserting new ones. The purpose behind this is optimization for the language I am writing. I have yet to find a solution to this problem. What would be the best way to go about this? 回答1: While there is currently no real support or tools for tree rewriting, it is very possible to do. It's not even that painful. The ParseTreeListener or

Reserved keywords in Objective-C?

天涯浪子 提交于 2019-12-18 12:59:15
问题 At the CocoaHeads Öresund meeting yesterday, peylow had constructed a great ObjC quiz. The competition was intense and three people were left with the same score when the final question was to be evaluated: How many reserved keywords does Objective-C add to C? Some spirited debate followed. All agreed that @interface , @implementation etc are all pre-processor directives rather than keywords, but how about something like in ? It might be a keyword, but it's not a reserved keyword. For example

Construct grammar given the following language {a^n b^m | n,m = 0,1,2,…,n <= 2m} [closed]

一曲冷凌霜 提交于 2019-12-18 12:42:55
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 6 years ago . I just took my midterm but couldn't answer this question. Can someone please give a couple of examples of the language and construct a grammar for the

Using adaptive grammars [closed]

荒凉一梦 提交于 2019-12-18 12:30:17
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 9 months ago . I'm trying to implement a language (or family of languages) whose grammar can be changed dynamically. I have found no examples that serve as study cases. Can you give me some reference to any that are actually used in the real world (even from the academic world)? Does it make sense to implement a Domain