This repository has been archived by the owner on May 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
easy.lex
executable file
·69 lines (58 loc) · 1.7 KB
/
easy.lex
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
/**
* @file easy.lex
* @brief EASY Lexical Analyzer
* @author Jared Dantis
* @version 0.1
* @date 2023-05-04
*
*/
/**
* Preamble
*/
%{
#include <stdio.h>
%}
/**
* Definitions
*/
/* Single line comments: // ... */
COMMENT \/\/[^\n]*
/* Reserved words */
KEYWORD go\ to|exit|if|then|else|case|endcase|while|endwhile|repeat|until|loop|forever|for|to|by|do|endfor|input|output|array|node|call|return|stop|end|procedure
BOOLEAN true|false
/* Alphanumeric characters */
LETTER [A-Za-z]
DIGIT [0-9]
/* Literals */
NUMERIC_LIT -?{DIGIT}+(\.{DIGIT}*)?
STRING_LIT \'[^\'\n]*\'
/* Identifiers: Alphanumeric with possible underscores */
IDENTIFIER {LETTER}({LETTER}|{DIGIT}|_)*
/* Delimiters: Group and separate tokens */
DELIMITER \[|\]|\(|\)|,|;|:
/* Operators */
ASSIGNMENT =
OPERATOR \+|\-|\/|\*|\^|and|or|not|<|>|<=|>=|==|!=
/* Whitespace */
WHITESPACE [ \s\n\r\t]+
/**
* Rules
*/
%%
{KEYWORD} printf("<%s, KEYWORD>\n", yytext);
{BOOLEAN} printf("<%s, BOOLEAN>\n", yytext);
{ASSIGNMENT} printf("<%s, ASSIGNMENT>\n", yytext);
{NUMERIC_LIT} printf("<%s, NUMERIC_LITERAL>\n", yytext);
{IDENTIFIER} printf("<%s, IDENTIFIER>\n", yytext);
{OPERATOR} printf("<\'%s\', OPERATOR>\n", yytext);
{STRING_LIT} printf("<%s, STRING_LITERAL>\n", yytext);
{WHITESPACE} /* do nothing */
{DELIMITER} printf("<\'%s\', DELIMITER>\n", yytext);
{COMMENT} /* do nothing */
%%
/**
* Program logic
*/
int main() {
yylex();
}