Merge pull request #10 from UB-CSE443/Sprint1-TokenizeID_MainFunction-FE-t#04
Merge #04
This commit is contained in:
@ -3,78 +3,70 @@
|
|||||||
/* definitions */
|
/* definitions */
|
||||||
|
|
||||||
%option noyywrap
|
%option noyywrap
|
||||||
|
|
||||||
%{
|
%{
|
||||||
#include "typedefs.h"
|
#include "typedefs.h"
|
||||||
|
int line_number = 1, column_number = 1;
|
||||||
%}
|
%}
|
||||||
int line_number = 1, column_number = 1;
|
|
||||||
|
|
||||||
|
COM ([^*]|\*+[^)*])*
|
||||||
|
ID [A-Za-z_][0-9A-Za-z_]*
|
||||||
DIGIT [0-9]
|
DIGIT [0-9]
|
||||||
CHAR \\n|\\t|\\'|[^'\n\t\\]
|
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 */
|
/* 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\\]
|
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 */
|
/* 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 */
|
||||||
STARTCOM \(\*
|
|
||||||
ENDCOM \*\)
|
%%
|
||||||
COMMENTCHAR [^\*]|\*[^\)]
|
|
||||||
/*Making the contents of a comment anything that is either not a * or not a * followed by ) to terminate comments at the first ENDCOM */
|
"integer" {return T_INTEGER;}
|
||||||
%%
|
"address" {return T_ADDRESS;}
|
||||||
|
"Boolean" {return T_BOOLEAN;}
|
||||||
|
"character" {return T_CHARACTER;}
|
||||||
\n line_number++ column_number = 1;
|
|
||||||
. column_number++;
|
{DIGIT}+ {return C_INTEGER;}
|
||||||
|
"null" {return C_NULL;}
|
||||||
"integer" {return T_INTEGER}
|
|
||||||
"address" {return T_ADDRESS}
|
"while" {return WHILE;}
|
||||||
"Boolean" {return T_BOOLEAN}
|
"if" {return IF;}
|
||||||
"character" {return T_CHARACTER}
|
"then" {return THEN;}
|
||||||
|
"else" {return ELSE;}
|
||||||
|
"type" {return TYPE;}
|
||||||
/* rules */
|
"function" {return FUNCTION;}
|
||||||
{DIGIT}+ {printf( "C_INTEGER: %s (%d)\n", yytext, atoi( yytext ) );}
|
"return" {return RETURN;}
|
||||||
|
"external" {return EXTERNAL;}
|
||||||
"null" {printf( "C_NULL: %s (%d)\n", yytext, atoi( yytext ) );}
|
"as" {return AS;}
|
||||||
|
|
||||||
"while" {return WHILE}
|
'{CHAR}' {return C_CHARACTER;}
|
||||||
"if" {return IF}
|
"true" {return C_TRUE;}
|
||||||
"then" {return THEN}
|
"false" {return C_FALSE;}
|
||||||
"else" {return ELSE}
|
|
||||||
"type" {return TYPE}
|
"+" {return ADD;}
|
||||||
"function" {return FUNCTION}
|
"-" {return SUB_OR_NEG;}
|
||||||
"return" {return RETURN}
|
"*" {return MUL;}
|
||||||
"external" {return EXTERNAL}
|
"/" {return DIV;}
|
||||||
"as" {return AS}
|
"%" {return REM;}
|
||||||
|
"<" {return LESS_THAN;}
|
||||||
'{CHAR}' {printf( "C_CHARACTER: %s (%d)\n", yytext, atoi( yytext ) );} /*using double \ per documentation to show escaped chars*/
|
"=" {return EQUAL_TO;}
|
||||||
|
":=" {return ASSIGN;}
|
||||||
"true" {printf( "C_TRUE: %s (%d)\n", yytext, atoi( yytext ) );}
|
"!" {return NOT;}
|
||||||
|
"&" {return AND;}
|
||||||
|
"|" {return OR;}
|
||||||
"false" {printf( "C_FALSE: %s (%d)\n", yytext, atoi( yytext ) );}
|
"." {return DOT;}
|
||||||
|
|
||||||
/* OPERATORS */
|
";" {return SEMI_COLON;}
|
||||||
|
":" {return COLON;}
|
||||||
"+" {return ADD;}
|
"," {return COMMA;}
|
||||||
"-" {return SUB_OR_NEG;}
|
"->" {return ARROW;}
|
||||||
"*" {return MUL;}
|
|
||||||
"/" {return DIV;}
|
"reserve" {return RESERVE;}
|
||||||
"%" {return REM;}
|
"release" {return RELEASE;}
|
||||||
"<" {return LESS_THAN;}
|
|
||||||
"=" {return EQUAL_TO;}
|
\"{SCHAR}*\" {return C_STRING;}
|
||||||
":=" {return ASSIGN;}
|
"(*"{COM}"*)" {return COMMENT;}
|
||||||
"!" {return NOT;}
|
|
||||||
"&" {return AND;}
|
{ID} {return ID;}
|
||||||
"|" {return OR;}
|
|
||||||
"." {return DOT;}
|
\n {line_number++; column_number = 1;}
|
||||||
"reserve" {return RESERVE;}
|
. {column_number++;}
|
||||||
"release" {return RELEASE;}
|
|
||||||
|
|
||||||
|
|
||||||
\"{SCHAR}*\" {printf( "C_STRING: %s (%d)\n", yytext, atoi( yytext ) );}
|
|
||||||
|
|
||||||
\(\*{COMMENTCHAR}*\*\) {printf( "COMMENT: %s (%d)\n", yytext, atoi( yytext ) );}
|
|
||||||
|
|
||||||
.|\n
|
|
||||||
|
|
||||||
|
|
||||||
%%
|
%%
|
9
tests/test_comments.alpha
Normal file
9
tests/test_comments.alpha
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
(* hello *)
|
||||||
|
(* hello *)
|
||||||
|
(* I'd think this is a legal "string" that contains several \n \t
|
||||||
|
escaped characters, isn't it? *)
|
||||||
|
(* \ *)
|
||||||
|
(* *)
|
||||||
|
(*{COMMENT}+ *)
|
||||||
|
(* * *)
|
||||||
|
(* (hello) *)
|
6
tests/test_otherpunc.alpha
Normal file
6
tests/test_otherpunc.alpha
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
;
|
||||||
|
:
|
||||||
|
,
|
||||||
|
->
|
||||||
|
->>
|
||||||
|
-->
|
@ -1,10 +0,0 @@
|
|||||||
integer
|
|
||||||
Integer
|
|
||||||
address
|
|
||||||
Address
|
|
||||||
Boolean
|
|
||||||
boolean
|
|
||||||
character
|
|
||||||
Character
|
|
||||||
string
|
|
||||||
String
|
|
10
tests/test_variables.alpha
Normal file
10
tests/test_variables.alpha
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
valid1
|
||||||
|
Valid2
|
||||||
|
_valid3
|
||||||
|
_valid_name_4
|
||||||
|
VALID
|
||||||
|
0Invalid
|
||||||
|
1invalid
|
||||||
|
"invalid
|
||||||
|
invalid=
|
||||||
|
String
|
Reference in New Issue
Block a user