author | unc0rr |
Sat, 15 Jun 2013 23:45:53 +0400 | |
branch | webgl |
changeset 9166 | 3774ac58e65e |
parent 8444 | 75db7bb8dce8 |
child 9954 | bf51bc7e2808 |
permissions | -rw-r--r-- |
4353
671d66ba3af6
Dumb parser of pascal, and a program which lists unit dependencies
unC0Rr
parents:
diff
changeset
|
1 |
module PascalParser where |
671d66ba3af6
Dumb parser of pascal, and a program which lists unit dependencies
unC0Rr
parents:
diff
changeset
|
2 |
|
6412 | 3 |
import Text.Parsec |
6272 | 4 |
import Text.Parsec.Char |
5 |
import Text.Parsec.Token |
|
6 |
import Text.Parsec.Language |
|
6412 | 7 |
import Text.Parsec.Expr |
6272 | 8 |
import Text.Parsec.Prim |
9 |
import Text.Parsec.Combinator |
|
10 |
import Text.Parsec.String |
|
4353
671d66ba3af6
Dumb parser of pascal, and a program which lists unit dependencies
unC0Rr
parents:
diff
changeset
|
11 |
import Control.Monad |
6399 | 12 |
import Data.Maybe |
7067
f98ec3aecf4e
A solution to char vs string problem: mark single-letter strings with _S macro
unc0rr
parents:
7066
diff
changeset
|
13 |
import Data.Char |
4353
671d66ba3af6
Dumb parser of pascal, and a program which lists unit dependencies
unC0Rr
parents:
diff
changeset
|
14 |
|
6412 | 15 |
import PascalBasics |
6467 | 16 |
import PascalUnitSyntaxTree |
7315 | 17 |
|
6891
ab9843957664
Improve rendering of function types, ranges, and more
unc0rr
parents:
6875
diff
changeset
|
18 |
knownTypes = ["shortstring", "ansistring", "char", "byte"] |
6357 | 19 |
|
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
20 |
pascalUnit = do |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
21 |
comments |
7429
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
22 |
u <- choice [program, unit, systemUnit, redoUnit] |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
23 |
comments |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
24 |
return u |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
25 |
|
6275 | 26 |
iD = do |
9166 | 27 |
i <- identifier pas |
6275 | 28 |
comments |
9166 | 29 |
when (i == "not") $ unexpected "'not' used as an identifier" |
30 |
return $ Identifier i BTUnknown |
|
7315 | 31 |
|
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
32 |
unit = do |
6275 | 33 |
string "unit" >> comments |
34 |
name <- iD |
|
35 |
semi pas |
|
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
36 |
comments |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
37 |
int <- interface |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
38 |
impl <- implementation |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
39 |
comments |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
40 |
return $ Unit name int impl Nothing Nothing |
6275 | 41 |
|
7315 | 42 |
|
6275 | 43 |
reference = buildExpressionParser table term <?> "reference" |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
44 |
where |
6275 | 45 |
term = comments >> choice [ |
6453
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6452
diff
changeset
|
46 |
parens pas (liftM RefExpression expression >>= postfixes) >>= postfixes |
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6452
diff
changeset
|
47 |
, try $ typeCast >>= postfixes |
6450 | 48 |
, char '@' >> liftM Address reference >>= postfixes |
8442 | 49 |
, liftM SimpleReference iD >>= postfixes |
6275 | 50 |
] <?> "simple reference" |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
51 |
|
7315 | 52 |
table = [ |
6275 | 53 |
] |
7315 | 54 |
|
6425
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
55 |
postfixes r = many postfix >>= return . foldl (flip ($)) r |
6386
7d7703b26bda
Prefix followed by prefix issue solved. Also some slight improvements.
unc0rr
parents:
6357
diff
changeset
|
56 |
postfix = choice [ |
7d7703b26bda
Prefix followed by prefix issue solved. Also some slight improvements.
unc0rr
parents:
6357
diff
changeset
|
57 |
parens pas (option [] parameters) >>= return . FunCall |
7d7703b26bda
Prefix followed by prefix issue solved. Also some slight improvements.
unc0rr
parents:
6357
diff
changeset
|
58 |
, char '^' >> return Dereference |
7d7703b26bda
Prefix followed by prefix issue solved. Also some slight improvements.
unc0rr
parents:
6357
diff
changeset
|
59 |
, (brackets pas) (commaSep1 pas $ expression) >>= return . ArrayElement |
6467 | 60 |
, (char '.' >> notFollowedBy (char '.')) >> liftM (flip RecordField) reference |
6386
7d7703b26bda
Prefix followed by prefix issue solved. Also some slight improvements.
unc0rr
parents:
6357
diff
changeset
|
61 |
] |
6316 | 62 |
|
6450 | 63 |
typeCast = do |
64 |
t <- choice $ map (\s -> try $ caseInsensitiveString s >>= \i -> notFollowedBy alphaNum >> return i) knownTypes |
|
6453
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6452
diff
changeset
|
65 |
e <- parens pas expression |
6450 | 66 |
comments |
6618 | 67 |
return $ TypeCast (Identifier t BTUnknown) e |
7315 | 68 |
|
69 |
varsDecl1 = varsParser sepEndBy1 |
|
6290 | 70 |
varsDecl = varsParser sepEndBy |
6277 | 71 |
varsParser m endsWithSemi = do |
6290 | 72 |
vs <- m (aVarDecl endsWithSemi) (semi pas) |
73 |
return vs |
|
74 |
||
75 |
aVarDecl endsWithSemi = do |
|
7317 | 76 |
isVar <- liftM (== Just "var") $ |
77 |
if not endsWithSemi then |
|
78 |
optionMaybe $ choice [ |
|
79 |
try $ string "var" |
|
80 |
, try $ string "const" |
|
81 |
, try $ string "out" |
|
82 |
] |
|
83 |
else |
|
84 |
return Nothing |
|
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
85 |
comments |
6290 | 86 |
ids <- do |
87 |
i <- (commaSep1 pas) $ (try iD <?> "variable declaration") |
|
88 |
char ':' |
|
89 |
return i |
|
90 |
comments |
|
91 |
t <- typeDecl <?> "variable type declaration" |
|
92 |
comments |
|
93 |
init <- option Nothing $ do |
|
94 |
char '=' |
|
6275 | 95 |
comments |
6355 | 96 |
e <- initExpression |
4353
671d66ba3af6
Dumb parser of pascal, and a program which lists unit dependencies
unC0Rr
parents:
diff
changeset
|
97 |
comments |
6290 | 98 |
return (Just e) |
7317 | 99 |
return $ VarDeclaration isVar False (ids, t) init |
6275 | 100 |
|
101 |
||
102 |
constsDecl = do |
|
6317
83b93a2d2741
Improve parsing of complex references like "a^[b[c], d]"
unc0rr
parents:
6316
diff
changeset
|
103 |
vs <- many1 (try (aConstDecl >>= \i -> semi pas >> return i) >>= \i -> comments >> return i) |
6275 | 104 |
comments |
6277 | 105 |
return vs |
6275 | 106 |
where |
107 |
aConstDecl = do |
|
108 |
comments |
|
6443
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
109 |
i <- iD |
6444 | 110 |
t <- optionMaybe $ do |
6275 | 111 |
char ':' |
112 |
comments |
|
113 |
t <- typeDecl |
|
6425
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
114 |
comments |
6444 | 115 |
return t |
6275 | 116 |
char '=' |
117 |
comments |
|
6355 | 118 |
e <- initExpression |
6275 | 119 |
comments |
7317 | 120 |
return $ VarDeclaration False (isNothing t) ([i], fromMaybe (DeriveType e) t) (Just e) |
7315 | 121 |
|
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
122 |
typeDecl = choice [ |
6290 | 123 |
char '^' >> typeDecl >>= return . PointerTo |
6399 | 124 |
, try (string "shortstring") >> return (String 255) |
125 |
, try (string "string") >> optionMaybe (brackets pas $ integer pas) >>= return . String . fromMaybe 255 |
|
6891
ab9843957664
Improve rendering of function types, ranges, and more
unc0rr
parents:
6875
diff
changeset
|
126 |
, try (string "ansistring") >> optionMaybe (brackets pas $ integer pas) >>= return . String . fromMaybe 255 |
6290 | 127 |
, arrayDecl |
6277 | 128 |
, recordDecl |
6425
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
129 |
, setDecl |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
130 |
, functionType |
6355 | 131 |
, sequenceDecl >>= return . Sequence |
6489 | 132 |
, try iD >>= return . SimpleType |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
133 |
, rangeDecl >>= return . RangeType |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
134 |
] <?> "type declaration" |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
135 |
where |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
136 |
arrayDecl = do |
6425
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
137 |
try $ do |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
138 |
optional $ (try $ string "packed") >> comments |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
139 |
string "array" |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
140 |
comments |
6426 | 141 |
r <- option [] $ do |
6425
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
142 |
char '[' |
6426 | 143 |
r <- commaSep pas rangeDecl |
6425
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
144 |
char ']' |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
145 |
comments |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
146 |
return r |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
147 |
string "of" |
4353
671d66ba3af6
Dumb parser of pascal, and a program which lists unit dependencies
unC0Rr
parents:
diff
changeset
|
148 |
comments |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
149 |
t <- typeDecl |
6426 | 150 |
if null r then |
151 |
return $ ArrayDecl Nothing t |
|
152 |
else |
|
8442 | 153 |
return $ foldr (\a b -> ArrayDecl (Just a) b) (ArrayDecl (Just $ head r) t) (tail r) |
6277 | 154 |
recordDecl = do |
6425
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
155 |
try $ do |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
156 |
optional $ (try $ string "packed") >> comments |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
157 |
string "record" |
6277 | 158 |
comments |
159 |
vs <- varsDecl True |
|
6425
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
160 |
union <- optionMaybe $ do |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
161 |
string "case" |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
162 |
comments |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
163 |
iD |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
164 |
comments |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
165 |
string "of" |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
166 |
comments |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
167 |
many unionCase |
6277 | 168 |
string "end" |
6425
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
169 |
return $ RecordType vs union |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
170 |
setDecl = do |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
171 |
try $ string "set" >> space |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
172 |
comments |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
173 |
string "of" |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
174 |
comments |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
175 |
liftM Set typeDecl |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
176 |
unionCase = do |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
177 |
try $ commaSep pas $ (iD >> return ()) <|> (integer pas >> return ()) |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
178 |
char ':' |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
179 |
comments |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
180 |
u <- parens pas $ varsDecl True |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
181 |
char ';' |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
182 |
comments |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
183 |
return u |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
184 |
sequenceDecl = (parens pas) $ (commaSep pas) (iD >>= \i -> optional (spaces >> char '=' >> spaces >> integer pas) >> return i) |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
185 |
functionType = do |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
186 |
fp <- try (string "function") <|> try (string "procedure") |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
187 |
comments |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
188 |
vs <- option [] $ parens pas $ varsDecl False |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
189 |
comments |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
190 |
ret <- if (fp == "function") then do |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
191 |
char ':' |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
192 |
comments |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
193 |
ret <- typeDecl |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
194 |
comments |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
195 |
return ret |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
196 |
else |
6826 | 197 |
return VoidType |
6425
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
198 |
optional $ try $ char ';' >> comments >> string "cdecl" |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
199 |
comments |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
200 |
return $ FunctionType ret vs |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
201 |
|
6277 | 202 |
typesDecl = many (aTypeDecl >>= \t -> comments >> return t) |
203 |
where |
|
204 |
aTypeDecl = do |
|
205 |
i <- try $ do |
|
206 |
i <- iD <?> "type declaration" |
|
207 |
comments |
|
208 |
char '=' |
|
209 |
return i |
|
210 |
comments |
|
211 |
t <- typeDecl |
|
212 |
comments |
|
213 |
semi pas |
|
214 |
comments |
|
215 |
return $ TypeDeclaration i t |
|
6453
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6452
diff
changeset
|
216 |
|
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
217 |
rangeDecl = choice [ |
6277 | 218 |
try $ rangeft |
219 |
, iD >>= return . Range |
|
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
220 |
] <?> "range declaration" |
6277 | 221 |
where |
222 |
rangeft = do |
|
6388 | 223 |
e1 <- initExpression |
6277 | 224 |
string ".." |
6388 | 225 |
e2 <- initExpression |
7315 | 226 |
return $ RangeFromTo e1 e2 |
227 |
||
6277 | 228 |
typeVarDeclaration isImpl = (liftM concat . many . choice) [ |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
229 |
varSection, |
6275 | 230 |
constSection, |
6277 | 231 |
typeSection, |
6443
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
232 |
funcDecl, |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
233 |
operatorDecl |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
234 |
] |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
235 |
where |
8020 | 236 |
|
237 |
fixInit v = concat $ map (\x -> case x of |
|
238 |
VarDeclaration a b (ids, t) c -> |
|
239 |
let typeId = (Identifier ((\(Identifier i _) -> i) (head ids) ++ "_tt") BTUnknown) in |
|
240 |
let res = [TypeDeclaration typeId t, VarDeclaration a b (ids, (SimpleType typeId)) c] in |
|
241 |
case t of |
|
242 |
RecordType _ _ -> res -- create a separated type declaration |
|
243 |
ArrayDecl _ _ -> res |
|
244 |
_ -> [x] |
|
245 |
_ -> error ("checkInit:\n" ++ (show v))) v |
|
246 |
||
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
247 |
varSection = do |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
248 |
try $ string "var" |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
249 |
comments |
6443
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
250 |
v <- varsDecl1 True <?> "variable declaration" |
6272 | 251 |
comments |
8020 | 252 |
return $ fixInit v |
6275 | 253 |
|
254 |
constSection = do |
|
255 |
try $ string "const" |
|
256 |
comments |
|
6443
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
257 |
c <- constsDecl <?> "const declaration" |
6275 | 258 |
comments |
8020 | 259 |
return $ fixInit c |
6277 | 260 |
|
261 |
typeSection = do |
|
262 |
try $ string "type" |
|
263 |
comments |
|
6443
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
264 |
t <- typesDecl <?> "type declaration" |
6277 | 265 |
comments |
266 |
return t |
|
7315 | 267 |
|
6443
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
268 |
operatorDecl = do |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
269 |
try $ string "operator" |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
270 |
comments |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
271 |
i <- manyTill anyChar space |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
272 |
comments |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
273 |
vs <- parens pas $ varsDecl False |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
274 |
comments |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
275 |
rid <- iD |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
276 |
comments |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
277 |
char ':' |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
278 |
comments |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
279 |
ret <- typeDecl |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
280 |
comments |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
281 |
return ret |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
282 |
char ';' |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
283 |
comments |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
284 |
forward <- liftM isJust $ optionMaybe (try (string "forward;") >> comments) |
7513 | 285 |
inline <- liftM (any (== "inline;")) $ many functionDecorator |
6443
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
286 |
b <- if isImpl && (not forward) then |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
287 |
liftM Just functionBody |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
288 |
else |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
289 |
return Nothing |
7513 | 290 |
return $ [OperatorDeclaration i rid inline ret vs b] |
6443
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
291 |
|
7315 | 292 |
|
6425
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
293 |
funcDecl = do |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
294 |
fp <- try (string "function") <|> try (string "procedure") |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
295 |
comments |
6275 | 296 |
i <- iD |
6425
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
297 |
vs <- option [] $ parens pas $ varsDecl False |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
298 |
comments |
6425
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
299 |
ret <- if (fp == "function") then do |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
300 |
char ':' |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
301 |
comments |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
302 |
ret <- typeDecl |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
303 |
comments |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
304 |
return ret |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
305 |
else |
6836 | 306 |
return VoidType |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
307 |
char ';' |
6399 | 308 |
comments |
6425
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
309 |
forward <- liftM isJust $ optionMaybe (try (string "forward;") >> comments) |
8020 | 310 |
decorators <- many functionDecorator |
311 |
let inline = any (== "inline;") decorators |
|
312 |
overload = any (== "overload;") decorators |
|
6417
eae5900fd8a4
Improve parser a bit, preparation to parsing whole program at once and compiling it into single C file
unc0rr
parents:
6414
diff
changeset
|
313 |
b <- if isImpl && (not forward) then |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
314 |
liftM Just functionBody |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
315 |
else |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
316 |
return Nothing |
8020 | 317 |
return $ [FunctionDeclaration i inline overload ret vs b] |
7315 | 318 |
|
7513 | 319 |
functionDecorator = do |
320 |
d <- choice [ |
|
321 |
try $ string "inline;" |
|
322 |
, try $ caseInsensitiveString "cdecl;" |
|
323 |
, try $ string "overload;" |
|
324 |
, try $ string "export;" |
|
325 |
, try $ string "varargs;" |
|
326 |
, try (string "external") >> comments >> iD >> optional (string "name" >> comments >> stringLiteral pas)>> string ";" |
|
327 |
] |
|
328 |
comments |
|
329 |
return d |
|
7315 | 330 |
|
331 |
||
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
332 |
program = do |
6275 | 333 |
string "program" |
334 |
comments |
|
335 |
name <- iD |
|
336 |
(char ';') |
|
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
337 |
comments |
6417
eae5900fd8a4
Improve parser a bit, preparation to parsing whole program at once and compiling it into single C file
unc0rr
parents:
6414
diff
changeset
|
338 |
comments |
eae5900fd8a4
Improve parser a bit, preparation to parsing whole program at once and compiling it into single C file
unc0rr
parents:
6414
diff
changeset
|
339 |
u <- uses |
eae5900fd8a4
Improve parser a bit, preparation to parsing whole program at once and compiling it into single C file
unc0rr
parents:
6414
diff
changeset
|
340 |
comments |
eae5900fd8a4
Improve parser a bit, preparation to parsing whole program at once and compiling it into single C file
unc0rr
parents:
6414
diff
changeset
|
341 |
tv <- typeVarDeclaration True |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
342 |
comments |
6417
eae5900fd8a4
Improve parser a bit, preparation to parsing whole program at once and compiling it into single C file
unc0rr
parents:
6414
diff
changeset
|
343 |
p <- phrase |
eae5900fd8a4
Improve parser a bit, preparation to parsing whole program at once and compiling it into single C file
unc0rr
parents:
6414
diff
changeset
|
344 |
comments |
eae5900fd8a4
Improve parser a bit, preparation to parsing whole program at once and compiling it into single C file
unc0rr
parents:
6414
diff
changeset
|
345 |
char '.' |
eae5900fd8a4
Improve parser a bit, preparation to parsing whole program at once and compiling it into single C file
unc0rr
parents:
6414
diff
changeset
|
346 |
comments |
eae5900fd8a4
Improve parser a bit, preparation to parsing whole program at once and compiling it into single C file
unc0rr
parents:
6414
diff
changeset
|
347 |
return $ Program name (Implementation u (TypesAndVars tv)) p |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
348 |
|
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
349 |
interface = do |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
350 |
string "interface" |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
351 |
comments |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
352 |
u <- uses |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
353 |
comments |
6277 | 354 |
tv <- typeVarDeclaration False |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
355 |
comments |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
356 |
return $ Interface u (TypesAndVars tv) |
4353
671d66ba3af6
Dumb parser of pascal, and a program which lists unit dependencies
unC0Rr
parents:
diff
changeset
|
357 |
|
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
358 |
implementation = do |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
359 |
string "implementation" |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
360 |
comments |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
361 |
u <- uses |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
362 |
comments |
6277 | 363 |
tv <- typeVarDeclaration True |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
364 |
string "end." |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
365 |
comments |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
366 |
return $ Implementation u (TypesAndVars tv) |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
367 |
|
7429
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
368 |
expression = do |
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
369 |
buildExpressionParser table term <?> "expression" |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
370 |
where |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
371 |
term = comments >> choice [ |
6618 | 372 |
builtInFunction expression >>= \(n, e) -> return $ BuiltInFunCall e (SimpleReference (Identifier n BTUnknown)) |
6453
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6452
diff
changeset
|
373 |
, try (parens pas $ expression >>= \e -> notFollowedBy (comments >> char '.') >> return e) |
6450 | 374 |
, brackets pas (commaSep pas iD) >>= return . SetExpression |
7429
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
375 |
, try $ integer pas >>= \i -> notFollowedBy (char '.') >> (return . NumberLiteral . show) i |
6452 | 376 |
, float pas >>= return . FloatLiteral . show |
7429
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
377 |
, try $ integer pas >>= return . NumberLiteral . show |
7067
f98ec3aecf4e
A solution to char vs string problem: mark single-letter strings with _S macro
unc0rr
parents:
7066
diff
changeset
|
378 |
, try (string "_S" >> stringLiteral pas) >>= return . StringLiteral |
7070 | 379 |
, try (string "_P" >> stringLiteral pas) >>= return . PCharLiteral |
7067
f98ec3aecf4e
A solution to char vs string problem: mark single-letter strings with _S macro
unc0rr
parents:
7066
diff
changeset
|
380 |
, stringLiteral pas >>= return . strOrChar |
6444 | 381 |
, try (string "#$") >> many hexDigit >>= \c -> comments >> return (HexCharCode c) |
6417
eae5900fd8a4
Improve parser a bit, preparation to parsing whole program at once and compiling it into single C file
unc0rr
parents:
6414
diff
changeset
|
382 |
, char '#' >> many digit >>= \c -> comments >> return (CharCode c) |
eae5900fd8a4
Improve parser a bit, preparation to parsing whole program at once and compiling it into single C file
unc0rr
parents:
6414
diff
changeset
|
383 |
, char '$' >> many hexDigit >>= \h -> comments >> return (HexNumber h) |
7429
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
384 |
--, char '-' >> expression >>= return . PrefixOp "-" |
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
385 |
, char '-' >> reference >>= return . PrefixOp "-" . Reference |
7762 | 386 |
, (try $ string "not" >> notFollowedBy comments) >> unexpected "'not'" |
6290 | 387 |
, try $ string "nil" >> return Null |
6275 | 388 |
, reference >>= return . Reference |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
389 |
] <?> "simple expression" |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
390 |
|
7429
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
391 |
table = [ |
8020 | 392 |
[ Prefix (reservedOp pas "not">> return (PrefixOp "not")) |
7429
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
393 |
, Prefix (try (char '-') >> return (PrefixOp "-"))] |
8020 | 394 |
, |
6290 | 395 |
[ Infix (char '*' >> return (BinOp "*")) AssocLeft |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
396 |
, Infix (char '/' >> return (BinOp "/")) AssocLeft |
6275 | 397 |
, Infix (try (string "div") >> return (BinOp "div")) AssocLeft |
398 |
, Infix (try (string "mod") >> return (BinOp "mod")) AssocLeft |
|
6450 | 399 |
, Infix (try (string "in") >> return (BinOp "in")) AssocNone |
7429
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
400 |
, Infix (try $ string "and" >> return (BinOp "and")) AssocLeft |
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
401 |
, Infix (try $ string "shl" >> return (BinOp "shl")) AssocLeft |
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
402 |
, Infix (try $ string "shr" >> return (BinOp "shr")) AssocLeft |
6275 | 403 |
] |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
404 |
, [ Infix (char '+' >> return (BinOp "+")) AssocLeft |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
405 |
, Infix (char '-' >> return (BinOp "-")) AssocLeft |
7429
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
406 |
, Infix (try $ string "or" >> return (BinOp "or")) AssocLeft |
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
407 |
, Infix (try $ string "xor" >> return (BinOp "xor")) AssocLeft |
6275 | 408 |
] |
409 |
, [ Infix (try (string "<>") >> return (BinOp "<>")) AssocNone |
|
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
410 |
, Infix (try (string "<=") >> return (BinOp "<=")) AssocNone |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
411 |
, Infix (try (string ">=") >> return (BinOp ">=")) AssocNone |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
412 |
, Infix (char '<' >> return (BinOp "<")) AssocNone |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
413 |
, Infix (char '>' >> return (BinOp ">")) AssocNone |
6275 | 414 |
] |
7429
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
415 |
{-, [ Infix (try $ string "shl" >> return (BinOp "shl")) AssocNone |
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
416 |
, Infix (try $ string "shr" >> return (BinOp "shr")) AssocNone |
7043
7c080e5ac8d0
Some work to make more units compile after conversion to c
unc0rr
parents:
6897
diff
changeset
|
417 |
] |
8442 | 418 |
, [ |
7429
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
419 |
Infix (try $ string "or" >> return (BinOp "or")) AssocLeft |
6275 | 420 |
, Infix (try $ string "xor" >> return (BinOp "xor")) AssocLeft |
7429
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
421 |
]-} |
7069 | 422 |
, [ |
423 |
Infix (char '=' >> return (BinOp "=")) AssocNone |
|
424 |
] |
|
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
425 |
] |
7067
f98ec3aecf4e
A solution to char vs string problem: mark single-letter strings with _S macro
unc0rr
parents:
7066
diff
changeset
|
426 |
strOrChar [a] = CharCode . show . ord $ a |
7315 | 427 |
strOrChar a = StringLiteral a |
428 |
||
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
429 |
phrasesBlock = do |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
430 |
try $ string "begin" |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
431 |
comments |
6444 | 432 |
p <- manyTill phrase (try $ string "end" >> notFollowedBy alphaNum) |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
433 |
comments |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
434 |
return $ Phrases p |
7315 | 435 |
|
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
436 |
phrase = do |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
437 |
o <- choice [ |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
438 |
phrasesBlock |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
439 |
, ifBlock |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
440 |
, whileCycle |
6275 | 441 |
, repeatCycle |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
442 |
, switchCase |
6275 | 443 |
, withBlock |
444 |
, forCycle |
|
7429
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
445 |
, (try $ reference >>= \r -> string ":=" >> return r) >>= \r -> comments >> expression >>= return . Assignment r |
6895 | 446 |
, builtInFunction expression >>= \(n, e) -> return $ BuiltInFunctionCall e (SimpleReference (Identifier n BTUnknown)) |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
447 |
, procCall |
6453
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6452
diff
changeset
|
448 |
, char ';' >> comments >> return NOP |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
449 |
] |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
450 |
optional $ char ';' |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
451 |
comments |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
452 |
return o |
4353
671d66ba3af6
Dumb parser of pascal, and a program which lists unit dependencies
unC0Rr
parents:
diff
changeset
|
453 |
|
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
454 |
ifBlock = do |
7642
91fce82f9c6f
fix parsing of 'if': identifiers can also contain underscores
sheepluva
parents:
7641
diff
changeset
|
455 |
try $ string "if" >> notFollowedBy (alphaNum <|> char '_') |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
456 |
comments |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
457 |
e <- expression |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
458 |
comments |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
459 |
string "then" |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
460 |
comments |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
461 |
o1 <- phrase |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
462 |
comments |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
463 |
o2 <- optionMaybe $ do |
6425
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
464 |
try $ string "else" >> space |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
465 |
comments |
6450 | 466 |
o <- option NOP phrase |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
467 |
comments |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
468 |
return o |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
469 |
return $ IfThenElse e o1 o2 |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
470 |
|
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
471 |
whileCycle = do |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
472 |
try $ string "while" |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
473 |
comments |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
474 |
e <- expression |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
475 |
comments |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
476 |
string "do" |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
477 |
comments |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
478 |
o <- phrase |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
479 |
return $ WhileCycle e o |
4353
671d66ba3af6
Dumb parser of pascal, and a program which lists unit dependencies
unC0Rr
parents:
diff
changeset
|
480 |
|
6275 | 481 |
withBlock = do |
6425
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
482 |
try $ string "with" >> space |
6275 | 483 |
comments |
6387 | 484 |
rs <- (commaSep1 pas) reference |
6275 | 485 |
comments |
486 |
string "do" |
|
487 |
comments |
|
488 |
o <- phrase |
|
6387 | 489 |
return $ foldr WithBlock o rs |
7315 | 490 |
|
6275 | 491 |
repeatCycle = do |
6425
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
492 |
try $ string "repeat" >> space |
6275 | 493 |
comments |
494 |
o <- many phrase |
|
495 |
string "until" |
|
496 |
comments |
|
497 |
e <- expression |
|
498 |
comments |
|
499 |
return $ RepeatCycle e o |
|
500 |
||
501 |
forCycle = do |
|
6425
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
502 |
try $ string "for" >> space |
6275 | 503 |
comments |
504 |
i <- iD |
|
505 |
comments |
|
506 |
string ":=" |
|
507 |
comments |
|
508 |
e1 <- expression |
|
509 |
comments |
|
7429
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
510 |
up <- liftM (== Just "to") $ |
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
511 |
optionMaybe $ choice [ |
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
512 |
try $ string "to" |
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
513 |
, try $ string "downto" |
8442 | 514 |
] |
7429
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
515 |
--choice [string "to", string "downto"] |
6275 | 516 |
comments |
517 |
e2 <- expression |
|
518 |
comments |
|
519 |
string "do" |
|
520 |
comments |
|
521 |
p <- phrase |
|
522 |
comments |
|
7429
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
523 |
return $ ForCycle i e1 e2 p up |
7315 | 524 |
|
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
525 |
switchCase = do |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
526 |
try $ string "case" |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
527 |
comments |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
528 |
e <- expression |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
529 |
comments |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
530 |
string "of" |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
531 |
comments |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
532 |
cs <- many1 aCase |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
533 |
o2 <- optionMaybe $ do |
6450 | 534 |
try $ string "else" >> notFollowedBy alphaNum |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
535 |
comments |
6453
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6452
diff
changeset
|
536 |
o <- many phrase |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
537 |
comments |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
538 |
return o |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
539 |
string "end" |
6399 | 540 |
comments |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
541 |
return $ SwitchCase e cs o2 |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
542 |
where |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
543 |
aCase = do |
6453
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6452
diff
changeset
|
544 |
e <- (commaSep pas) $ (liftM InitRange rangeDecl <|> initExpression) |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
545 |
comments |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
546 |
char ':' |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
547 |
comments |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
548 |
p <- phrase |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
549 |
comments |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
550 |
return (e, p) |
7315 | 551 |
|
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
552 |
procCall = do |
6450 | 553 |
r <- reference |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
554 |
p <- option [] $ (parens pas) parameters |
6450 | 555 |
return $ ProcCall r p |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
556 |
|
6275 | 557 |
parameters = (commaSep pas) expression <?> "parameters" |
7315 | 558 |
|
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
559 |
functionBody = do |
6399 | 560 |
tv <- typeVarDeclaration True |
561 |
comments |
|
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
562 |
p <- phrasesBlock |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
563 |
char ';' |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
564 |
comments |
6399 | 565 |
return (TypesAndVars tv, p) |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
566 |
|
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
567 |
uses = liftM Uses (option [] u) |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
568 |
where |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
569 |
u = do |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
570 |
string "uses" |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
571 |
comments |
6275 | 572 |
u <- (iD >>= \i -> comments >> return i) `sepBy1` (char ',' >> comments) |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
573 |
char ';' |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
574 |
comments |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
575 |
return u |
6355 | 576 |
|
577 |
initExpression = buildExpressionParser table term <?> "initialization expression" |
|
578 |
where |
|
579 |
term = comments >> choice [ |
|
8442 | 580 |
liftM (uncurry BuiltInFunction) $ builtInFunction initExpression |
6453
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6452
diff
changeset
|
581 |
, try $ brackets pas (commaSep pas $ initExpression) >>= return . InitSet |
7690
6ef121a80cb0
Treat init expression in parens as just expression instead of array initializer when there's only one entry in expressions list
unc0rr
parents:
7642
diff
changeset
|
582 |
, try $ parens pas (commaSep pas $ initExpression) >>= \ia -> when (null $ tail ia) mzero >> return (InitArray ia) |
6ef121a80cb0
Treat init expression in parens as just expression instead of array initializer when there's only one entry in expressions list
unc0rr
parents:
7642
diff
changeset
|
583 |
, try $ parens pas (sepEndBy recField (char ';' >> comments)) >>= return . InitRecord |
6ef121a80cb0
Treat init expression in parens as just expression instead of array initializer when there's only one entry in expressions list
unc0rr
parents:
7642
diff
changeset
|
584 |
, parens pas initExpression |
6355 | 585 |
, try $ integer pas >>= \i -> notFollowedBy (char '.') >> (return . InitNumber . show) i |
586 |
, try $ float pas >>= return . InitFloat . show |
|
6388 | 587 |
, try $ integer pas >>= return . InitNumber . show |
6355 | 588 |
, stringLiteral pas >>= return . InitString |
6444 | 589 |
, char '#' >> many digit >>= \c -> comments >> return (InitChar c) |
590 |
, char '$' >> many hexDigit >>= \h -> comments >> return (InitHexNumber h) |
|
6453
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6452
diff
changeset
|
591 |
, char '@' >> initExpression >>= \c -> comments >> return (InitAddress c) |
6355 | 592 |
, try $ string "nil" >> return InitNull |
6453
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6452
diff
changeset
|
593 |
, itypeCast |
6355 | 594 |
, iD >>= return . InitReference |
595 |
] |
|
7315 | 596 |
|
6355 | 597 |
recField = do |
598 |
i <- iD |
|
599 |
spaces |
|
600 |
char ':' |
|
601 |
spaces |
|
602 |
e <- initExpression |
|
603 |
spaces |
|
604 |
return (i ,e) |
|
605 |
||
7315 | 606 |
table = [ |
7066
12cc2bd84b0b
Make pas2c even more happier with uGears.c, allow assigning arrays in some cases
unc0rr
parents:
7043
diff
changeset
|
607 |
[ |
12cc2bd84b0b
Make pas2c even more happier with uGears.c, allow assigning arrays in some cases
unc0rr
parents:
7043
diff
changeset
|
608 |
Prefix (char '-' >> return (InitPrefixOp "-")) |
7429
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
609 |
,Prefix (try (string "not") >> return (InitPrefixOp "not")) |
7066
12cc2bd84b0b
Make pas2c even more happier with uGears.c, allow assigning arrays in some cases
unc0rr
parents:
7043
diff
changeset
|
610 |
] |
12cc2bd84b0b
Make pas2c even more happier with uGears.c, allow assigning arrays in some cases
unc0rr
parents:
7043
diff
changeset
|
611 |
, [ Infix (char '*' >> return (InitBinOp "*")) AssocLeft |
6355 | 612 |
, Infix (char '/' >> return (InitBinOp "/")) AssocLeft |
613 |
, Infix (try (string "div") >> return (InitBinOp "div")) AssocLeft |
|
614 |
, Infix (try (string "mod") >> return (InitBinOp "mod")) AssocLeft |
|
7429
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
615 |
, Infix (try $ string "and" >> return (InitBinOp "and")) AssocLeft |
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
616 |
, Infix (try $ string "shl" >> return (InitBinOp "shl")) AssocNone |
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
617 |
, Infix (try $ string "shr" >> return (InitBinOp "shr")) AssocNone |
6355 | 618 |
] |
619 |
, [ Infix (char '+' >> return (InitBinOp "+")) AssocLeft |
|
620 |
, Infix (char '-' >> return (InitBinOp "-")) AssocLeft |
|
7429
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
621 |
, Infix (try $ string "or" >> return (InitBinOp "or")) AssocLeft |
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
622 |
, Infix (try $ string "xor" >> return (InitBinOp "xor")) AssocLeft |
6355 | 623 |
] |
624 |
, [ Infix (try (string "<>") >> return (InitBinOp "<>")) AssocNone |
|
625 |
, Infix (try (string "<=") >> return (InitBinOp "<=")) AssocNone |
|
626 |
, Infix (try (string ">=") >> return (InitBinOp ">=")) AssocNone |
|
627 |
, Infix (char '<' >> return (InitBinOp "<")) AssocNone |
|
628 |
, Infix (char '>' >> return (InitBinOp ">")) AssocNone |
|
629 |
, Infix (char '=' >> return (InitBinOp "=")) AssocNone |
|
630 |
] |
|
7429
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
631 |
{--, [ Infix (try $ string "and" >> return (InitBinOp "and")) AssocLeft |
6355 | 632 |
, Infix (try $ string "or" >> return (InitBinOp "or")) AssocLeft |
633 |
, Infix (try $ string "xor" >> return (InitBinOp "xor")) AssocLeft |
|
634 |
] |
|
6858 | 635 |
, [ Infix (try $ string "shl" >> return (InitBinOp "shl")) AssocNone |
636 |
, Infix (try $ string "shr" >> return (InitBinOp "shr")) AssocNone |
|
7429
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
637 |
]--} |
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
638 |
--, [Prefix (try (string "not") >> return (InitPrefixOp "not"))] |
6355 | 639 |
] |
6388 | 640 |
|
6453
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6452
diff
changeset
|
641 |
itypeCast = do |
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6452
diff
changeset
|
642 |
t <- choice $ map (\s -> try $ caseInsensitiveString s >>= \i -> notFollowedBy alphaNum >> return i) knownTypes |
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6452
diff
changeset
|
643 |
i <- parens pas initExpression |
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6452
diff
changeset
|
644 |
comments |
6618 | 645 |
return $ InitTypeCast (Identifier t BTUnknown) i |
7315 | 646 |
|
6388 | 647 |
builtInFunction e = do |
648 |
name <- choice $ map (\s -> try $ caseInsensitiveString s >>= \i -> notFollowedBy alphaNum >> return i) builtin |
|
649 |
spaces |
|
6897 | 650 |
exprs <- option [] $ parens pas $ option [] $ commaSep1 pas $ e |
6388 | 651 |
spaces |
652 |
return (name, exprs) |
|
6512 | 653 |
|
654 |
systemUnit = do |
|
655 |
string "system;" |
|
656 |
comments |
|
657 |
string "type" |
|
658 |
comments |
|
659 |
t <- typesDecl |
|
660 |
string "var" |
|
661 |
v <- varsDecl True |
|
662 |
return $ System (t ++ v) |
|
7429
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
663 |
|
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
664 |
redoUnit = do |
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
665 |
string "redo;" |
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
666 |
comments |
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
667 |
string "type" |
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
668 |
comments |
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
669 |
t <- typesDecl |
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
670 |
string "var" |
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
671 |
v <- varsDecl True |
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
672 |
return $ Redo (t ++ v) |
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
673 |