72 lines
2.1 KiB
Plaintext
72 lines
2.1 KiB
Plaintext
/* Lexical Analysis with Flex (1.6.0) We used some of the code from this manual */
|
|
/* so we placed the citation here. */
|
|
/* definitions */
|
|
|
|
%option noyywrap
|
|
%{
|
|
#include "typedefs.h"
|
|
int line_number = 1, column_number = 1;
|
|
%}
|
|
|
|
COM ([^*]|\*+[^)*])*
|
|
ID [A-Za-z_][0-9A-Za-z_]*
|
|
DIGIT [0-9]
|
|
CHAR \\n|\\t|\\'|[^'\n\t\\]
|
|
/* char can be a newline, tab, an escaped quote, or anything but a single quote, an actual line break, an actual tab, or a backslash by itself (to prevent confusion from escaped quote */
|
|
SCHAR \\n|\\t|\\\"|[^\"\n\\]
|
|
/* similar to above, a string Char (SCHAR) is the same as a CHAR except we cannot have double quotes instead of single quotes. Double quotes need to be escaped in Flex unlike single quotes based on documentation */
|
|
|
|
%%
|
|
|
|
"integer" {return T_INTEGER;}
|
|
"address" {return T_ADDRESS;}
|
|
"Boolean" {return T_BOOLEAN;}
|
|
"character" {return T_CHARACTER;}
|
|
|
|
{DIGIT}+ {return C_INTEGER;}
|
|
"null" {return C_NULL;}
|
|
|
|
"while" {return WHILE;}
|
|
"if" {return IF;}
|
|
"then" {return THEN;}
|
|
"else" {return ELSE;}
|
|
"type" {return TYPE;}
|
|
"function" {return FUNCTION;}
|
|
"return" {return RETURN;}
|
|
"external" {return EXTERNAL;}
|
|
"as" {return AS;}
|
|
|
|
'{CHAR}' {return C_CHARACTER;}
|
|
"true" {return C_TRUE;}
|
|
"false" {return C_FALSE;}
|
|
|
|
"+" {return ADD;}
|
|
"-" {return SUB_OR_NEG;}
|
|
"*" {return MUL;}
|
|
"/" {return DIV;}
|
|
"%" {return REM;}
|
|
"<" {return LESS_THAN;}
|
|
"=" {return EQUAL_TO;}
|
|
":=" {return ASSIGN;}
|
|
"!" {return NOT;}
|
|
"&" {return AND;}
|
|
"|" {return OR;}
|
|
"." {return DOT;}
|
|
|
|
";" {return SEMI_COLON;}
|
|
":" {return COLON;}
|
|
"," {return COMMA;}
|
|
"->" {return ARROW;}
|
|
|
|
"reserve" {return RESERVE;}
|
|
"release" {return RELEASE;}
|
|
|
|
\"{SCHAR}*\" {return C_STRING;}
|
|
"(*"{COM}"*)" {return COMMENT;}
|
|
|
|
{ID} {return ID;}
|
|
|
|
\n {line_number++; column_number = 1;}
|
|
. {column_number++;}
|
|
|
|
%% |