What's new? | Help | Directory | Sign in
Google
heron-language
Heron is an object-oriented programming language for model driven architecture
  
  
  
  
    
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
/*
Authour: Christopher Diggins
License: MIT Licence 1.0

YARD Grammar for the JAction language
*/

#ifndef JACTION_GRAMMAR_HPP
#define JACTION_GRAMMAR_HPP

namespace jaction_grammar
{
using namespace yard;
using namespace text_grammar;

struct Expr;
struct TypeExpr;
struct SimpleExpr;
struct Statement;
struct StatementList;
struct CodeBlock;

struct SymChar :
CharSetParser<CharSet<'~','!','@','#','$','%','^','&','*','-','+','|','\\','<','>','/','?',',', '='> > { };

struct NewLine :
Or<CharSeq<'\r', '\n'>, CharSeq<'\n'> > { };

struct LineComment :
Seq<CharSeq<'/', '/'>, UntilPast<NewLine> > { };

struct FullComment :
Seq<CharSeq<'/', '*'>, UntilPast<CharSeq<'*', '/'> > > { };

struct Comment :
Or<LineComment, FullComment> { };

struct WS :
Star<Or<Char<' '>, Char<'\t'>, NewLine, Comment, Char<'\r'>, Char<'\v'>, Char<'\f'> > > { };

template<typename R>
struct Tok :
Seq<R, WS> { };

template<typename T>
struct Keyword :
Tok<Seq<T, NotAlphaNum > > { };

template<char C>
struct CharTok :
Seq<Char<C>, WS> { };

struct Sym :
Tok<Or<Store<Ident>, Store<Plus<SymChar> > > > { };

struct DotSym :
Seq<Char<'.'>, Sym> { };

template<typename R, typename D>
struct DelimitedList :
Or<Seq<R, Plus<Seq<D, R> > >, Opt<R> >
{ };

template<typename First, typename T, typename Last>
struct StoreList :
Seq<
First,
Or<
Last,
Seq<
Store<T>,
Star<
Seq<
CharTok<','>,
Store<T>
>
>,
Last
>
>
>
{ };


template<typename R>
struct CommaList :
DelimitedList<R, CharTok<','> > { };

template<typename R>
struct Braced :
Seq<CharTok<'{'>, R, CharTok<'}'> > { };

template<typename R>
struct BracedList :
Seq<CharTok<'{'>, Star<R>, CharTok<'}'> > { };

template<typename R>
struct StoreBracedList :
Seq<CharTok<'{'>, Star<Store<R> >, CharTok<'}'> > { };

template<typename R>
struct BracedCommaList :
Braced<CommaList<R> > { };

template<typename R>
struct Paranthesized :
Seq<CharTok<'('>, R, CharTok<')'> > { };

template<typename R>
struct ParanthesizedCommaList :
Paranthesized<CommaList<R> > { };

struct StringCharLiteral :
Or<Seq<Char<'\\'>, NotChar<'\n'> >, AnyCharExcept<CharSet<'\n', '\"', '\'' > > > { };

struct CharLiteral :
Seq<Char<'\''>, StringCharLiteral, Char<'\''> > { };

struct StringLiteral :
Seq<Char<'\"'>, Star<StringCharLiteral>, Char<'\"'> > { };

struct BinaryDigit :
Or<Char<'0'>, Char<'1'> > { };

struct BinNumber :
Seq<CharSeq<'0', 'b'>, Plus<BinaryDigit> > { };

struct HexNumber :
Seq<CharSeq<'0', 'x'>, Plus<HexDigit> > { };

struct DecNumber :
Seq<Opt<Char<'-'> >, Plus<Digit>, Opt<Seq<Char<'.'>, Star<Digit> > > > { };

struct NEW : Keyword<CharSeq<'n','e','w'> > { };
struct DELETE : Keyword<CharSeq<'d','e','l','e','t','e'> > { };
struct VAR : Keyword<CharSeq<'v','a','r'> > { };
struct ELSE : Keyword<CharSeq<'e','l','s','e'> > { };
struct IF : Keyword<CharSeq<'i','f'> > { };
struct FOREACH : Keyword<CharSeq<'f','o','r','e','a','c','h'> > { };
struct WHILE : Keyword<CharSeq<'w','h','i','l','e'> > { };
struct IN : Keyword<CharSeq<'i','n'> > { };
struct CASE : Keyword<CharSeq<'c','a','s','e'> > { };
struct SWITCH : Keyword<CharSeq<'s','w','i','t','c','h'> > { };
struct RETURN : Keyword<CharSeq<'r','e','t','u','r','n'> > { };
struct DEFAULT : Keyword<CharSeq<'d','e','f','a','u','l','t'> > { };

struct Literal :
Tok<Store<Or<BinNumber, HexNumber, DecNumber, CharLiteral, StringLiteral > > > { };

struct ParamList :
StoreList<CharTok<'('>, Expr, CharTok<')'> > { };

struct TypeArgs :
StoreList<CharTok<'<'>, TypeExpr, CharTok<'>'> > { };

struct TypeExpr :
Seq<Store<Sym>, Opt<Store<TypeArgs> > > { };

struct TypeDecl :
NoFailSeq<CharTok<':'>, Store<TypeExpr> > { };

struct Arg :
Seq<Store<Sym>, Opt<TypeDecl> > { };

struct ArgList :
StoreList<CharTok<'('>, Arg, CharTok<')'> >
{ };

struct AnonFxn :
Seq<Store<ArgList>, Char<'='>, Char<'>'>, Opt<WS>, Store<CodeBlock> > { };

struct NewExpr :
NoFailSeq<NEW, Store<TypeExpr>, Store<ParamList> > { };

struct DelExpr :
NoFailSeq<DELETE, Store<Expr> > { };

struct ParanthesizedExpr :
NoFailSeq<CharTok<'('>, Opt<Expr>, CharTok<')'> > { };

struct SimpleExpr :
Or<Store<NewExpr>,
Store<DelExpr>,
Store<Sym>,
Store<DotSym>,
Store<Literal>,
Store<AnonFxn>,
Store<ParanthesizedExpr>
> { };

struct Expr :
Plus<SimpleExpr> { };

struct Initializer :
Seq<CharTok<'='>, Store<Expr> > { };

struct CodeBlock :
NoFailSeq<CharTok<'{'>, StatementList, Finao<CharTok<'}'> > > { };

struct Eos :
CharTok<';'> { };

struct VarDecl :
NoFailSeq<VAR, Store<Sym>, Opt<TypeDecl>, Opt<Initializer>, Eos > { };

struct ElseStatement :
NoFailSeq<ELSE, Statement> { };

struct IfStatement :
NoFailSeq<IF, Paranthesized<Store<Expr> >, Statement, Opt<ElseStatement> > { };

struct ForEachStatement :
NoFailSeq<FOREACH, CharTok<'('>, Store<Sym>, Opt<TypeDecl>,
IN, Store<Expr>, CharTok<')'>, Store<CodeBlock> > { };

struct ExprStatement :
Seq<Store<Expr>, Eos> { };

struct ReturnStatement :
NoFailSeq<RETURN, Store<Expr>, Eos> { };

struct CaseStatement :
NoFailSeq<CASE, Paranthesized<Store<Expr> >, Store<CodeBlock> > { };

struct DefaultStatement :
NoFailSeq<DEFAULT, Store<CodeBlock> > { };

struct SwitchStatement :
NoFailSeq<SWITCH, Paranthesized<Store<Expr> >, CharTok<'{'>, Star<Store<CaseStatement> >,
Opt<Store<DefaultStatement> >, CharTok<'}'> > { };

struct WhileStatement :
NoFailSeq<WHILE, Paranthesized<Store<Expr> >, Store<CodeBlock> > { };

struct AssignmentStatement :
Seq<Store<SimpleExpr>, NoFailSeq<Initializer, Eos> > { };

struct EmptyStatement :
Eos { };

struct Statement :
Or<Store<CodeBlock>,
Store<VarDecl>,
Store<IfStatement>,
Store<SwitchStatement>,
Store<ForEachStatement>,
Store<WhileStatement>,
Store<ReturnStatement>,
Store<AssignmentStatement>,
Store<ExprStatement>,
Store<EmptyStatement>
> { };

struct StatementList :
Star<Statement> { };

}

#endif
Show details Hide details

Change log

r46 by cdiggins on Apr 08, 2008   Diff

 
Go to: 
Project members, sign in to write a code review

Older revisions

r45 by cdiggins on Mar 26, 2008   Diff
Some minor changes to the input file.
r44 by cdiggins on Mar 26, 2008   Diff
Improved parsing. Java code generation
still not great.
r43 by cdiggins on Mar 25, 2008   Diff
Improved C++ compliance of YARD
library. Started using unit tests
again. Made a bunch of improvements.
All revisions of this file

File info

Size: 6431 bytes, 259 lines