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=5
Because "rule
-
I avoid plurals in module names, unless there might be confusion otherwise. E.g.,
C-EXPRESSION-FUNCTION-CALL
instead ofC-EXPRESSIONS-FUNCTION-CALLS
. -
I think of syntax modules somewhat like C header files.
MYMODULE-SYNTAX
should contain the interface of a module (i.e., only "public" syntax productions -- cf. symbols with external linkage in C). Generally, when moduleA
uses syntax productions that are defined by moduleB
, moduleA
should 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
-SYNTAX
modules, except for the main language semantics module, which should only import non-SYNTAX
modules. And most-SYNTAX
modules should not import any other module, but if they do, then it should better be another-SYNTAX
module. -
I try to avoid giant modules, especially giant
SYNTAX
modules. These seem analogous to putting everything in a global namespace and can make figuring out other modules' true dependencies difficult. -
context
rules should probably go in semantic modules and not syntactic modules because they often have awkward dependencies (e.g.,reval
andpeval
in 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-CALL
is 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.