57 lines
2.7 KiB
Plaintext
57 lines
2.7 KiB
Plaintext
/* Lexical Analysis with Flex (2.6.0) We used some of the code from this manual */
|
|
/* so we placed the citation here. */
|
|
/* definitions */
|
|
%option noyywrap
|
|
%{
|
|
#include "typedefs.h"
|
|
%}
|
|
|
|
DIGIT [0-9]
|
|
CHAR \\n|\\t|\\'|[^'\n\t\\]
|
|
SCHAR \\n|\\t|\\\"|[^\"\n\\]
|
|
COM ([^*]|\*+[^)*])*
|
|
|
|
/* INCOMPLETE */
|
|
ID [A-Za-z_][0-9A-Za-z_]*
|
|
|
|
%%
|
|
|
|
"(*"{COM}"*)" {printf("COMMENT: %s, Token: %d\n", yytext, COMMENT );} // {return COMMENT}
|
|
|
|
"integer" {printf("T_INTEGER %s, Token: %d\n", yytext, T_INTEGER);} // {return T_INTEGER}
|
|
"address" {printf("T_ADDRESS %s, Token: %d\n", yytext, T_ADDRESS);} // {return T_ADDRESS}
|
|
"Boolean" {printf("T_BOOLEAN %s, Token: %d\n", yytext, T_BOOLEAN);} // {return T_BOOLEAN}
|
|
"character" {printf("T_CHARACTER %s, Token: %d\n", yytext, T_CHARACTER);} // {return T_CHARACTER}
|
|
"string" {printf("T_STRING %s, Token: %d\n", yytext, T_STRING);} // {return T_STRING}
|
|
|
|
"while" {printf("WHILE %s, Token: %d\n", yytext, WHILE);} // {return WHILE}
|
|
"if" {printf("IF %s, Token: %d\n", yytext, IF);} // {return IF}
|
|
"then" {printf("THEN %s, Token: %d\n", yytext, THEN);} // {return THEN}
|
|
"else" {printf("ELSE %s, Token: %d\n", yytext, ELSE);} // {return ELSE}
|
|
"type" {printf("TYPE %s, Token: %d\n", yytext, TYPE);} // {return TYPE}
|
|
"function" {printf("FUNCTION %s, Token: %d\n", yytext, FUNCTION);} // {return FUNCTION}
|
|
"return" {printf("RETURN %s, Token: %d\n", yytext, RETURN);} // {return RETURN}
|
|
"external" {printf("EXTERNAL %s, Token: %d\n", yytext, EXTERNAL);} // {return EXTERNAL}
|
|
"as" {printf("AS %s, Token: %d\n", yytext, AS);} // {return AS}
|
|
|
|
{ID} {printf("ID: %s, Token: %d\n", yytext, ID );} // INCOMPLETE
|
|
|
|
{DIGIT}+ {printf("C_INTEGER: %s, Token: %d\n", yytext, atoi( yytext ) );}
|
|
"null" {printf("C_NULL: %s, Token: %d\n", yytext, atoi( yytext ) );}
|
|
'{CHAR}' {printf("C_CHARACTER: %s, Token: %d\n", yytext, atoi( yytext ) );}
|
|
"true" {printf("C_TRUE: %s, Token: %d\n", yytext, atoi( yytext ) );}
|
|
"false" {printf("C_FALSE: %s, Token: %d\n", yytext, atoi( yytext ) );}
|
|
\"{SCHAR}*\" {printf("C_STRING: %s, Token: %d\n", yytext, atoi( yytext ) );}
|
|
.|\n
|
|
|
|
%%
|
|
|
|
int main(int argc, char *argv[]){
|
|
argc--, argv++;
|
|
if ( argc > 0 )
|
|
yyin = fopen( argv[0], "r" );
|
|
else
|
|
yyin = stdin;
|
|
yylex();
|
|
}
|