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?


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


That's probably what you're looking for?

| improve this answer | |
  • 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. – Matthias 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 github.com/ethereum/solidity/blob/develop/docs/grammar.txt – Richard Horrocks Jan 5 '17 at 15:07

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


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

| improve this answer | |

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


| improve this answer | |

There is also a xText grammar, https://github.com/webdaford/smart-contract-tools/blob/master/workspace/com.dell.research.bc.eth.solidity.editor/src/com/dell/research/bc/eth/solidity/editor/Solidity.xtext which is quite similar to BNF.

| improve this answer | |

There is also a grammar based on javascript grammar.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.