11

I scoured the Mix and Solidity repos for something like a formal definition of the language's grammar, so that one may generate parsers using tools like GrammarKit, but couldn't find anything.

Any pointers?

q9f
  • 32,913
  • 47
  • 156
  • 395
mxk
  • 243
  • 1
  • 6
  • 1
    If there's no answer here, I suggest trying https://gitter.im/ethereum/solidity – eth Jun 15 '16 at 09:57

5 Answers5

10

There's a file called grammar.txt in the Solidity repo:

https://github.com/ethereum/solidity/blob/develop/docs/grammar.txt

That's probably what you're looking for?

max taldykin
  • 2,966
  • 19
  • 27
Jamie Hale
  • 1,005
  • 7
  • 18
  • Thanks! I searched for "grammar" in the same repo, and the only thing GitHub was able to find was "Scanner.cpp"... Too bad they're not using BNF, I might raise an issue for that. Should be easy to convert though. – mxk Jun 15 '16 at 15:02
  • @Matthias could you explain how to convert that file to BNF? – Sri Aug 14 '16 at 20:07
  • 2
    NOTE: This has now moved to https://github.com/ethereum/solidity/blob/develop/docs/grammar.txt – Richard Horrocks Jan 05 '17 at 15:07
  • the 2nd link is also broken, but here’s a “mirror”: https://ethereumacademy.blogspot.com/2017/10/describing-syntax-of-solidity-using-bnf.html?m=1 – Erik Kaplun Mar 01 '21 at 14:41
8

I wrote an ANTLR4 grammar for Solidity that you may find useful:

https://github.com/solidityj/solidity-antlr4

It can generate parsers in any of the ANTLR supported targets and it has full support for the Solidity language as of today.

Federico B.
  • 191
  • 1
  • 2
2

Here's yet another link pointing to the solidity documentation:

http://solidity.readthedocs.io/en/develop/miscellaneous.html#language-grammar

0

There is also a grammar based on javascript grammar.

Tom Hale
  • 3,107
  • 4
  • 20
  • 37