Skip to content

Commit

Permalink
Added BOZ
Browse files Browse the repository at this point in the history
  • Loading branch information
czgdp1807 committed Oct 19, 2021
1 parent c413fc7 commit 589411f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions grammar/ASR.asdl
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ expr
| ConstantComplex(float re, float im, ttype type)
| ConstantLogical(bool value, ttype type)
| ConstantString(string s, ttype type)
| BOZ(string s, boz boz_type, ttype? type)
| Var(symbol v)
| ArrayRef(symbol v, array_index* args, ttype type, expr? value)
| DerivedRef(expr v, symbol m, ttype type, expr? value)
Expand Down Expand Up @@ -242,6 +243,8 @@ strop = Concat

cmpop = Eq | NotEq | Lt | LtE | Gt | GtE

boz = Binary | Hex | Octal

cast_kind
= RealToInteger
| IntegerToReal
Expand Down
1 change: 1 addition & 0 deletions src/lfortran/asr_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ static inline ASR::ttype_t* expr_type(const ASR::expr_t *f)
case ASR::exprType::StrOp: { return ((ASR::StrOp_t*)f)->m_type; }
case ASR::exprType::ImpliedDoLoop: { return ((ASR::ImpliedDoLoop_t*)f)->m_type; }
case ASR::exprType::DerivedTypeConstructor: { return ((ASR::DerivedTypeConstructor_t*)f)->m_type; }
case ASR::exprType::BOZ: { return ((ASR::BOZ_t*)f)->m_type; }
default : throw LFortranException("Not implemented");
}
}
Expand Down
21 changes: 21 additions & 0 deletions src/lfortran/semantics/ast_common_visitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -1210,6 +1210,27 @@ class CommonVisitor : public AST::BaseVisitor<Derived> {
tmp = ASR::make_ConstantString_t(al, x.base.base.loc, x.m_s, type);
}

void visit_BOZ(const AST::BOZ_t& x) {
LFortran::Str boz_content;
std::string s = x.m_s;
boz_content.from_str(al, s.substr(1));
ASR::bozType boz_type;
if( s[0] == 'b' || s[0] == 'B' ) {
boz_type = ASR::bozType::Binary;
} else if( s[0] == 'z' || s[0] == 'Z' ) {
boz_type = ASR::bozType::Hex;
} else if( s[0] == 'o' || s[0] == 'O' ) {
boz_type = ASR::bozType::Octal;
} else {
throw SemanticError(R"""(Only 'b', 'o' and 'z'
are accepted as prefixes of
BOZ literal constants.)""",
x.base.base.loc);
}
tmp = ASR::make_BOZ_t(al, x.base.base.loc, boz_content.c_str(al),
boz_type, nullptr);
}

void visit_Num(const AST::Num_t &x) {
int ikind = 4;
if (x.m_kind) {
Expand Down

0 comments on commit 589411f

Please sign in to comment.