diff --git a/agast.py b/agast.py index 3e910e1..19a249f 100644 --- a/agast.py +++ b/agast.py @@ -29,6 +29,7 @@ class Equation: def __init__(self, lhs: Expr, rhs: Expr): self.lhs = lhs self.rhs = rhs + def __repr__(self) -> str: return f"{self.lhs} = {self.rhs}" class Variant: def __init__(self, prod: List[Sym], equations: List[Equation]): @@ -43,7 +44,7 @@ class Node(Decl): self.variants = variants class ExprDot(Expr): - def __init__(self, left: Expr, right: Expr): + def __init__(self, left: Expr, right: str): self.left = left self.right = right def __repr__(self) -> str: return f"{self.left}.{self.right}" @@ -101,7 +102,7 @@ class Parser(Transformer[List[Decl]]): def equation(self, items: List[Expr]) -> Equation: return Equation(items[0], items[1]) # expr - def expr_dot(self, items: List[Expr]) -> Expr: + def expr_dot(self, items: List[Any]) -> Expr: [left, right] = items return ExprDot(left, right) def expr_add(self, items: List[Expr]) -> Expr: @@ -112,7 +113,10 @@ class Parser(Transformer[List[Decl]]): return ExprMul(left, right) def expr_call(self, items: List[Expr]) -> Expr: [func, args] = items - return ExprMul(func, args) + # TODO: args should be a list of exprs -_ - + return ExprCall(func, [args]) + def expr_name(self, items: List[str]) -> Expr: + return ExprName(items[0]) def sep_trail(self, items: List[Tree]) -> List[T]: return list(map(lambda it: cast(T, it), items)) diff --git a/grammar.lark b/grammar.lark index 377cbe6..008d538 100644 --- a/grammar.lark +++ b/grammar.lark @@ -29,7 +29,7 @@ equation_: equation ";" // called lvalue, and should NOT include literals equation: expr "=" expr -expr: expr_dot +?expr: expr_dot | expr_add | expr_mul | expr_call