natefaubion/example-functional-compiler

data structure to define language

BebeSparkelSparkel opened this issue · 4 comments

Maybe this has been tried before but have you considered defining you language syntax as a data structure in a common format like json, yaml, dhall so that there can be a common reference for generating a parser for the multiple implementations of the parser.

This would allow parsers to be generated from the defined syntax so that there could be:

  • all parser implementation would remain up to date without as much maintenance since they generate the parser instead of having a static implementation of the parser that needs to be
  • clear changes to the actual language syntax in the version diffs not just the parser implementation
  • This makes it a dynamic language that is self modifying and allows for module, function, line level language extensions/contractions
  • less software rot because the code can specify which language version it is using and on the fly generate parsers for that version

Questions:

  • What should the data structure actually define? syntax to ast, syntax to lexer to ast
  • Should it define the progression of steps from syntax to lexed tokens to ast to system f? I don't like this solution because it constrains the modularity. Perhaps they could be separate definition files. Anyways, better suggestions would be appreciated.

Since this is a teaching tool, the only additional point I would consider adding for grammars would be some kind of BNF notation to explain standard rules for specifying a grammar.

What is BNF?

@bbarker That is really cool. Very interesting to see how the parsing libs copy all this. It's funny how programmers usually learn things in reverse; where one learns the tool and then the theory rather than the theory then the tool.