grammar

Why the need for terminals? Is my solution sufficient enough?

巧了我就是萌 提交于 2019-11-27 16:20:03
I'm trying to get my head around context free grammars and I think I'm close. What is baffling me is this one question (I'm doing practise questions as I have an exam in a month's time): I've come up with this language but I believe it's wrong. S --> aSb | A | B A --> aA | Σ B --> bB | Σ Apparently this is the correct solution: S --> aSb | aA | bB A --> aA | Σ B --> bB | Σ What I don't quite understand is why we have S --> aSb | aA | bB and not just S --> aSb | A | B . What is the need for the terminals? Can't I just call A instead and grab my terminals that way? Testing to see if I can

Which type of quotes we should use in css background url (“…”)? Single, double or no quote needed? [duplicate]

我怕爱的太早我们不能终老 提交于 2019-11-27 14:59:59
This question already has an answer here: Is quoting the value of url() really necessary? 7 answers this background:url(http://url); this background:url("http://url"); or this background:url('http://url'); The URL bits of all three of your examples are valid CSS, according to the CSS specification . Note that the spec identifies some characters in a URL which will need to be escaped with a backslash if present in an unquoted URI, such as parentheses, commas, white space characters, single quotes (') and double quotes ("). For this reason, you might find it better to use single or double quotes

History of trailing comma in programming language grammars

笑着哭i 提交于 2019-11-27 14:39:55
Many programming languages allow trailing commas in their grammar following the last item in a list. Supposedly this was done to simplify automatic code generation, which is understandable. As an example, the following is a perfectly legal array initialization in Java ( JLS 10.6 Array Initializers ): int[] a = { 1, 2, 3, }; I'm curious if anyone knows which language was first to allow trailing commas such as these. Apparently C had it as far back as 1985 . Also, if anybody knows other grammar "peculiarities" of modern programming languages, I'd be very interested in hearing about those also. I

Grammatical inference of regular expressions for given finite list of representative strings?

删除回忆录丶 提交于 2019-11-27 13:11:38
I'm working on analyzing a large public dataset with lots of verbose human-readable strings that were clearly generated by some regular (in the formal language theory sense) grammar. It's not too hard to look at sets of these strings one by one to see the patterns; unfortunately, there's about 24,000 of these unique strings broken up into 33 categories and 1714 subcategories, so it's somewhat painful to do this manually. Basically, I'm looking for an existing algorithm (preferably with an existing reference implementation ) to take an arbitrary list of strings and try to infer some minimal

Is there a fast algorithm to determine the godel number of a term of a context free language?

↘锁芯ラ 提交于 2019-11-27 13:11:24
问题 Suppose we have a simple grammar specification. There is a way to enumerate terms of that grammar that guarantees that any finite term will have a finite position, by iterating it diagonally. For example, for the following grammar: S ::= add add ::= mul | add + mul mul ::= term | mul * term term ::= number | ( S ) number ::= digit | digit number digit ::= 0 | 1 | ... | 9 You can enumerate terms like that: 0 1 0+0 0*0 0+1 (0) 1+0 0*1 0+0*0 00 ... etc My question is: is there a way to do the

Ruby Grammar

回眸只為那壹抹淺笑 提交于 2019-11-27 11:13:08
I'm looking for Ruby grammar in BNF form. Is there an official version? Adrian Grigore Yes, there is one Ruby BNF syntax by the University of buffalo. Edit: I've also found this alternate Ruby BNF syntax . The YACC syntax is in the Ruby source. Download it and run the bundled utiliy to get the readable syntax. wget ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p195.tar.gz tar xvzf ruby-2.0.0-p195.tar.gz cd ruby-2.0.0-p195 ruby sample/exyacc.rb < parse.y Output sample (total 918 lines for the v2.0.0-p195) program : top_compstmt ; top_compstmt : top_stmts opt_terms ; top_stmts : none | top

Is there a standard C++ grammar?

左心房为你撑大大i 提交于 2019-11-27 10:00:39
问题 Does the standard specify the official C++ grammar? I searched, but did not find it anywhere. Also, I wish to read a bit about C++ grammar in detail, like which category of grammars it falls in, etc. Any links pointing me in the right direction would be helpful. By category, I mean taken from here. 回答1: Yes, it does. The grammar is described in detail throughout the standard and is summarized in Appendix A: Grammar Summary (it's Appendix A in both the C++03 standard and the C++0x final

Is C++ context-free or context-sensitive?

为君一笑 提交于 2019-11-27 09:24:35
I often hear claims that C++ is a context-sensitive language. Take the following example: a b(c); Is this a variable definition or a function declaration? That depends on the meaning of the symbol c . If c is a variable , then a b(c); defines a variable named b of type a . It is directly initialized with c . But if c is a type , then a b(c); declares a function named b that takes a c and returns an a . If you look up the definition of context-free languages, it will basically tell you that all grammar rules must have left-hand sides that consist of exactly one non-terminal symbol. Context

What does this JavaScript snippet mean? [duplicate]

不打扰是莪最后的温柔 提交于 2019-11-27 09:20:56
This question already has an answer here: What is the (function() { } )() construct in JavaScript? 23 answers I have not met this type of grammar before. What does it mean? To what technique is it related? (function(fun) { })(myFunkyAlert); Ibu This is an anonymous function that will run as soon as it is declared. Its parameter is myFunkyAlert and inside the function it will be referenced as the fun variable. The reason we usually write a function like that is to avoid conflicts, due to scoping. Example: var myFunkyAlert = "The funky alert"; (function(fun) { alert(fun); })(myFunkyAlert); This

How can error reporting in grammars be improved?

烂漫一生 提交于 2019-11-27 09:15:30
Is there a way to get Perl 6 to generate an error message if a grammar does not match? Or at least return the position of the last data it processed? It is quite hard to fix syntax errors if all I get from the parser is 'no match'. If your focus is generating messages for users of your grammar, see Generating Good Parse Errors from a Parser and Grammar::ErrorReporting . The rest of this answer is about debugging. First, you can embed arbitrary closures (code) in Perl 6 rules (or tokens or regexes). Just type { your code goes here } in the middle of a rule. So you could just sprinkle { say ...