Siaras.jjt 11.8 KB
Newer Older
1
/* -*-Java-*- */
2
3
4
5
6
7
8

/* 
 * Copyright (C) 2006  Anders Nilsson <anders.nilsson@cs.lth.se>
 *
 * This file is part of OntologyCompiler.
 */

9
10
11
12
13
14
15
16
options {
    MULTI                       = true;
    VISITOR                     = true;
    NODE_DEFAULT_VOID           = true;
    NODE_SCOPE_HOOK             = false;
    NODE_PREFIX                 = "";
    JAVA_UNICODE_ESCAPE         = true;
    STATIC                      = false;
17
//   	DEBUG_PARSER                = true;
Anders Nilsson's avatar
Anders Nilsson committed
18
// 	DEBUG_LOOKAHEAD             = true;
19
//   	DEBUG_TOKEN_MANAGER         = true;
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
} // options


PARSER_BEGIN(SiarasParser)
package AST;
public class SiarasParser {
}
PARSER_END(SiarasParser)


//--------------------------------------------------------------------//
//                           LEXICAL TOKENS                           //
//--------------------------------------------------------------------//

<DEFAULT, BOUNDS> SKIP : /* WHITE SPACE */
{
    " "
    |
    "\t"
    |
    "\n"
    |
    "\r"
    |
    "\f"
}// WHITE SPACE



SPECIAL_TOKEN : /* COMMENTS */
{
< "<!--" ( ~["-"] | ( "-" ~["-"] ) )* "-->">
	| < "<rdfs:comment" ( ~["<"] | ( "<" ~["/"] ) )* "</rdfs:comment>" >
//     <XML_COMMENT  :  "<!--" (~["-","-",">"])* "-->"  >
}// COMMENTS



<DEFAULT, BOUNDS> TOKEN : /* RESERVED WORDS AND LITERALS */
{
//     < OWL_ALLVALUESFROM     : "owl:allValuesFrom" >
//   | < OWL_ALLDIFFERENT      : "owl:AllDifferent" >
//   | < OWL_CARDINALITY        : "owl:cardinality" >
//   | < OWL_CLASS             : "owl:Class" >
//   | < OWL_DATARANGE         : "owl:DataRange" >
//   | < OWL_DATATYPEPROPERTY  : "owl:DatatypeProperty" >
//   | < OWL_DISJOINTWITH      : "owl:disjointWith" >
//   | < OWL_EQUIVALENTCLASS   : "owl:equivalentClass" >
//   | < OWL_FUNCTIONALPROPERTY : "owl:FunctionalProperty" >
//   | < OWL_IMPORTS            : "owl:imports" >
//   | < OWL_INTERSECTIONOF     : "owl:intersectionOf" >
//   | < OWL_INVERSEOF         : "owl:inverseOf" >
//   | < OWL_MINCARDINALITY     : "owl:minCardinality" >
//   | < OWL_OBJECTPROPERTY    : "owl:ObjectProperty" >
//   | < OWL_ONPROPERTY        : "owl:onProperty" >
//   | < OWL_ONEOF             : "owl:oneOf" >
//   | < OWL_ONTOLOGY          : "owl:Ontology" >
//   | < OWL_RESTRICTION       : "owl:Restriction" >
//   | < OWL_SOMEVALUESFROM    : "owl:someValuesFrom" >
//   | < OWL_UNIONOF           : "owl:unionOf" >
//   | < RDF_RDF            : "rdf:RDF"      >
    < RDF_ABOUT          : "rdf:about" >
  | < RDF_DATATYPE          : "rdf:datatype" >
  | < RDF_ID                : "rdf:ID" >
//   | < RDF_FIRST             : "rdf:first" >
//   | < RDF_REST              : "rdf:rest" >
   | < RDF_PARSETYPE         : "rdf:parseType" >
  | < RDF_RESOURCE          : "rdf:resource" >
//   | < RDF_TYPE              : "rdf:type" >
  | < RDFS_COMMENT          : "rdfs:comment" >
//   | < RDFS_DOMAIN           : "rdfs:domain" >
//   | < RDFS_RANGE            : "rdfs:range" >
//   | < RDFS_SUBCLASSOF       : "rdfs:subClassOf" >
//   | < RDFS_SUBPROPERTYOF     : "rdfs:subPropertyOf" >
   | < VERSION               : "version" >
//   | < XML                   : "xml"          >
   | < XML_BASE              : "xml:base" >
   | < XMLNS                 : "xmlns" >	 
   | < XMLNS_DAML            : "xmlns:daml" >	 
   | < XMLNS_DC              : "xmlns:dc" >	 
   | < XMLNS_P1              : "xmlns:p1" >	 
   | < XMLNS_PROTEGE         : "xmlns:protege" >	 
   | < XMLNS_RDF             : "xmlns:rdf" >	 
   | < XMLNS_XSD             : "xmlns:xsd" >	 
   | < XMLNS_RDFS            : "xmlns:rdfs" >	 
   | < XMLNS_OWL             : "xmlns:owl" >	 

107
//      | < VacuumGripper             : "VacuumGripper" >	 
108

109
}// RESERVED WORDS AND LITERALS
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
<DEFAULT, BOUNDS> TOKEN : /* LITERALS */
{
    < INTEGER_LITERAL:
        <DECIMAL_LITERAL> (["l","L"])?
        |
        <HEX_LITERAL> (["l","L"])?
        |
        <OCTAL_LITERAL> (["l","L"])?
    >
    |
    < #DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* >
    |
    < #HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
    |
    < #OCTAL_LITERAL: "0" (["0"-"7"])* >
    |
    < FLOAT_LITERAL:
        (["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? (["f","F","d","D"])?
        |
        "." (["0"-"9"])+ (<EXPONENT>)? (["f","F","d","D"])?
        |
        (["0"-"9"])+ <EXPONENT> (["f","F","d","D"])?
        |
        (["0"-"9"])+ (<EXPONENT>)? ["f","F","d","D"]
    >
    |
    < #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
    |
    < CHARACTER_LITERAL:
        "'"
        (   (~["'","\\","\n","\r"])
            |
            ("\\"
                (   ["n","t","b","r","f","\\","'","\""]
                    |
                    ["0"-"7"] ( ["0"-"7"] )?
                    |
                    ["0"-"3"] ["0"-"7"] ["0"-"7"]
                )
            )
        )
        "'"
    >
    |
    < STRING_LITERAL:
        "\""
        (   (~["\"","\\","\n","\r"])
            |
            ("\\"
                (    ["n","t","b","r","f","\\","'","\""]
                     |
                     ["0"-"7"] ( ["0"-"7"] )?
                     |
                     ["0"-"3"] ["0"-"7"] ["0"-"7"]
                )
            )
        )*
        "\""
    >
}// LITERALS

<DEFAULT, BOUNDS> TOKEN : /* IDENTIFIERS */
{
174
    < IDENTIFIER: <LETTER> (<LETTER>|<DIGIT>|":")* >
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
    |
    < #LETTER:
        [
        "\u0024",
        "\u0041"-"\u005a",
        "\u005f",
        "\u0061"-"\u007a",
        "\u00c0"-"\u00d6",
        "\u00d8"-"\u00f6",
        "\u00f8"-"\u00ff",
        "\u0100"-"\u1fff",
        "\u3040"-"\u318f",
        "\u3300"-"\u337f",
        "\u3400"-"\u3d2d",
        "\u4e00"-"\u9fff",
190
191
192
        "\uf900"-"\ufaff",
		"+",
		"-",
193
194
		",",
		"."
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
        ]
    >
    |
    < #DIGIT:
        [
        "\u0030"-"\u0039",
        "\u0660"-"\u0669",
        "\u06f0"-"\u06f9",
        "\u0966"-"\u096f",
        "\u09e6"-"\u09ef",
        "\u0a66"-"\u0a6f",
        "\u0ae6"-"\u0aef",
        "\u0b66"-"\u0b6f",
        "\u0be7"-"\u0bef",
        "\u0c66"-"\u0c6f",
        "\u0ce6"-"\u0cef",
        "\u0d66"-"\u0d6f",
        "\u0e50"-"\u0e59",
        "\u0ed0"-"\u0ed9",
        "\u1040"-"\u1049"
        ]
    >
217
}//IDENTIFIERS
218
219
220
221
222
223
224
225
226
227

<DEFAULT,BOUNDS> TOKEN : /* SEPARATORS */
{
//       < LPAREN               : "("    >
//     | < RPAREN               : ")"    >
     < LBRACE               : "{"    >
    | < RBRACE               : "}"    >
    | < LBRACKET             : "["    >
    | < RBRACKET             : "]"    >
    | < SEMICOLON            : ";"    >
228
    | < QUOTE                : "\""    >
229
230
// 	| < COMMA                : ","    >
//     | < DOT                  : "."    >
231
232
233
234
235
236
}// SEPARATORS


<DEFAULT,BOUNDS> TOKEN : /* OPERATORS */
{
      < ASSIGN               : "="    >
237
238
239
240
     | < END_TAG             : ">"    >
     | < START_ENDTAG        : "</"    >
     | < START_TAG           : "<"    >
     | < END_TAGS            : "/>"   >
241
242
243
244
245
246
247
248
249
250
251
252
//     | < BANG                 : "!"    >
//     | < TILDE                : "~"    >
//     | < HOOK                 : "?"    >
//     | < COLON                : ":"    >
//     | < EQ                   : "=="   >
//     | < LE                   : "<="   >
//     | < GE                   : ">="   >
//     | < NE                   : "!="   >
//     | < SC_OR                : "||"   >
//     | < SC_AND               : "&&"   >
//     | < INCR                 : "++"   >
//     | < DECR                 : "--"   >
253
254
//      | < PLUS                 : "+"    >
//      | < MINUS                : "-"    >
255
//     | < STAR                 : "*"    >
256
      | < SLASH                : "/"    >
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
//     | < BIT_AND              : "&"    >
//     | < BIT_OR               : "|"    >
//     | < XOR                  : "^"    >
//     | < REM                  : "%"    >
//     | < LSHIFT               : "<<"   >
//     | < RSIGNEDSHIFT         : ">>"   >
//     | < RUNSIGNEDSHIFT       : ">>>"  >
//     | < PLUSASSIGN           : "+="   >
//     | < MINUSASSIGN          : "-="   >
//     | < STARASSIGN           : "*="   >
//     | < SLASHASSIGN          : "/="   >
//     | < ANDASSIGN            : "&="   >
//     | < ORASSIGN             : "|="   >
//     | < XORASSIGN            : "^="   >
//     | < REMASSIGN            : "%="   >
//     | < LSHIFTASSIGN         : "<<="  >
//     | < RSIGNEDSHIFTASSIGN   : ">>="  >
//     | < RUNSIGNEDSHIFTASSIGN : ">>>=" >
}// OPERATORS


Anders Nilsson's avatar
Anders Nilsson committed
278
279


280
281
282
283
284
285
286
287


//--------------------------------------------------------------------//
//                      THE OWL LANGUAGE GRAMMAR                     //
//--------------------------------------------------------------------//

Start Start() #Start : {}
{
288
 	("<?xml version=\"1.0\"?>")?
Anders Nilsson's avatar
Anders Nilsson committed
289
		ElementList()
290
291
292
293
294
  { return jjtThis; }
}

void ElementList() #List : {}
{
Anders Nilsson's avatar
Anders Nilsson committed
295
    (Element())*
296
297
298
299
300
301
302
}

void AttributeList() #List : {}
{
    (Attribute())*    
}

303
void ComplexElement() #ComplexElement  : {} 
304
{
305
306
	"<" Identifier() AttributeList()
	(">" ElementList() "</" <IDENTIFIER> ">" | ElementList() "/>")
307
}
308

309
310
311
312
313
void Identifier() #OwlIdentifier : {Token t;}
{
	t=<IDENTIFIER>
		{jjtThis.setIDENTIFIER(t.image);}
}
314

315
316
317
318
319
// void OtherToken() #OwlIdentifier : {Token t;}
// {
// 	t=<PLUS> | t=<MINUS> | t=<SLASH> | t=<COMMA> | t=<DOT>
// 		{jjtThis.setIDENTIFIER(t.image);}
// }
320
321
322



323
324
325
void Element() : {}
{
	ComplexElement()
326
 	| SimpleElement()
327
328
329
330
331
332
}

void SimpleElement() : {}
{
    IntElement()
	| FloatElement()
333
  	| StringElement()
334
335
336
337
338
}

void IntElement() #IntElement : { Token t; }
{
    t = <INTEGER_LITERAL>
339
	{jjtThis.setLITERAL(t.image);}
340
341
342
343
344
}

void FloatElement() #FloatElement : { Token t; }
{
    t = <FLOAT_LITERAL>
345
	{jjtThis.setLITERAL(t.image);}
346
347
}

348
void StringElement() #StringElement : { Token t;String s; }
349
{
350
	t = <IDENTIFIER>
351
352
353
354
355
356
357
	{
		s = t.image;
		if (getToken(1).kind != START_TAG ) {
		s += getData();
	}
	}
        {jjtThis.setLITERAL(s);}
358
359
}

360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
JAVACODE
String getData() {
	StringBuffer s = new StringBuffer();
//     jjtThis.someData = true;
    while ((getToken(1)).kind != START_TAG && (getToken(1)).kind != START_ENDTAG) {
		Token t = getNextToken();
		if (t.specialToken != null) {
			Token tmp_t = t.specialToken;
			while (tmp_t.specialToken != null) {
				tmp_t = tmp_t.specialToken;
			}
			while (tmp_t != null) {
				s.append(tmp_t.image);
				tmp_t = tmp_t.next;
			}
		}
		s.append(t.image);
	}
	return s.toString();
}


// void StringElement() #StringElement : {Token t;} 
// {
// 	t = <IDENTIFIER>
// 		{jjtThis.setIDENTIFIER(t.image);}
// // 	Identifier() | OtherToken()
// }

389
390
391
392


void Attribute() : {}
{
393
394
395
396
     Version()
 	| RdfAttribute()
  	| XmlAttribute()
 	| XmlnsAttribute()
397
398
399
400
401
402
403
404
405
}

void Version() #Version : {}
{
    <VERSION> <ASSIGN> Value()
}

void RdfAttribute() : {}
{
406
407
408
409
      RdfAbout()
  	| RdfDatatype()
 	| RdfId()
  	| RdfResource()
410
   	| RdfParseType()
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
}

void RdfAbout() #RdfAbout : {}
{
    <RDF_ABOUT> <ASSIGN> Value()
}

void RdfDatatype() #RdfDatatype : {}
{
    <RDF_DATATYPE> <ASSIGN> Value()
}

void RdfId() #RdfId : {}
{
    <RDF_ID> <ASSIGN> Value()
}

void RdfParseType() #RdfParseType : {}
{
    <RDF_PARSETYPE> <ASSIGN> Value()
}

void RdfResource() #RdfResource : {}
{
    <RDF_RESOURCE> <ASSIGN> Value()
}

void XmlAttribute() : {}
{
    XmlBase()
}

void XmlBase() #XmlBase : {}
{
    <XML_BASE> <ASSIGN> Value()
}

void XmlnsAttribute() : {}
{
    Xmlns()
	| XmlnsDaml()
	| XmlnsDc()
	| XmlnsOwl()
	| XmlnsP1()
	| XmlnsProtege()
	| XmlnsRdf()
	| XmlnsRdfs()
	| XmlnsXsd()
}

void Xmlns() #Xmlns : {}
{
    <XMLNS> <ASSIGN> Value()
}

void XmlnsDaml() #XmlnsDaml : {}
{
    <XMLNS_DAML> <ASSIGN> Value()
}

void XmlnsDc() #XmlnsDc : {}
{
    <XMLNS_DC> <ASSIGN> Value()
}

void XmlnsP1() #XmlnsP1 : {}
{
    <XMLNS_P1> <ASSIGN> Value()
}

void XmlnsProtege() #XmlnsProtege : {}
{
    <XMLNS_PROTEGE> <ASSIGN> Value()
}

void XmlnsRdf() #XmlnsRdf : {}
{
    <XMLNS_RDF> <ASSIGN> Value()
}

void XmlnsXsd() #XmlnsXsd : {}
{
    <XMLNS_XSD> <ASSIGN> Value()
}

void XmlnsRdfs() #XmlnsRdfs : {}
{
    <XMLNS_RDFS> <ASSIGN> Value()
}

void XmlnsOwl() #XmlnsOwl : {}
{
    <XMLNS_OWL> <ASSIGN> Value()
}

void Value() #Value : { Token t; }
{
    t = <STRING_LITERAL>
	{jjtThis.setSTRING_LITERAL(t.image);}
}