Last active
May 3, 2023 17:18
-
-
Save mohanr/b8b1735456fe7112865014bcf2ed182b to your computer and use it in GitHub Desktop.
Lexer in Racket
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang typed/racket | |
(require racket/list) | |
(define (operator c ) | |
(match c | |
['+' Plus] | |
['-' Minus] | |
['/' Div])) | |
(struct (i) Literal ([v : i])) | |
(struct Plus ()) | |
(struct Minus ()) | |
(struct Div ()) | |
(struct (i) InvalidChar ([v : i])) | |
(struct EndOfInput()) | |
(struct Empty() ) | |
(struct (i) Unexpected([val : i])) | |
(define-type (Expected i e) (U Integer Char)) | |
(struct (i) ExpectedEndOfFile([val : i])) | |
(struct (i) BeginningOfInput ([val : i])) | |
(define-type (ErrorType i e) | |
(U Empty EndOfInput | |
( Unexpected i) | |
( Expected i e) | |
( ExpectedEndOfFile i) | |
( BeginningOfInput i))) | |
(define-type (Error i e) (U Integer | |
(ErrorType i e))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment