author | unc0rr |
Mon, 26 Mar 2012 17:56:15 +0400 | |
changeset 6826 | 8fadeefdd352 |
parent 6816 | 572571ea945e |
child 6827 | a0e152e68337 |
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 |
| UnknownType |
36 |
deriving Show |
|
37 |
data Range = Range Identifier |
|
38 |
| RangeFromTo InitExpression InitExpression |
|
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 |
|
55 |
| NOP |
|
56 |
deriving Show |
|
57 |
data Expression = Expression String |
|
58 |
| BuiltInFunCall [Expression] Reference |
|
59 |
| PrefixOp String Expression |
|
60 |
| PostfixOp String Expression |
|
61 |
| BinOp String Expression Expression |
|
62 |
| StringLiteral String |
|
63 |
| CharCode String |
|
64 |
| HexCharCode String |
|
65 |
| NumberLiteral String |
|
66 |
| FloatLiteral String |
|
67 |
| HexNumber String |
|
68 |
| Reference Reference |
|
69 |
| SetExpression [Identifier] |
|
70 |
| Null |
|
71 |
deriving Show |
|
72 |
data Reference = ArrayElement [Expression] Reference |
|
73 |
| FunCall [Expression] Reference |
|
74 |
| TypeCast Identifier Expression |
|
75 |
| SimpleReference Identifier |
|
76 |
| Dereference Reference |
|
77 |
| RecordField Reference Reference |
|
78 |
| Address Reference |
|
79 |
| RefExpression Expression |
|
80 |
deriving Show |
|
81 |
data InitExpression = InitBinOp String InitExpression InitExpression |
|
82 |
| InitPrefixOp String InitExpression |
|
83 |
| InitReference Identifier |
|
84 |
| InitArray [InitExpression] |
|
85 |
| InitRecord [(Identifier, InitExpression)] |
|
86 |
| InitFloat String |
|
87 |
| InitNumber String |
|
88 |
| InitHexNumber String |
|
89 |
| InitString String |
|
90 |
| InitChar String |
|
91 |
| BuiltInFunction String [InitExpression] |
|
92 |
| InitSet [InitExpression] |
|
93 |
| InitAddress InitExpression |
|
94 |
| InitNull |
|
95 |
| InitRange Range |
|
96 |
| InitTypeCast Identifier InitExpression |
|
97 |
deriving Show |
|
6489 | 98 |
|
6618 | 99 |
data BaseType = BTUnknown |
6489 | 100 |
| BTChar |
101 |
| BTString |
|
102 |
| BTInt |
|
6635
c2fa29fe2a58
Some progress, still can't find the source of bad behavior
unc0rr
parents:
6626
diff
changeset
|
103 |
| BTBool |
6649
7f78e8a6db69
Fix a bug with type declaration trying to resolve type being declared
unc0rr
parents:
6635
diff
changeset
|
104 |
| BTFloat |
6826 | 105 |
| BTRecord |
6618 | 106 |
| BTArray BaseType BaseType |
6826 | 107 |
| BTFunction BaseType |
6489 | 108 |
| BTPointerTo BaseType |
6653 | 109 |
| BTSet BaseType |
6489 | 110 |
| BTEnum [String] |
6618 | 111 |
| BTVoid |
6816 | 112 |
| BTUnit |
6489 | 113 |
deriving Show |