diff options
Diffstat (limited to 'compilador/ast')
-rw-r--r-- | compilador/ast/decl.py | 26 | ||||
-rw-r--r-- | compilador/ast/expr.py | 108 | ||||
-rw-r--r-- | compilador/ast/ident.py | 3 | ||||
-rw-r--r-- | compilador/ast/type.py | 11 |
4 files changed, 0 insertions, 148 deletions
diff --git a/compilador/ast/decl.py b/compilador/ast/decl.py deleted file mode 100644 index 1c12162..0000000 --- a/compilador/ast/decl.py +++ /dev/null @@ -1,26 +0,0 @@ -from typing import Optional - -from type import Type -from ident import Ident -from expr import Expr - -# A global declaration. -# -# entero a = 0; -@dataclass -class DeclGlobal: - ident: Ident - _type: Type - init: Optional[Expr] - -# A function declaration. -# -# vacio main() { ... } -@dataclass -class DeclFunc: - ident: Ident - prototype: Type - body: Optional[Expr] - -# A Javañol declaration -Decl = DeclGlobal | DeclFunc diff --git a/compilador/ast/expr.py b/compilador/ast/expr.py deleted file mode 100644 index 646733f..0000000 --- a/compilador/ast/expr.py +++ /dev/null @@ -1,108 +0,0 @@ -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) diff --git a/compilador/ast/ident.py b/compilador/ast/ident.py deleted file mode 100644 index b6a3acb..0000000 --- a/compilador/ast/ident.py +++ /dev/null @@ -1,3 +0,0 @@ -from typing import List - -Ident = List[str] diff --git a/compilador/ast/type.py b/compilador/ast/type.py deleted file mode 100644 index 62a56e9..0000000 --- a/compilador/ast/type.py +++ /dev/null @@ -1,11 +0,0 @@ -from enum import Enum - -# A built-in primitive type (int, bool, str, etc). -class BuiltinType(Enum): - BOOLEAN = 'booleano' - STRING = 'cadena' - CHAR = 'caracter' - INT = 'entero' - VOID = 'vacio' - -Type = BuiltinType |