Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a basic formal definition of the source language #69

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

zerbina
Copy link
Collaborator

@zerbina zerbina commented Nov 12, 2024

Summary

Add the first version of a formal definition for the source language, covering the tree grammar and the static semantics. The definition is expressed using a macro DSL.

Details

The source language specification only provides an informal definition of the language, making it inaccessible to programs and formal reasoning.

Having a formal definition of the source language would allow for formal reasoning about programs, which in turn allows for proving that some program has a certain meaning and/or behaviour.

A macro DSL (language) is used for expressing the language definition. This:

  • allows re-using NimSkull's syntax, removing the need to write a dedicated lexer/parser
  • makes it easy to experiment with / modify the meta-language's syntax
  • makes it easy to generated code based on the language definition (by using the macro API)

The macro parses and validates the meta language and translates it into an internal data structure. Planned - but not yet implemented - usages of this data are:

  • generating a human-readable definition using mathematical notation common to formal language definitions
  • generating syntax checking logic (replacing the passtool functionality)
  • generating code for computing the semantics of source language code

At the moment, the language macro is still missing a way to define operational semantics (i.e., a formal definition of how a program written in the source language is evaluated).

The idea is to keep the formal definition and specification side-by-side until everything in the specification can be expressed with the language macro, at which point the specification would be removed.


To-Do

  • complete the validation logic
  • document the meta language
  • integrate compiling def.nim into koch and CI

Note For Reviewers

  • questions / suggestions regarding the meta language are welcome
  • the meta language is not meant to be final
  • a major inspiration for the definition was the formal definition of Standard ML

The implementation of the used macro DSL is still missing.
It only performs basic parsing and validation.
@zerbina zerbina added documentation Improvements or additions to documentation enhancement New feature or request labels Nov 12, 2024
@zerbina
Copy link
Collaborator Author

zerbina commented Nov 12, 2024

It's important to note that due to the - not yet implemented - compile-time evaluation and meta programming facilities, a strict separation between static semantics (i.e., types, symbols, etc.) and dynamic semantics (i.e., how a program behaves at run-time) is not going to be possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant