Skip to content

Commit 7154c36

Browse files
authored
Merge pull request #24 from dstolfa/master
Initial work on D grammar
2 parents ff4e164 + 85f2ceb commit 7154c36

File tree

2 files changed

+160
-4
lines changed

2 files changed

+160
-4
lines changed

specification/chap-opendtrace-dlang.tex

+159-4
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,167 @@
55
OpenDTrace, as well as elaborate on its properties in multithreaded
66
environments.
77

8-
\section{Grammar definition}
8+
\section{Language grammar}
99
\label{sec:grammar}
1010

11-
\input{dt_grammar.tex}
11+
\setlength{\grammarparsep}{5pt plus 1pt minus 1pt} % increase separation between rules
12+
\setlength{\grammarindent}{12em} % increase separation between LHS/RHS
1213

13-
\ebnftable
14+
%\input{dt_grammar.tex}
15+
16+
%\ebnftable
17+
18+
%TODO: Define all the auxiliary things we may need, such as integers, ...
19+
20+
In this section, we will define the grammar of the D language and explain how
21+
each part fits together when interacting with DTrace. Terminals are represented
22+
using lower\_case, while non-terminals are written as CamelCase. Furthermore, we
23+
define the tab character, `\textbackslash t' and space, ` ' as separators. We first
24+
define a number of auxiliary constructs to define the rest of the grammar.
25+
26+
\begin{grammar}
27+
<letter> ::= `A' ... `Z'
28+
\alt `a' ... `z'
29+
\alt `\_' ;
30+
31+
<Word> ::= <letter> \{ <letter> \} ;
32+
\end{grammar}
33+
34+
\noindent
35+
In D, `\_' is considered a letter, which can be used at either the start of a
36+
name. As in C, separators can either be tabs or whitespace characters.
37+
Additionally, we define number constants that are supported in D:
38+
39+
\begin{grammar}
40+
<dec\_digit> ::= `1' | `2' | `3' | `4' | `5' | `6' | `7' | `8' | `9' ;
41+
42+
<DecDigitWithZero> ::= `0' | <dec\_digit> ;
43+
44+
<bin\_digit> ::= `0' | `1' ;
45+
46+
<oct\_digit> ::= `0' | `1' | `2' | `3' | `4' | `5' | `6' | `7' ;
47+
48+
<HexDigit> ::= <DecDigitWithZero>
49+
\alt `A' ... `F'
50+
\alt `a' ... `f' ;
51+
52+
<Integer> ::= <dec\_digit> <DecDigitWithZero>
53+
\alt `0b' <bin\_digit>
54+
\alt `0' <oct\_digit>
55+
\alt `0x' <HexDigit>
56+
\end{grammar}
57+
58+
% XXX: Is this sufficient for a <Identifier>
59+
\begin{grammar}
60+
<Identifier> ::= <Word> \{ ( <DecDigitWithZero> | <Word> ) \} ;
61+
62+
<VarList> ::= <Identifier> \{ `,' <Identifier> \} ;
63+
\end{grammar}
64+
65+
\noindent
66+
In D, there are many ways to access types. However, there are a number of
67+
builtin types, as well as mechanisms to define these types. Similarly to C, D
68+
supports a number of primitive integer types and floating point types, as well
69+
as a specialized \texttt{string} and \texttt{userland} type.
70+
71+
\begin{grammar}
72+
<Type> ::= `char'
73+
\alt `short'
74+
\alt `int'
75+
\alt `signed'
76+
\alt `unsigned'
77+
\alt `long'
78+
\alt `long long'
79+
\alt `userland'
80+
\alt `string'
81+
\alt `void'
82+
\alt `float'
83+
\alt `double'
84+
\alt <TypedefName>
85+
\alt <StructOrUnionSpec>
86+
\alt <EnumSpecifier> ;
87+
\end{grammar}
88+
89+
\noindent
90+
In the above type specification, we introduce three new non-terminals that we
91+
further have to specify: \texttt{TypedefName}, \texttt{StructOrUnionSpec} and
92+
\texttt{EnumSpecifier}. \texttt{TypedefName} represents a type that is defined
93+
to be an alias to another type, much like in C:
94+
95+
\begin{grammar}
96+
<TypedefName> ::= <Identifier> ;
97+
\end{grammar}
98+
99+
\noindent
100+
Similarly, \texttt{StructOrUnionSpec} represents a way to specify a D
101+
\texttt{struct} or \texttt{union} type. These language primitives are compatible
102+
with their C counterparts and ensure ABI compatibility. This is important when
103+
tracing the kernel, but also allows trivial translation to other ABIs. We
104+
specify \texttt{StructOrUnionSpec} as follows:
105+
106+
\begin{grammar}
107+
<StructOrUnionSpec> ::= <Modifier> ( `struct' | `union' ) [ <Identifier> ] \newline
108+
`{' <StructDeclList> `}' [ <VarList> ] `;'
109+
\alt ( `struct' | `union' ) <Identifier> [ <VarList> ] `;' ;
110+
111+
<StructDeclList> ::= <Type> <VarList> `;' \{ <Type> <VarList> `;' \} ;
112+
113+
<EnumSpecifier> ::= <Modifier> `enum' [ <Identifier> ] \newline
114+
`{' <EnumDeclList> `}' [ <VarList> ] `;'
115+
\alt `enum' <Identifier> [ <VarList> ] `;' ;
116+
117+
<EnumDeclList> ::= <Identifier> [ `=' <Identifier> ] [ `,' ] ;
118+
\end{grammar}
119+
120+
\noindent
121+
Here we introduce a new non-terminal, \texttt{Modifier} which encapsulates the
122+
modifiers that may occur before a \texttt{struct} or \texttt{enum} definition.
123+
It is defined as follows:
124+
125+
% XXX: Verify that this is correct
126+
\begin{grammar}
127+
<Modifier> ::= `const'
128+
\alt `volatile'
129+
\alt `typedef'
130+
\alt `register'
131+
\alt `restrict'
132+
\alt `static'
133+
\alt `extern' ;
134+
\end{grammar}
135+
136+
\noindent
137+
Eventhough \texttt{Modifier} is permissive in terms of what keywords are
138+
allowed, the definitions of these keywords are equivalent to those in C and may
139+
only be used when appropriate. The compiler may choose to emit a warning and
140+
ignore modifiers that are not applicable or it may choose to be more strict and
141+
treat misuse of a modifier as an error. Using these modifiers when not
142+
applicable is considered undefined behaviour. \newline
143+
144+
\noindent
145+
Since D is a domain-specific language for tracing and provides probes in the
146+
kenrel, we define the following way of specifying probes:
147+
148+
% TODO: Make this render a bit nicer.
149+
% XXX: Is this correct?
150+
\begin{grammar}
151+
<ProbeSpecifier> ::= <Identifier>
152+
\alt [ <Identifier> ] `:' [ <Identifier> ]
153+
\alt [ <Identifier> ] `:' [ <Identifier> ] `:' [ <Identifier> ]
154+
\alt [ <Identifier> ] `:' [ <Identifier> ] `:'
155+
[ <Identifier> ] `:' [ <Identifier> ]
156+
\end{grammar}
157+
158+
\noindent
159+
This provides us with a way to specify the \texttt{provider}, \texttt{module},
160+
\texttt{function} and \texttt{name} of a DTrace probe in D.
161+
162+
% TODO: Define <Predicate> and <Statements>
163+
\begin{grammar}
164+
<ProbeDefinition> ::= <ProbeSpecifier> [ <Predicate> ] `{' { <Statement> } `}'
165+
\end{grammar}
166+
167+
% TODO: Define all different types of expressions that we can have, assignment
168+
% operators, conditionals, ...
14169

15170
\section{Safety}
16171
\label{sec:safety}
@@ -233,4 +388,4 @@ \section{Aggregations}
233388
\section{Subroutines}
234389
\label{sec:subroutines}
235390

236-
% XXX explain how subroutines are different from actions.
391+
% XXX explain how subroutines are different from actions.

specification/preamble.tex

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
\usepackage{setspace}
3131
\usepackage{amsmath}
3232
\usepackage{longtable}
33+
\usepackage[nounderscore]{syntax}
3334
% Must be included later than setspace, otherwise all footnote hyperlinks
3435
% point to the title page.
3536
\usepackage{hyperref}

0 commit comments

Comments
 (0)