tags:

views:

327

answers:

6

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.

A: 

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"..

Jack
It would be nice to add a pointer that the link points to a PDF file.
simon
(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!!)
Carl Smotricz
+2  A: 

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.

kemiisto
Gosh that looks familiar. It appears to be closely related to Modula-2, which itself was a direct descendant of Pascal.
wallyk
please see an answer below - Lua's BNF is much better
psihodelia
@ 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".
kemiisto
+1  A: 

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.

mjv
The problem about assembly language is that its grammar is not structured at all, just a list of instructions..
Jack
+3  A: 

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 .

Carl Smotricz
OK, I was curious so I looked. In terms of simplicity, Lua wins hands down against Oberon and even Component Pascal.
Carl Smotricz
@ Carl Smotricz Please, see my comment below my answer. =)
kemiisto
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.
Adrian McCarthy
+1  A: 

Pascal has only 2-3 pages of BNF notations

RocketSurgeon
A: 

Lisp is probably pretty small.

lisp ::= `(´ exp `)´
Robert
I am sorry, but have u really read my question ?
psihodelia