From 2c232dd87459797fc3528e50d7b887d67e584a7c Mon Sep 17 00:00:00 2001 From: Joseph Ferano Date: Tue, 9 Jul 2024 21:50:27 +0700 Subject: [PATCH] Adding a bunch of new tokens --- lib/oflan.mly | 27 +++++++++++++++++++++++++-- lib/olexer.mll | 29 ++++++++++++++++++++++++++--- 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/lib/oflan.mly b/lib/oflan.mly index f8f8a60..84aefdc 100644 --- a/lib/oflan.mly +++ b/lib/oflan.mly @@ -10,13 +10,36 @@ %token False %token True +%token If +%token Then +%token Else +%token Print %token Ident %token Int %token F32 -%token Equal %token LParen %token RParen +%token LBrace +%token RBrace +%token LBracket +%token RBracket +%token Dot +%token Comma +%token Colon +%token Semicolon +%token Plus +%token Minus +%token Star +%token Slash +%token Bang +%token Equal +%token EqualEqual +%token BangEqual +%token LT +%token GT +%token LTE +%token GTE %start prog @@ -39,4 +62,4 @@ toplevel_item: | stmt = stmt { Stmt stmt } prog: - | prog = separated_list(Newline, toplevel_item); Eof { prog } \ No newline at end of file + | prog = separated_list(Newline, toplevel_item); Eof { prog } diff --git a/lib/olexer.mll b/lib/olexer.mll index ba5eb0a..3c0f301 100644 --- a/lib/olexer.mll +++ b/lib/olexer.mll @@ -27,9 +27,32 @@ rule read = | newline { next_line lexbuf; read lexbuf } | int { Int (int_of_string (Lexing.lexeme lexbuf))} | "let" { Let } + | "if" { If } + | "then" { Then } + | "else" { Else } + | "print" { Print } | ident { Ident (Lexing.lexeme lexbuf) } - | '=' { Equal } | '(' { LParen } - | 'R' { RParen } + | ')' { RParen } + | '[' { LBracket } + | ']' { RBracket } + | '{' { LBrace } + | '}' { RBrace } + | '.' { Dot } + | ',' { Comma } + | ':' { Colon } + | ';' { Semicolon } + | '+' { Plus } + | '-' { Minus } + | '*' { Star } + | '/' { Slash } + | '!' { Bang } + | '=' { Equal } + | "==" { EqualEqual } + | "!=" { BangEqual } + | '<' { LT } + | '>' { GT } + | "<=" { LTE } + | ">=" { GTE } | eof { Eof } - | _ { raise (SyntaxError ("Unexpected char: " ^ Lexing.lexeme lexbuf)) } \ No newline at end of file + | _ { raise (SyntaxError ("Unexpected char: " ^ Lexing.lexeme lexbuf)) }