aboutsummaryrefslogtreecommitdiff
path: root/compilador/parse
diff options
context:
space:
mode:
Diffstat (limited to 'compilador/parse')
-rw-r--r--compilador/parse/base.py4
-rw-r--r--compilador/parse/expr.py15
-rw-r--r--compilador/parse/type.py2
3 files changed, 10 insertions, 11 deletions
diff --git a/compilador/parse/base.py b/compilador/parse/base.py
index 9ee673b..bf9277d 100644
--- a/compilador/parse/base.py
+++ b/compilador/parse/base.py
@@ -61,10 +61,10 @@ class BaseParser:
def unlex(self):
self.iterador.back()
- def synassert(self, cond: bool, msg: str) -> (Error | NoReturn):
+ def synassert(self, cond: bool, msg: str, numlinea: int) -> (Error | NoReturn):
'''Returns a syntax error if cond is false and void
otherwise.
'''
if not cond:
- return Error(msg = msg)
+ return Error(msg = msg, numlinea = numlinea)
diff --git a/compilador/parse/expr.py b/compilador/parse/expr.py
index 6608f6a..2401f30 100644
--- a/compilador/parse/expr.py
+++ b/compilador/parse/expr.py
@@ -33,7 +33,8 @@ class ParseExpr:
error = self.parser.synassert(
isinstance(obj, AccessExpr),
- "Se esperaba un objeto como destino de la asignación.")
+ "Se esperaba un objeto como destino de la asignación.",
+ numlinea = tok.numlinea)
if type(error) is Error:
return error
@@ -88,7 +89,7 @@ class ParseExpr:
# Expresión
expr = self.expr()
if type(expr) is Error:
- return epr
+ return expr
args.append(expr)
@@ -136,12 +137,10 @@ class ParseExpr:
def constant(self) -> (Expr | Error):
tok: LexToken = self.parser.lex()
expr: Optional[ConstantExpr] = None
- if tok.tipo == Token.STRING_LIT:
- expr: str = tok.valor
+ if tok.tipo in [Token.STRING_LIT, Token.BOOLEAN_LIT]:
+ expr = Value(value = tok.valor)
elif tok.tipo == Token.INT_LIT:
expr = NumberConstant(value = tok.valor)
- elif tok.tipo == Token.BOOLEAN_LIT:
- expr: bool = tok.valor
else:
return Error(msg = "Se esperaba una constante.", numlinea = tok.numlinea)
return expr
@@ -260,7 +259,7 @@ class ParseExpr:
if type(ident) is Error:
return ident
- return ReadExpr(expr = ident)
+ return ReadExpr(expr = AccessExpr(ident = ident))
def plain_expression(self) -> (Expr | Error):
tok: LexToken = self.parser.peek()
@@ -281,7 +280,7 @@ class ParseExpr:
ident = ParseIdent(self.parser).ident()
if type(ident) is Error:
return ident
- return ident
+ return AccessIdentifier(ident = ident)
def unarithm(self) -> (Expr | Error):
if self.parser._try(Token.L_BRACKET):
diff --git a/compilador/parse/type.py b/compilador/parse/type.py
index 06c68d0..1fd0957 100644
--- a/compilador/parse/type.py
+++ b/compilador/parse/type.py
@@ -36,7 +36,7 @@ class ParseType:
if type(name) is Error:
return name
- params.append(FuncParam(name = name,
+ params.append(FuncParam(name = name.nombre,
_type = __type))
# ,