Skip to content

Commit

Permalink
Parsing parenthesized expressions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Baris Aktemur committed Nov 9, 2017
1 parent acd8eb5 commit 169f372
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Deve/lexer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type token = INT of int
| PLUS | STAR | MINUS | SLASH
| LET | EQUALS | IN
| IF | THEN | ELSE
| LPAR | RPAR
| ERROR of char
| EOF
;;
Expand Down Expand Up @@ -50,6 +51,8 @@ let rec tokenize chars =
| ' '::rest -> tokenize rest
| '\t'::rest -> tokenize rest
| '\n'::rest -> tokenize rest
| '('::rest -> LPAR::(tokenize rest)
| ')'::rest -> RPAR::(tokenize rest)
| c::rest when isDigit(c) ->
tokenizeInt rest (digitToInt c)
| c::rest when isLowercaseLetter(c) ->
Expand Down
4 changes: 4 additions & 0 deletions Deve/parser.ml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ and parseLevel4Exp tokens =
| INT i :: rest -> (CstI i, rest)
| NAME x :: rest -> (Var x, rest)
| BOOL b :: rest -> (CstB b, rest)
| LPAR::rest ->
let (e, tokens1) = parseExp rest in
let rest1 = consume RPAR tokens1 in
(e, rest1)
| t::rest -> failwith ("Unsupported token: " ^ toString(t))

(* parseMain: token list -> exp *)
Expand Down

0 comments on commit 169f372

Please sign in to comment.