-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlexer.mll
99 lines (80 loc) · 1.84 KB
/
lexer.mll
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
{
open Parser
open Lexing
(** Increments the lexing buffer line number counter.*)
let incr_line lexbuf =
let pos = lexbuf.lex_curr_p in
lexbuf.lex_curr_p <-
{pos with pos_lnum = pos.pos_lnum + 1; pos_bol = 0}
}
let impr = "Print "
let const = "Const"
let com = '\'' [^'\n']*
let coms = "/\'" ([^'\''] | '\''[^'/'])* "\'/"
let inclu = "#include " ('\"' ['a'-'z' 'A'-'Z' '_' '.']* '\"' | '<' ['a'-'z' 'A'-'Z' '_' '.']* '>')
let var_int = ('0'|['1'-'9']['0'-'9']*)
let var_double = ('0'|['1'-'9']['0'-'9']*)('.'['0'-'9']+)?
let var_string = '\"' ([^'\"'] | "\\\"")* '\"'
let ident = ['a'-'z' 'A'-'Z' '_'] ['a'-'z' 'A'-'Z' '0'-'9' '_']*
let type_string = "String"
let type_double = "Double"
let type_integer = "Integer"
rule basic = parse
impr as ip {PRINT ip}
| ';' {SEMICOLON}
| ':' {COLON}
| ',' {COMMA}
| '\\' {BS}
| '(' {LPAREN}
| ')' {RPAREN}
| '+' {PLUS}
| '-' {MINUS}
| '*' {MUL}
| '/' {DIV}
| '{' {ACOLLEFT}
| '}' {ACOLRIGHT}
| '=' {AFFECT}
| "<" {LT}
| ">" {GT}
| "==" {EQ}
| "!=" {NE}
| "<=" {LE}
| ">=" {GE}
| "If" {IF}
| "Then" {THEN}
| "Else" {ELSE}
| "ElseIf" {ELSEIF}
| "End If" {ENDIF}
| "Declare" {DECLARE}
| "Function" {FUNCTION}
| "Return" {RETURN}
| "End Function" {END_FUNC}
| "Sub" {SUB}
| "End Sub" {END_SUB}
| "While" {WHILE}
| "Wend" {WEND}
| "For" {FOR}
| "To" {TO}
| "Step" {STEP}
| "Do" {DO}
| "Loop" {LOOP}
| "Next" {NEXT}
| com as c {LCOM c}
| coms as c {MCOM c}
| inclu as i {INCLUDE i}
| var_int as i {INT i}
| var_double as d {DOUBLE d}
| var_string as str {STRING str}
| "Dim" {DIM}
| "As" {AS}
| const {CONST}
| "True" {TRUE}
| "False" {FALSE}
| type_string {TYPE_STRING}
| type_double {TYPE_DOUBLE}
| type_integer {TYPE_INT}
| ident as id {IDENT id}
| '\n' {incr_line lexbuf; basic lexbuf}
| ' ' | '\t' | '\r' {basic lexbuf}
| _ {basic lexbuf}
| eof {EOF}