Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which programming language has very short context-free Grammar in its formal specification?

Tags:

python

c

bash

vhdl

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.

like image 369
psihodelia Avatar asked Nov 21 '09 22:11

psihodelia


People also ask

What is context-free grammar in programming?

A context-free grammar is a set of recursive rewriting rules (or productions) used to generate patterns of strings. Context-free grammars are often used to define the syntax of programming languages. A parse tree displays the structure used by a grammar to generate an input string.

Does C have a context-free grammar?

Are C and C++ context-free languages? No, C and C++ are context-sensitive languages.

Is Python a context-free grammar?

Python is not a context free language.

Which languages are context-free?

All regular languages are context-free languages, but not all context-free languages are regular. Most arithmetic expressions are generated by context-free grammars, and are therefore, context-free languages.


2 Answers

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.

like image 125
mjv Avatar answered Oct 25 '22 14:10

mjv


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 .

like image 32
Carl Smotricz Avatar answered Oct 25 '22 15:10

Carl Smotricz