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 True
%token If
%token Then
%token Else
%token Print
%token <string> Ident
%token <int> Int
%token <float> 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 <Omniflan.Ast.program> prog

View File

@ -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)) }