Skip to content

Commit

Permalink
Support float numbers (#858)
Browse files Browse the repository at this point in the history
  • Loading branch information
vladmos authored Jun 5, 2020
1 parent a6c28d6 commit bcd428a
Show file tree
Hide file tree
Showing 6 changed files with 227 additions and 175 deletions.
2 changes: 1 addition & 1 deletion build/lex.go
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ func (in *input) Lex(val *yySymType) int {
return _CONTINUE
}
if len(val.tok) > 0 && val.tok[0] >= '0' && val.tok[0] <= '9' {
return _NUMBER
return _INT
}
return _IDENT
}
Expand Down
16 changes: 14 additions & 2 deletions build/parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ package build
%token <pos> _FOR // keyword for
%token <pos> _GE // operator >=
%token <pos> _IDENT // non-keyword identifier
%token <pos> _NUMBER // number
%token <pos> _INT // integer number
%token <pos> _IF // keyword if
%token <pos> _ELSE // keyword else
%token <pos> _ELIF // keyword elif
Expand Down Expand Up @@ -924,7 +924,19 @@ ident:
}

number:
_NUMBER
_INT '.' _INT
{
$$ = &LiteralExpr{Start: $1, Token: $<tok>1 + "." + $<tok>3}
}
| _INT '.'
{
$$ = &LiteralExpr{Start: $1, Token: $<tok>1 + "."}
}
| '.' _INT
{
$$ = &LiteralExpr{Start: $1, Token: "." + $<tok>2}
}
| _INT %prec ShiftInstead
{
$$ = &LiteralExpr{Start: $1, Token: $<tok>1}
}
Expand Down
Loading

0 comments on commit bcd428a

Please sign in to comment.