Add all the assignment code.
Signed-off-by: jmug <u.g.a.mariano@gmail.com>
This commit is contained in:
parent
58c6b1f81c
commit
cfe502c598
1277 changed files with 48709 additions and 1 deletions
83
hw4/ll/lllexer.mll
Normal file
83
hw4/ll/lllexer.mll
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
{ open Lexing
|
||||
open Llparser
|
||||
|
||||
exception SyntaxError of string
|
||||
}
|
||||
|
||||
let newline = '\n' | ('\r' '\n') | '\r'
|
||||
let whitespace = ['\t' ' ']
|
||||
let lowercase = ['a'-'z']
|
||||
let uppercase = ['A'-'Z']
|
||||
let character = lowercase | uppercase
|
||||
let digit = '-'? ['0'-'9']
|
||||
let identifier = (character | digit | '_' ) (character | digit | '_' | '.')*
|
||||
|
||||
rule token = parse
|
||||
| eof { EOF }
|
||||
| whitespace+ { token lexbuf }
|
||||
| newline+ { token lexbuf }
|
||||
| "c\"" { read_string (Buffer.create 17) lexbuf }
|
||||
| '*' { STAR }
|
||||
| ',' { COMMA }
|
||||
| ':' { COLON }
|
||||
| '=' { EQUALS }
|
||||
| '(' { LPAREN }
|
||||
| ')' { RPAREN }
|
||||
| '{' { LBRACE }
|
||||
| '}' { RBRACE }
|
||||
| '[' { LBRACKET }
|
||||
| ']' { RBRACKET }
|
||||
| "i1" { I1 }
|
||||
| "i8" { I8 }
|
||||
| "i32" { I32 }
|
||||
| "i64" { I64 }
|
||||
| "to" { TO }
|
||||
| "br" { BR }
|
||||
| "eq" { EQ }
|
||||
| "ne" { NE }
|
||||
| "or" { OR }
|
||||
| "and" { AND }
|
||||
| "add" { ADD }
|
||||
| "sub" { SUB }
|
||||
| "mul" { MUL }
|
||||
| "xor" { XOR }
|
||||
| "slt" { SLT }
|
||||
| "sle" { SLE }
|
||||
| "sgt" { SGT }
|
||||
| "sge" { SGE }
|
||||
| "shl" { SHL }
|
||||
| "ret" { RET }
|
||||
| "getelementptr" { GEP }
|
||||
| "type" { TYPE }
|
||||
| "null" { NULL }
|
||||
| "lshr" { LSHR }
|
||||
| "ashr" { ASHR }
|
||||
| "call" { CALL }
|
||||
| "icmp" { ICMP }
|
||||
| "void" { VOID }
|
||||
| "load" { LOAD }
|
||||
| "entry" { ENTRY }
|
||||
| "store" { STORE }
|
||||
| "label" { LABEL }
|
||||
| "global" { GLOBAL }
|
||||
| "define" { DEFINE }
|
||||
| "declare" { DECLARE }
|
||||
| "external" { EXTERNAL }
|
||||
| "alloca" { ALLOCA }
|
||||
| "bitcast" { BITCAST }
|
||||
| '%' ('.' ?) (identifier as i) { UID i }
|
||||
| '@' ('.' ?) (identifier as i) { GID i }
|
||||
| "x" { CROSS } (* for Array types *)
|
||||
| digit+ as d { INT (int_of_string d) }
|
||||
| identifier as i { LBL i }
|
||||
| ";" ([^ '\n' '\r'])* newline { token lexbuf } (* comments *)
|
||||
| "declare" ([^ '\n' '\r'])* newline { token lexbuf } (* declare acts as a comment for our IR *)
|
||||
| _ as c { raise @@ SyntaxError ("Unexpected character: " ^ Char.escaped c) }
|
||||
|
||||
and read_string buf = parse
|
||||
| '\\' "00" '"' { STRING (Buffer.contents buf) }
|
||||
| '\\' { Buffer.add_char buf '\\'; read_string buf lexbuf }
|
||||
| [^ '"' '\\']+ { Buffer.add_string buf (Lexing.lexeme lexbuf)
|
||||
; read_string buf lexbuf }
|
||||
| _ { raise (SyntaxError ("Illegal string character: " ^ Lexing.lexeme lexbuf)) }
|
||||
| eof { raise (SyntaxError ("String is not terminated")) }
|
||||
Loading…
Add table
Add a link
Reference in a new issue