Adding a bunch of new tokens

This commit is contained in:
Joseph Ferano 2024-07-09 21:50:27 +07:00
parent a9fa510483
commit 2c232dd874
2 changed files with 51 additions and 5 deletions

View File

@ -10,13 +10,36 @@
%token False %token False
%token True %token True
%token If
%token Then
%token Else
%token Print
%token <string> Ident %token <string> Ident
%token <int> Int %token <int> Int
%token <float> F32 %token <float> F32
%token Equal
%token LParen %token LParen
%token RParen %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 <Omniflan.Ast.program> prog %start <Omniflan.Ast.program> prog
@ -39,4 +62,4 @@ toplevel_item:
| stmt = stmt { Stmt stmt } | stmt = stmt { Stmt stmt }
prog: prog:
| prog = separated_list(Newline, toplevel_item); Eof { prog } | prog = separated_list(Newline, toplevel_item); Eof { prog }

View File

@ -27,9 +27,32 @@ rule read =
| newline { next_line lexbuf; read lexbuf } | newline { next_line lexbuf; read lexbuf }
| int { Int (int_of_string (Lexing.lexeme lexbuf))} | int { Int (int_of_string (Lexing.lexeme lexbuf))}
| "let" { Let } | "let" { Let }
| "if" { If }
| "then" { Then }
| "else" { Else }
| "print" { Print }
| ident { Ident (Lexing.lexeme lexbuf) } | ident { Ident (Lexing.lexeme lexbuf) }
| '=' { Equal }
| '(' { LParen } | '(' { 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 } | eof { Eof }
| _ { raise (SyntaxError ("Unexpected char: " ^ Lexing.lexeme lexbuf)) } | _ { raise (SyntaxError ("Unexpected char: " ^ Lexing.lexeme lexbuf)) }