Merge #04
This commit is contained in:
scarlett
2025-02-12 12:57:29 -05:00
committed by GitHub
5 changed files with 84 additions and 77 deletions

View File

@ -3,56 +3,42 @@
/* 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; {DIGIT}+ {return C_INTEGER;}
. column_number++; "null" {return C_NULL;}
"integer" {return T_INTEGER} "while" {return WHILE;}
"address" {return T_ADDRESS} "if" {return IF;}
"Boolean" {return T_BOOLEAN} "then" {return THEN;}
"character" {return T_CHARACTER} "else" {return ELSE;}
"type" {return TYPE;}
"function" {return FUNCTION;}
"return" {return RETURN;}
"external" {return EXTERNAL;}
"as" {return AS;}
'{CHAR}' {return C_CHARACTER;}
/* rules */ "true" {return C_TRUE;}
{DIGIT}+ {printf( "C_INTEGER: %s (%d)\n", yytext, atoi( yytext ) );} "false" {return C_FALSE;}
"null" {printf( "C_NULL: %s (%d)\n", yytext, atoi( yytext ) );}
"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}' {printf( "C_CHARACTER: %s (%d)\n", yytext, atoi( yytext ) );} /*using double \ per documentation to show escaped chars*/
"true" {printf( "C_TRUE: %s (%d)\n", yytext, atoi( yytext ) );}
"false" {printf( "C_FALSE: %s (%d)\n", yytext, atoi( yytext ) );}
/* OPERATORS */
"+" {return ADD;} "+" {return ADD;}
"-" {return SUB_OR_NEG;} "-" {return SUB_OR_NEG;}
@ -66,15 +52,21 @@ COMMENTCHAR [^\*]|\*[^\)]
"&" {return AND;} "&" {return AND;}
"|" {return OR;} "|" {return OR;}
"." {return DOT;} "." {return DOT;}
";" {return SEMI_COLON;}
":" {return COLON;}
"," {return COMMA;}
"->" {return ARROW;}
"reserve" {return RESERVE;} "reserve" {return RESERVE;}
"release" {return RELEASE;} "release" {return RELEASE;}
\"{SCHAR}*\" {return C_STRING;}
"(*"{COM}"*)" {return COMMENT;}
\"{SCHAR}*\" {printf( "C_STRING: %s (%d)\n", yytext, atoi( yytext ) );} {ID} {return ID;}
\(\*{COMMENTCHAR}*\*\) {printf( "COMMENT: %s (%d)\n", yytext, atoi( yytext ) );}
.|\n
\n {line_number++; column_number = 1;}
. {column_number++;}
%% %%

View 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) *)

View File

@ -0,0 +1,6 @@
;
:
,
->
->>
-->

View File

@ -1,10 +0,0 @@
integer
Integer
address
Address
Boolean
boolean
character
Character
string
String

View File

@ -0,0 +1,10 @@
valid1
Valid2
_valid3
_valid_name_4
VALID
0Invalid
1invalid
"invalid
invalid=
String