-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrammarmini.cf
65 lines (50 loc) · 1.65 KB
/
grammarmini.cf
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
-- mycpp
--
-- Sont déclarés dans la syntaxe :
-- + namespace,
-- + class,
-- + héritage;
-- + field (attributs/méthodes),
-- ###
comment "//";
comment "/*" "*/";
entrypoints Program;
ProgramDef. Program ::= [Namespace];
-- Namespace definition
separator Namespace "";
NamespaceDec. Namespace ::= "namespace" Ident "{" [Class] "}";
-- Class definition
separator Class "";
ClassDec. Class ::= ClassHeader "{" [Field] "}";
-- Class header definition
ClassHeaderDec. ClassHeader ::= "class" Ident;
ClassHeaderDecI. ClassHeader ::= "class" Ident "inherits" ClassName;
-- Class name definition
ClassNameDec. ClassName ::= Ident;
-- Fields definition
separator Field "";
FieldDecAtt. Field ::= "attribute" Ident ";";
FieldDecMeth. Field ::= "method" Ident "{" [Stm] Return "}";
FieldDecMethPar. Field ::= "method" Ident "(" [Param] ")" "{" [Stm] Return "}";
-- Statements definition
separator Stm "";
Statement. Stm ::= Exp ";" ;
-- Expressions
separator nonempty Ident ":";
Eassign. Exp ::= Exp4 "=" Exp;
EAdd. Exp ::= Exp "+" Exp1 ;
ESub. Exp ::= Exp "-" Exp1 ;
EMul. Exp1 ::= Exp1 "*" Exp2 ;
EDiv. Exp1 ::= Exp1 "/" Exp2 ;
EMod. Exp1 ::= Exp1 "%" Exp2 ;
EInt. Exp2 ::= Integer ;
ENewAlloc. Exp3 ::= NewInst ;
EVar. Exp4 ::= [Ident] ;
coercions Exp 4 ;
-- Class instanciation definition
ANewInstance. NewInst ::= "new" Ident;
-- Return definition
ReturnExp. Return ::= "return" Exp ";";
-- Parameters definition
separator Param ",";
ParamDec. Param ::= "var" Ident;