source: trunk/src/syn/Magnolia/Core/Expressions.sdf@ 425

Last change on this file since 425 was 425, checked in by Anya Helene Bagge, 14 years ago

Allow dots in names

File size: 2.4 KB
Line 
1%% Expressions.sdf is part of Magnolia
2%%
3%% Copyright (C) 2008,2009 Anya Helene Bagge
4%% Copyright (C) 2008,2009 University of Bergen
5%%
6%% Contact: <magnolia@magnolia-lang.org>
7%%
8%% This program is free software: you can redistribute it and/or modify
9%% it under the terms of the GNU General Public License as published by
10%% the Free Software Foundation, either version 3 of the License, or
11%% (at your option) any later version.
12%%
13%% This program is distributed in the hope that it will be useful,
14%% but WITHOUT ANY WARRANTY; without even the implied warranty of
15%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16%% GNU General Public License for more details.
17%%
18%% You should have received a copy of the GNU General Public License
19%% along with this program. If not, see <http://www.gnu.org/licenses/>.
20
21%% This modules defines the syntax of expression. An expression is one of
22%%
23%% - a literal
24%% - a variable
25%% - an operator applied to expressions
26%% - a function applied to expressions
27%% - a type (possibly with expression arguments)
28%% - a control-flow expression
29
30module Magnolia/Core/Expressions
31
32exports
33 sorts
34 Expr
35 InitSpec
36 Fun
37 Var
38 FunName
39 %% Externals
40 Type
41 Identifier
42 Literal
43 Stat
44
45 context-free syntax
46
47%%% Variables
48
49 "_" -> Expr {cons("Undefined")}
50
51%%% Variables
52
53 Name ":" Type -> Var {cons("Var"), selectable}
54
55 Var -> Expr
56
57%%% Literals
58
59 Literal -> Expr {cons("Literal"), selectable}
60
61%%% Tuple
62
63 "(" {Expr ","}* ")" -> Expr {cons("Tuple"), selectable}
64
65%%% Type Expressions
66
67 ":" Type -> Expr {cons("TypeExpr"), selectable}
68
69%%% Value Construction
70
71 Type "$" "{" {InitSpec ","}* "}" -> Expr {cons("Struct"), selectable}
72
73 Identifier ":=" Expr -> InitSpec {cons("Field")}
74
75%%% Function Application
76
77 Fun "(" {Expr ","}* ")" -> Expr {cons("Apply"), selectable}
78
79 FunName -> Fun {cons("Fun")}
80
81 Name -> FunName
82
83%%% Control-flow expressions
84
85 "if" Expr "then" Expr "else" Expr "end" -> Expr {cons("IfThenElseExpr"), selectable}
86 "{" Stat* "}" -> Expr {cons("BlockExpr"), selectable}
87
88%%% List Expressions
89
90 "[" {Expr ","}* "]" -> Expr {cons("ListCons")}
91
92 "[" {Expr ","}* "|" Expr "]" -> Expr {cons("ListCons")}
93
94
95
96
97
98lexical restrictions
99
100 "if" -/- [A-Za-z\_\$0-9]
101 "then" -/- [A-Za-z\_\$0-9]
102 "else" -/- [A-Za-z\_\$0-9]
103 "end" -/- [A-Za-z\_\$0-9]
104 "_" -/- [A-Za-z\_\$0-9]
Note: See TracBrowser for help on using the repository browser.