Added the keywards and types t#01

This commit is contained in:
Meyer Simon
2025-02-07 14:34:37 -05:00
parent bfe8cc35dd
commit 78c743736c
6 changed files with 1943 additions and 5 deletions

1870
lex.yy.c Normal file

File diff suppressed because it is too large Load Diff

BIN
lexer Executable file

Binary file not shown.

BIN
lexicalStructure Executable file

Binary file not shown.

View File

@ -2,11 +2,40 @@
/* so we placed the citation here. */
/* definitions */
%option noyywrap
%{
#include <typedefs.h>
%}
%{
#include "typedefs.h"
%}
%%
//rules
.|\n
"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}
/* KEYWARDS */
"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}
%%
//user code
int main(int argc, char *argv[]){
argc--, argv++;
if ( argc > 0 )
yyin = fopen( argv[0], "r" );
else
yyin = stdin;
yylex();
}

29
tests/test_keywards.alpha Normal file
View File

@ -0,0 +1,29 @@
while
While
whiLe
if
IF
If
iF
then
Then
theN
else
eLse
elSe
Else
type
Type
tyPe
function
Function
functioN
return
Return
returN
external
External
exteRnal
as
As
aS

10
tests/test_types.alpha Normal file
View File

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