Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: Severos on November 18, 2017, 04:08:43 PM



Title: Bitcoin Script language grammar?
Post by: Severos on November 18, 2017, 04:08:43 PM
This wiki page contain pretty much helpful info: https://en.bitcoin.it/wiki/Script  since it has all the 'words' accepted in the scripting language.
However, I was wondering if there's something like a grammar to this language? something like the grammar used to build parse tree for other languages.

Reason I'm looking for this is that I have a project at university for the compilers course, so I was looking into building a parse tree for the bitcoin scripts.

Thanks in advance.


Title: Re: Bitcoin Script language grammar?
Post by: 2112 on November 18, 2017, 07:02:05 PM
The context-free grammar is trivial, just a concatenation of lexical elements (alphabet symbols). All the expressive power is contained in the context (in this case, the contents of the stacks). It is equivalent to a simple RPN (reverse-polish notation) calculator, it doesn't even use parentheses for disambiguating the order of operations.

Since you've mentioned "university course": the formal languages aren't a good tool to analyze simple stack machines like the one in Bitcoin. You would just waste time trying to analyze it at this level. Search for another, more productive, subject for your coursework.


Title: Re: Bitcoin Script language grammar?
Post by: Severos on November 18, 2017, 07:54:33 PM
Thanks for your explanation, do you think it'll be worth trying to do it for the ethereum solidity language ??


Title: Re: Bitcoin Script language grammar?
Post by: 2112 on November 18, 2017, 08:09:46 PM
Thanks for your explanation, do you think it'll be worth trying to do it for the ethereum solidity language ??
Yeah, with Solidity the context-free grammars are the proper tool-set to for the problem domain.

You'd really will have to discuss this with your scientific advisor at your school. They will need to help you select a project with the proper difficulty level for your school and your degree. My advice is: prepare a palette of possible projects, some too trivial (like your original idea), some too complex, and have have a discussion with the a teacher at your school who knows you and who will grade your coursework.