author | Stepan777 <stepik-777@mail.ru> |
Mon, 11 Jun 2012 17:56:10 +0400 | |
changeset 7231 | f484455dd055 |
parent 7070 | 8d4189609e90 |
child 7317 | 3534a264b27a |
permissions | -rw-r--r-- |
6467 | 1 |
module PascalUnitSyntaxTree where |
2 |
||
6618 | 3 |
import Data.Maybe |
6626
a447993f2ad7
Further work on propagating types. Now it hopefully works fully, just need to annotate namespace with types first.
unc0rr
parents:
6618
diff
changeset
|
4 |
import Data.Char |
6467 | 5 |
|
6 |
data PascalUnit = |
|
7 |
Program Identifier Implementation Phrase |
|
8 |
| Unit Identifier Interface Implementation (Maybe Initialize) (Maybe Finalize) |
|
6512 | 9 |
| System [TypeVarDeclaration] |
6467 | 10 |
deriving Show |
11 |
data Interface = Interface Uses TypesAndVars |
|
12 |
deriving Show |
|
13 |
data Implementation = Implementation Uses TypesAndVars |
|
14 |
deriving Show |
|
6489 | 15 |
data Identifier = Identifier String BaseType |
6467 | 16 |
deriving Show |
17 |
data TypesAndVars = TypesAndVars [TypeVarDeclaration] |
|
18 |
deriving Show |
|
19 |
data TypeVarDeclaration = TypeDeclaration Identifier TypeDecl |
|
20 |
| VarDeclaration Bool ([Identifier], TypeDecl) (Maybe InitExpression) |
|
21 |
| FunctionDeclaration Identifier TypeDecl [TypeVarDeclaration] (Maybe (TypesAndVars, Phrase)) |
|
22 |
| OperatorDeclaration String Identifier TypeDecl [TypeVarDeclaration] (Maybe (TypesAndVars, Phrase)) |
|
23 |
deriving Show |
|
24 |
data TypeDecl = SimpleType Identifier |
|
25 |
| RangeType Range |
|
26 |
| Sequence [Identifier] |
|
27 |
| ArrayDecl (Maybe Range) TypeDecl |
|
28 |
| RecordType [TypeVarDeclaration] (Maybe [[TypeVarDeclaration]]) |
|
29 |
| PointerTo TypeDecl |
|
30 |
| String Integer |
|
31 |
| Set TypeDecl |
|
32 |
| FunctionType TypeDecl [TypeVarDeclaration] |
|
6626
a447993f2ad7
Further work on propagating types. Now it hopefully works fully, just need to annotate namespace with types first.
unc0rr
parents:
6618
diff
changeset
|
33 |
| DeriveType InitExpression |
6826 | 34 |
| VoidType |
6467 | 35 |
deriving Show |
36 |
data Range = Range Identifier |
|
37 |
| RangeFromTo InitExpression InitExpression |
|
6893 | 38 |
| RangeInfinite |
6467 | 39 |
deriving Show |
40 |
data Initialize = Initialize String |
|
41 |
deriving Show |
|
42 |
data Finalize = Finalize String |
|
43 |
deriving Show |
|
44 |
data Uses = Uses [Identifier] |
|
45 |
deriving Show |
|
46 |
data Phrase = ProcCall Reference [Expression] |
|
47 |
| IfThenElse Expression Phrase (Maybe Phrase) |
|
48 |
| WhileCycle Expression Phrase |
|
49 |
| RepeatCycle Expression [Phrase] |
|
50 |
| ForCycle Identifier Expression Expression Phrase |
|
51 |
| WithBlock Reference Phrase |
|
52 |
| Phrases [Phrase] |
|
53 |
| SwitchCase Expression [([InitExpression], Phrase)] (Maybe [Phrase]) |
|
54 |
| Assignment Reference Expression |
|
6895 | 55 |
| BuiltInFunctionCall [Expression] Reference |
6467 | 56 |
| NOP |
57 |
deriving Show |
|
58 |
data Expression = Expression String |
|
59 |
| BuiltInFunCall [Expression] Reference |
|
60 |
| PrefixOp String Expression |
|
61 |
| PostfixOp String Expression |
|
62 |
| BinOp String Expression Expression |
|
63 |
| StringLiteral String |
|
7070 | 64 |
| PCharLiteral String |
6467 | 65 |
| CharCode String |
66 |
| HexCharCode String |
|
67 |
| NumberLiteral String |
|
68 |
| FloatLiteral String |
|
69 |
| HexNumber String |
|
70 |
| Reference Reference |
|
71 |
| SetExpression [Identifier] |
|
72 |
| Null |
|
73 |
deriving Show |
|
74 |
data Reference = ArrayElement [Expression] Reference |
|
75 |
| FunCall [Expression] Reference |
|
76 |
| TypeCast Identifier Expression |
|
77 |
| SimpleReference Identifier |
|
78 |
| Dereference Reference |
|
79 |
| RecordField Reference Reference |
|
80 |
| Address Reference |
|
81 |
| RefExpression Expression |
|
82 |
deriving Show |
|
83 |
data InitExpression = InitBinOp String InitExpression InitExpression |
|
84 |
| InitPrefixOp String InitExpression |
|
85 |
| InitReference Identifier |
|
86 |
| InitArray [InitExpression] |
|
87 |
| InitRecord [(Identifier, InitExpression)] |
|
88 |
| InitFloat String |
|
89 |
| InitNumber String |
|
90 |
| InitHexNumber String |
|
91 |
| InitString String |
|
92 |
| InitChar String |
|
93 |
| BuiltInFunction String [InitExpression] |
|
94 |
| InitSet [InitExpression] |
|
95 |
| InitAddress InitExpression |
|
96 |
| InitNull |
|
97 |
| InitRange Range |
|
98 |
| InitTypeCast Identifier InitExpression |
|
99 |
deriving Show |
|
6489 | 100 |
|
6618 | 101 |
data BaseType = BTUnknown |
6489 | 102 |
| BTChar |
103 |
| BTString |
|
104 |
| BTInt |
|
6635
c2fa29fe2a58
Some progress, still can't find the source of bad behavior
unc0rr
parents:
6626
diff
changeset
|
105 |
| BTBool |
6649
7f78e8a6db69
Fix a bug with type declaration trying to resolve type being declared
unc0rr
parents:
6635
diff
changeset
|
106 |
| BTFloat |
7042
de20086a6bcc
Support overloaded operators on (hwFloat op hwFloat) calls
unc0rr
parents:
7032
diff
changeset
|
107 |
| BTRecord String [(String, BaseType)] |
6893 | 108 |
| BTArray Range BaseType BaseType |
7019
333afe233886
Convert namespace from list into map in preparation for implementation of overloaded functions support. Greatly improve speed of rendering as a side effect (parse + render time reduced from 5:20 to 0:20)
unc0rr
parents:
6967
diff
changeset
|
109 |
| BTFunction Int BaseType |
6489 | 110 |
| BTPointerTo BaseType |
6827 | 111 |
| BTUnresolved String |
6653 | 112 |
| BTSet BaseType |
6489 | 113 |
| BTEnum [String] |
6618 | 114 |
| BTVoid |
6816 | 115 |
| BTUnit |
6489 | 116 |
deriving Show |