-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
98 lines (78 loc) · 2.21 KB
/
README
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
Morgan Peters
Sean Gray
CS 440 - Languages and Translators
How to run:
To run our analyzer you can either use the tests.py to run checks on the code.
Or you can call our lexer on a string to get the results from that string.
Report:
You have to submit a report of lexical analyzer
that states different tokens of your programming language.
Such as operators, identifier, keywords.
Define regular expressions of all tokens
Tokens:
Operators:
'LOGIC', # Or And Xor
'EQUALS', 'PLUS', 'MINUS', 'TIMES', 'DIVIDE', 'POW',
'LTHAN', 'LETHAN', 'GTHAN','GETHAN','ETO',
Identifier:
'TYPE', 'VAR', 'ID'
'ARROW', 'MATCHBREAK', 'EOL',
'COMMA', 'LBRACKET', 'RBRACKET',
'LPAREN', 'RPAREN', 'COLON',
Keywords:
IF, RULE, START, MATCH, INT, FLOAT, CHAR, STRING, BOOL, HEX
#data types
'INT', 'FLOAT', 'CHAR', 'STRING', 'BOOL', 'HEX'
Regular expressions:
MATCHBREAK = r'\|'
COMMA = r'\,'
LBRACKET = r'\['
RBRACKET = r'\]'
LETHAN = r'\<='
LTHAN = r'\<'
GETHAN = r'\>='
GTHAN = r'\>'
PLUS = r'\+'
ARROW = r'->'
MINUS = r'-'
TIMES = r'\*'
DIVIDE = r'/'
POW = r'\^'
ETO = r'=='
EQUALS = r'='
LPAREN = r'\('
RPAREN = r'\)'
COLON = r':'
STRING = r'(").+(")'
HEX = r'0x(\d|[a-f]|[A-F])+\s'
INT = r'-*\d+'
FLOAT = r'-?\d+\.d*(e-?\d+)?'
CHAR = r'(\')\S(\')'
BOOL = r'(True|False)'
COMMENT = r'\#.+'
EOL = r'!+'
RESERVED = r'[a-zA-Z_][a-zA-Z_0-9]*'
------------------------------------------------------------------------
Part 2 - Lexical Analyzer
data types -> int, float, char, string, array, bool
logic -> and, or, xor, not
forking -> () if conditional yes and no
comparisons -> == | => | =< | > | < |
match x
[x] = x|
[x:xs] = x+xs!
assignment -> =
functions -> rule
math -> +, -, %, /, *, ^ (fractional powers),
End line -> !
examples:
person type = name: string, age: int!
name rule ( arg1 type; arg2 type ) -> type = (X + Y)
fact rule (x:[int])-> int =
match x
[x] = x|
[x:xs] = x + factx!
start x = fact(x)
.........................................................................
PLY language site. Python LEX
http://www.dabeaz.com/ply/