-
Notifications
You must be signed in to change notification settings - Fork 0
/
Comandos.hs
94 lines (78 loc) · 2.05 KB
/
Comandos.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
module Comandos where
import Text.Parsec
import Text.Parsec.Expr
import qualified Text.Parsec.Token as T
import Text.Parsec.Language
import DataTypes
import Lex
import Relacional
import Tabelas
import Parametro
import Logico
--blocos
blocoPrincipal = do
b <- braces bloco'
return (concat (fst b), snd b)
bloco' = do
d <- many declaration
c <- many comando'
return (d, c)
bloco = braces (many comando')
-- comandos
comandoif = try (do
reserved "if"
l <- parenteses logic
b <- bloco
reserved "else"
If l b <$> bloco
)
<|> do
reserved "if"
l <- parenteses logic
b <- bloco
return (If l b [])
comandowhile = do
reserved "while"
l <- parenteses logic
While l <$> bloco
atribuicao = do
i <- identifier
operator "="
e <- expr
pontovirgula
return (Atrib i e)
comandoread = do
reserved "read"
i <- parenteses identifier
pontovirgula
return (Leitura i)
comandoprint = do
reserved "print"
e <- parenteses expr
pontovirgula
return (Print e)
comandoreturn = try (do
reserved "return"
e <- expr
pontovirgula
return (Ret (Just e))
)
<|> do
reserved "return"
pontovirgula
return (Ret Nothing)
comandocall = do
i <- identifier
e <- parenteses (list expr)
pontovirgula
return (Proc i e)
callatrib = try atribuicao
<|> comandocall
comando' = do
comandoif
<|> comandowhile
<|> callatrib
<|> comandoread
<|> comandoprint
<|> comandoreturn
<?> "command"