Questions tagged [grammar]

A formal grammar is a set of production rules that describe how to form strings of valid syntax. Formal Grammars are most often used to specify the syntax of a programming language.

A formal grammar is a set of production rules that describe how to form strings of valid syntax. Formal Grammars are most often used to specify the syntax of a programming language.

A grammar is formally defined as a 4-tuple, consisting of a series of production rules, terminal symbols, nonterminal symbols, and a start symbol, which itself is a nonterminal. Any terminal cannot be a nonterminal and vice-versa.

Grammars prove very useful in parsers for programming languages. A grammar can be used to determine the syntactical correctness of a given string.

Parser generators such as JavaCC or ANTLR use a given grammar (usually one of a particular form, and free of ambiguities) to generate the parser.

3251 questions
55
votes
51 answers

Is there a human readable programming language?

I mean, is there a coded language with human style coding? For example: Create an object called MyVar and initialize it to 10; Take MyVar and call MyMethod() with parameters. . . I know it's not so useful, but it can be interesting to create such a…
Enrico Murru
  • 2,313
  • 4
  • 21
  • 24
54
votes
3 answers

Why isn't this a syntax error in python?

Noticed a line in our codebase today which I thought surely would have failed the build with syntax error, but tests were passing so apparently it was actually valid python (in both 2.x and 3). Whitespace is sometimes not required in the…
wim
  • 338,267
  • 99
  • 616
  • 750
50
votes
4 answers

Is HTML a context-free language?

Reading some related questions made me think about the theoretical nature of HTML. I'm not talking about XHTML-like code here. I'm talking about stuff like this crazy piece of markup, which is perfectly valid HTML(!)
user123444555621
  • 148,182
  • 27
  • 114
  • 126
49
votes
3 answers

Context-free grammars versus context-sensitive grammars?

Can someone explain to me why grammars [context-free grammar and context-sensitive grammar] of this kind accepts a String? What I know is Context-free grammar is a formal grammar in which every production(rewrite) rule is a form of V→w Where V is…
45
votes
3 answers

Ruby Grammar

I'm looking for Ruby grammar in BNF form. Is there an official version?
user68109
  • 2,446
  • 6
  • 21
  • 20
43
votes
6 answers

BNF vs EBNF vs ABNF: which to choose?

I want to come up with a language syntax. I have read a bit about these three, and can't really see anything that one can do that another can't. Is there any reason to use one over another? Or is it just a matter of preference?
Jason Baker
  • 192,085
  • 135
  • 376
  • 510
42
votes
5 answers

In Javadocs, how should I write plural forms of singular Objects in tags?

I have a class named Identity. In my javadoc comments I am referencing it as a plural. I can think of two solutions: change the reference to Identities or Identitys. Neither of these feel correct, and I'm wondering if…
maxbfuer
  • 839
  • 2
  • 9
  • 15
42
votes
3 answers

Does the '@' symbol have special meaning in Javascript, Coffeescript or Jquery?

I have some code that looks like self = @ and then later on it's using @someMethodName or self.someMethodName Does @ have some special meaning?
Noah Clark
  • 8,101
  • 14
  • 74
  • 116
39
votes
7 answers

How do I do dependency parsing in NLTK?

Going through the NLTK book, it's not clear how to generate a dependency tree from a given sentence. The relevant section of the book: sub-chapter on dependency grammar gives an example figure but it doesn't show how to parse a sentence to come up…
MrD
  • 2,405
  • 3
  • 22
  • 23
38
votes
2 answers

Is "Implicit token definition in parser rule" something to worry about?

I'm creating my first grammar with ANTLR and ANTLRWorks 2. I have mostly finished the grammar itself (it recognizes the code written in the described language and builds correct parse trees), but I haven't started anything beyond that. What worries…
Matěj Zábský
  • 16,909
  • 15
  • 69
  • 114
36
votes
5 answers

Is there a standard C++ grammar?

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…
Lazer
  • 90,700
  • 113
  • 281
  • 364
36
votes
5 answers

Separate word lists for nouns, verbs, adjectives, etc

Usually word lists are 1 file that contains everything, but are there separately downloadable noun list, verb list, adjective list, etc? I need them for English specifically.
polygenelubricants
  • 376,812
  • 128
  • 561
  • 623
34
votes
3 answers

chomsky hierarchy in plain english

I'm trying to find a plain (i.e. non-formal) explanation of the 4 levels of formal grammars (unrestricted, context-sensitive, context-free, regular) as set out by Chomsky. It's been an age since I studied formal grammars, and the various definitions…
33
votes
10 answers

Is there a name meaning "not a singleton"?

Is there a name meaning "not a singleton"?
Richard Nagle
  • 11,974
  • 3
  • 21
  • 16
30
votes
3 answers

Selecting the most fluent text from a set of possibilities via grammar checking (Python)

Some background I am a literature student at New College of Florida, currently working on an overly ambitious creative project. The project is geared towards the algorithmic generation of poetry. It's written in Python. My Python knowledge and…
floer32
  • 2,190
  • 4
  • 29
  • 50