aboutsummaryrefslogtreecommitdiff
path: root/compilador/astree
diff options
context:
space:
mode:
authorIván Ávalos <avalos@disroot.org>2022-11-25 16:33:08 -0600
committerIván Ávalos <avalos@disroot.org>2022-11-25 16:33:08 -0600
commitc7f014aef2c86d7a17f2642180732a6ba9b2a125 (patch)
treed3439be25bf3ef025abb67144fc9c2fe1114530b /compilador/astree
parent43ca3b1370fcb9e7cb8c3126ebf4e6ed7833fc13 (diff)
downloadjavanol-c7f014aef2c86d7a17f2642180732a6ba9b2a125.tar.gz
javanol-c7f014aef2c86d7a17f2642180732a6ba9b2a125.tar.bz2
javanol-c7f014aef2c86d7a17f2642180732a6ba9b2a125.zip
¡Ya hay funciones y (algunas) expresiones!
Diffstat (limited to 'compilador/astree')
-rw-r--r--compilador/astree/expr.py29
1 files changed, 21 insertions, 8 deletions
diff --git a/compilador/astree/expr.py b/compilador/astree/expr.py
index 1bb7f4f..d5a2cb0 100644
--- a/compilador/astree/expr.py
+++ b/compilador/astree/expr.py
@@ -3,10 +3,19 @@ from enum import Enum, auto
from typing import List, Optional
from astree.type import Type
+from astree.ident import Ident
Expr = None
-# An assignment expression
+# An identifier access expression.
+#
+# a
+AccessIdentifier = Ident
+
+# An access expression.
+AccessExpr = AccessIdentifier
+
+# An assignment expression.
#
# a = 10
@dataclass
@@ -14,7 +23,7 @@ class AssignExpr:
_object: Expr
value: Expr
-# A binary arithmetic operator
+# A binary arithmetic operator.
class BinarithmOp(Enum):
BAND = '&'
BOR = '|'
@@ -92,19 +101,23 @@ class IfExpr:
# A print statement.
#
# imprimir a
-PrintExpr = Expr
+@dataclass
+class PrintExpr:
+ expr: Expr
# A read statement.
#
# leer a
-ReadExpr = Expr
+@dataclass
+class ReadExpr:
+ expr: AccessExpr
# A return statement.
#
# return a
ReturnExpr = Optional[Expr]
-# A Javañol expression
-Expr = (AssignExpr | BinarithmExpr | CallExpr | ConstantExpr |
- ForExpr | IfExpr | CompoundExpr | PrintExpr |
- ReadExpr | ReturnExpr)
+# A Javañol expression.
+Expr = (AccessExpr | AssignExpr | BinarithmExpr | CallExpr |
+ ConstantExpr | ForExpr | IfExpr | CompoundExpr |
+ PrintExpr | ReadExpr | ReturnExpr)