blob: 646733f3862d456bcfc25d78ab07faa8a674266f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
from dataclasses import dataclass
from enum import Enum, auto
from typing import List, Optional
from type import Type
# An assignment expression
#
# a = 10
@dataclass
class AssignExpr:
_object: Expr
value: Expr
# A binary arithmetic operator
class BinarithmOp(Enum):
BAND = '&'
BOR = '|'
DIV = '/'
GT = '>'
GTEQ = '>='
LAND = '&&'
LEQUAL = '=='
LESS = '<'
LESSEQ = '<='
LOR = '||'
MINUS = '-'
NEQUAL = '!='
PLUS = '+'
TIMES = '*'
# A binary arithmetic expression.
#
# a * b
@dataclass
class BinarithmExpr:
op: BinarithmOp
lvalue: Expr
rvalue: Expr
# A function call expression.
#
# foo(bar)
@dataclass
class CallExpr:
lvalue: Expr,
args: List[Expr]
# A compound expression.
#
# {
# foo;
# bar;
# // ...
# }
@dataclass
class CompoundExpr:
exprs: List[Expr]
# A scalar value.
Value = bool | str | int | type(None)
# An integer constant.
@dataclass
class NumberConstant:
value: int
# A constant expression.
ConstantExpr = Value | NumberConstant
# A for loop.
#
# porcada (entero a = 0; a < b; a++) {}
@dataclass
class ForExpr:
bindings: Optional[Expr]
cond: Expr,
afterthought: Optional[Expr]
body: Expr
# An if or if..else expression.
#
# si (a) { } sino { }
@dataclass
class IfExpr:
cond: Expr,
tbranch: Expr,
fbranch: Optional[Expr]
# A print statement.
#
# imprimir a
PrintExpr = Expr
# A read statement.
#
# leer a
ReadExpr = Expr
# A return statement.
#
# return a
ReturnExpr = Optional[Expr]
# A Javañol expression
Expr = (AssignExpr | BinarithmExpr | CallExpr | ConstantExpr |
ForExpr | IfExpr | CompoundExpr | PrintExpr |
ReadExpr | ReturnExpr)
|