See:
See:
- Chucky Ellison, A Formal Semantics of C with Applications, PhD Thesis, http://fsl.cs.uiuc.edu/pubs/ellison-2012-thesis.pdf
- Chucky Ellison and Grigore Rosu, An Executable Formal Semantics of C with Applications, POPL'12, http://fsl.cs.uiuc.edu/pubs/ellison-rosu-2012-popl.pdf
This is a formal semantics of C as described in the ISO/IEC 9899:2011 standard ("C11"). Some highlights:
-
language/translation: semantics specific to the translation phase.
-
language/execution: semantics specific to the execution phase.
-
language/common: semantics shared between the translation and execution phases.
-
library: the definition of various functions from the C standard library described in the standard.
-
c11.k: the main syntax/semantics language modules for the execution phase.
-
c11-translation.k: the main syntax/semantics language modules for the translation phase.
-
language/common/syntax.k: the main C language syntax module.
Various stylistic conventions:
-
80 character lines.
-
vim: expandtab, tabstop=5, shiftwidth=5Because "rule
" and "when" are both 5 characters, indents of 5 spaces make things line up very prettily. -
I avoid plurals in module names, unless there might be confusion otherwise. E.g.,
C-EXPRESSION-FUNCTION-CALLinstead ofC-EXPRESSIONS-FUNCTION-CALLS. -
I think of syntax modules somewhat like C header files.
MYMODULE-SYNTAXshould contain the interface of a module (i.e., only "public" syntax productions -- cf. symbols with external linkage in C). Generally, when moduleAuses syntax productions that are defined by moduleB, moduleAshould importB-SYNTAX. If some part ofB's syntax isn't meant to be used in other modules, then it shouldn't be included inB-SYNTAX.Generally, semantic modules should only ever import
-SYNTAXmodules, except for the main language semantics module, which should only import non-SYNTAXmodules. And most-SYNTAXmodules should not import any other module, but if they do, then it should better be another-SYNTAXmodule. -
I try to avoid giant modules, especially giant
SYNTAXmodules. These seem analogous to putting everything in a global namespace and can make figuring out other modules' true dependencies difficult. -
contextrules should probably go in semantic modules and not syntactic modules because they often have awkward dependencies (e.g.,revalandpevalin the C semantics). -
My module names generally correspond somehow to file names, but with dashes for slashes. E.g., the module called
C-EXPRESSION-FUNCTION-CALLis at [language/expression/function-call.k][]. -
The word "semantics" in module names and elsewhere seems redundant.
-
I like to "declare" variables in rules at the point where they're bound (i.e., on the left side of the
=>). -
I prefer single quotes (e.g.,
func',func'', etc.) for "auxiliary" syntax productions. -
I prefix "#" to predicates that aren't total functions.