File: Mod3.atg

package info (click to toggle)
pm3 1.1.15-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 140,404 kB
  • ctags: 106,859
  • sloc: ansic: 891,434; modula3: 550,649; exp: 18,409; sh: 16,930; lisp: 13,693; makefile: 13,271; asm: 11,795; cpp: 5,560; yacc: 5,125; sed: 1,047; csh: 254; awk: 223; pascal: 95; fortran: 5
file content (155 lines) | stat: -rw-r--r-- 5,533 bytes parent folder | download | duplicates (2)
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
COMPILER Mod3

CHARACTERS
  letter  = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
          + "abcdefghijklmnopqrstuvwxyz" .
  octal   = "01234567" .
  digit   = "0123456789" .
  hex     = "0123456789abcdefABCDEF" .
  other   = " !#$%&()*+,-./:;<=>?@[]^_'{|}" + CHR(128) .. CHR(255) .
  exp     = "EeDdXx" .
  esc     = "ntrf\'" + '"' .
  print   = letter + digit + other .

TOKENS
  id      = letter {letter | digit | "_"} .
  number  = digit {digit} ["_" hex {hex} |
                           "." digit {digit} exp ["+"|"-"] digit {digit}] .
  charlit = "'" (print | "\" (esc | octal octal octal) | '"') "'" .
  textlit = '"' {print | "\" (esc | octal octal octal) | "'"} '"' .

COMMENTS FROM "(*" TO "*)" NESTED
COMMENTS FROM "<*" TO "*>" NESTED

PRODUCTIONS

(* Compilation unit productions *)

Mod3          = ["UNSAFE"] (Interface | Module) | Generic .

Interface     = "INTERFACE" id (";" {Import} {Decl} "END" id "." |
                               "=" id GenActls "END" id ".") .
Module        = "MODULE" id ["EXPORTS" IdList] (";" {Import} Block id "." |
                                                "=" id GenActls "END" id ".") .

Generic       = "GENERIC"
                ( "INTERFACE" id GenFmls ";" {Import} {Decl} "END" id "." |
                  "MODULE" id GenFmls ";" {Import} Block id "." ) .

Import        = AsImport | FromImport .
AsImport      = "IMPORT" ImportItem {"," ImportItem} ";" .
FromImport    = "FROM" id "IMPORT" IdList ";" .
Block         = {Decl} "BEGIN" S "END" .
Decl          = "CONST" {ConstDecl ";"}
              | "TYPE" {TypeDecl ";"}
              | "EXCEPTION" {ExceptionDecl ";"}
              | "VAR" {VariableDecl ";"}
              | ProcedureHead ["=" Block id] ";"
              | "REVEAL" {QualId ("=" | "<:") Type ";"} .

GenFmls       = "(" [IdList] ")" .
GenActls      = "(" [IdList] ")" .
ImportItem    = id ["AS" id] .
ConstDecl     = id [":" Type] "=" ConstExpr .
TypeDecl      = id ("=" | "<:") Type .
ExceptionDecl = id ["(" Type ")"] .
VariableDecl  = IdList [":" Type] [":=" Expr] .
ProcedureHead = "PROCEDURE" id Signature .

Signature     = "(" Formals ")" [":" Type] ["RAISES" Raises] .
Formals       = [Formal {";" Formal} [";"]] .
Formal        = [Mode] IdList [":" Type] [":=" ConstExpr] .
Mode          = "VALUE" | "VAR" | "READONLY" .
Raises        = "{" [QualId {"," QualId}] "}" | "ANY" .

(* Statement productions *)

S             = [Stmt {";" Stmt} [";"]] .
Stmt          = Block
              | Expr ( ":=" Expr | "(" [Actual {"," Actual}] ")" )
              | "CASE" Expr "OF" [Case] {"|" Case} ["ELSE" S] "END"
              | "EXIT"
              | "EVAL" Expr
              | "FOR" id ":=" Expr "TO" Expr ["BY" Expr] "DO" S "END"
              | "IF" Expr "THEN" S ["ELSIF" Expr "THEN" S] ["ELSE" S] "END"
              | "LOCK" Expr "DO" S "END"
              | "LOOP" S "END"
              | "RAISE" QualId ["(" Expr ")"]
              | "REPEAT" S "UNTIL" Expr
              | "RETURN" [Expr]
              | "TYPECASE" Expr "OF" [TCase] {"|" TCase} ["ELSE" S] "END"
              | "TRY" S "EXCEPT" [Handler] {"|" Handler} ["ELSE" S] "END"
              | "TRY" S "FINALLY" S "END"
              | "WHILE" Expr "DO" S "END"
              | "WITH" Binding {"," Binding} "DO" S "END" .

Case          = Labels {"," Labels} "=>" S .
Labels        = ConstExpr [".." ConstExpr] .
Handler       = QualId {"," QualId} ["(" id ")"] "=>" S .
TCase         = Type {"," Type} ["(" id ")"] "=>" S .
Binding       = id "=" Expr .
Actual        = Type | [id ":="] Expr .

(* Type productions *)

Type          = TypeName
              | "ARRAY" [Type {"," Type}] "OF" Type
              | "BITS" ConstExpr "FOR" Type
              | "{" [IdList] "}"
              | [TypeName] [Brand] "OBJECT" Fields ["METHODS" Methods]
                                                   ["OVERRIDES" Overrides] "END"
              | "PROCEDURE" Signature
              | "RECORD" Fields "END"
              | ["UNTRACED"] [Brand] "REF" Type
              | "SET" "OF" Type
              | "[" ConstExpr ".." ConstExpr "]"
              | "(" Type ")" .

Brand         = "BRANDED" [textlit] .
Fields        = [ Field {";" Field} [";"] ] .
Field         = IdList [":" Type] [":=" ConstExpr] .
Methods       = [ Method {";" Method} [";"] ] .
Method        = id Signature [":=" ConstExpr] .
Overrides     = [ Override {";" Override} [";"] ] .
Override      = id ":=" ConstExpr .

(* Expression productions *)

ConstExpr     = Expr .
Expr          = E1 {"OR" E1} .
E1            = E2 {"AND" E2} .
E2            = {"NOT"} E3 .
E3            = E4 {RelOp E4} .
E4            = E5 {AddOp E5} .
E5            = E6 {MulOp E6} .
E6            = {"+" | "-"} E7 .
E7            = E8 {Selector} .
E8            = id | number | charlit | textlit
                (* | Constructor *) | "(" Expr ")" .

RelOp         = "=" | "#" | "<" | "<=" | ">" | ">=" | "IN" .
AddOp         = "+" | "-" | "&" .
MulOp         = "*" | "/" | "DIV" | "MOD" .

Selector      = "^" | "." id | "[" Expr {"," Expr} "]"
                    | "(" [Actual {"," Actual}] ")" .

(*** needs to be fixed

Constructor   = Type "{" [SetCons | RecordCons | ArrayCons] "}" .

SetCons       = SetElt {"," SetElt} .
SetElt        = Expr [".." Expr] .
RecordCons    = RecordElt {"," RecordElt} .
RecordElt     = Expr [":=" Expr] .
ArrayCons     = Expr {"," (Expr | "..")} .

***)

(* Miscellaneous productions *)

IdList        = id {"," id} .
QualId        = id ["." id] .
TypeName      = QualId | "ROOT" | "UNTRACED" "ROOT" .

END Mod3.