12

What programming language has short and beautiful grammars (in EBNF)?

Some languages are easer to be parsed. Some time ago I have created a simple VHDL parser, but it was very slow. Not because it is implemented completely in Python, but because VHDL grammar (in EBNF) is huge. The EBNF of Python is beautiful but it is not very short.

I suggest that many functional programming languages like LISP have short simple grammars, but I am interested in a more popular simple imperative language like C or Bash.

2
  • 2
    Refreshing! A language question not involving Go... Man, you are so not "in" ;-) Commented Nov 21, 2009 at 23:12
  • 1
    brainf**k, muppetlabs.com/~breadbox/bf :) Commented Nov 21, 2009 at 23:53

6 Answers 6

5

I haven't compared, but Lua is a language renowned for its simple syntax. The BNF is at the very end of this reference manual: http://www.lua.org/manual/5.1/manual.html .

Sign up to request clarification or add additional context in comments.

3 Comments

OK, I was curious so I looked. In terms of simplicity, Lua wins hands down against Oberon and even Component Pascal.
@ Carl Smotricz Please, see my comment below my answer. =)
The Lua BNF leaves some functionality, like operator precedence, to the semantic layer. Many other simple languages (Pascal, Modula, Oberon) code the operator precedence into the grammar.
4

Assembly languages!

...in general, and particularly for CPUs which have a simple architecture (few instructions, few addressing modes, few registers) have a relatively short grammar.

In fact, specialized processors, such as these found in programmable logic controllers can have a language with even simpler grammars. But then again the most simple of the PLCs are little more than Boolean equation calculators.

2 Comments

The problem about assembly language is that its grammar is not structured at all, just a list of instructions..
On top of it, @Jack, the "language" goes beyond the opcodes and EA expressions--it needs to include the macros, symbols, directives, and ... that are all defined by the assembler itself. Once we consider that, we usually end up with a pretty messy grammar.
3

One of the simplest imperative languages is Oberon-2. Syntax of Oberon-2.

Also take a look at Oberon-07 (The Programming Language Oberon-07, PDF) and Component Pascal.

3 Comments

Gosh that looks familiar. It appears to be closely related to Modula-2, which itself was a direct descendant of Pascal.
please see an answer below - Lua's BNF is much better
@ psihodelia I don't want to start holy war, but some clarifications: 1) About 30 EBNF rules in Oberon-2 syntax and about 20 rules in the case of Lua. Much better? I should say comparable. Strong static typing and direct support of OOP is the source of 10 additional rules in Oberon. 2) Lua is not imperative language. It's multi-paradigm. And you sad, that you are "interested in simple imperative language".
1

Pascal has only 2-3 pages of BNF notations

1 Comment

46 rules, 3 pages, GOTO ommited docstoc.com/docs/36767423/…
0

What about GL Shading language? Language Specification (PDF)

However for these kind of hobbies I always preferred to implement a subset of a known language by myself without choosing anything "premade"..

2 Comments

It would be nice to add a pointer that the link points to a PDF file.
(1) Your browser's status line probably tells you, you just need to be compulsive about checking - which is good anti-virus advice too. (2) I hate PDF too. Forget the Taliban, nuke Adobe! (KIDDING!!)
-1

Lisp is probably pretty small.

lisp ::= `(´ exp `)´ 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.