Added comments, began work on ID
This commit is contained in:
8
Makefile
8
Makefile
@ -7,10 +7,16 @@ lexicalStructure:
|
|||||||
$(FLEX) $(LEX)
|
$(FLEX) $(LEX)
|
||||||
$(CC) lex.yy.c -o $(EXE)
|
$(CC) lex.yy.c -o $(EXE)
|
||||||
|
|
||||||
test:
|
test1:
|
||||||
./$(EXE) ./tests/test_constants_literals.txt
|
./$(EXE) ./tests/test_constants_literals.txt
|
||||||
|
|
||||||
|
test2:
|
||||||
./$(EXE) ./tests/test_keywards.alpha
|
./$(EXE) ./tests/test_keywards.alpha
|
||||||
|
|
||||||
|
test3:
|
||||||
./$(EXE) ./tests/test_types.alpha
|
./$(EXE) ./tests/test_types.alpha
|
||||||
|
|
||||||
|
test4:
|
||||||
./$(EXE) ./tests/test_variables.txt
|
./$(EXE) ./tests/test_variables.txt
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
@ -7,35 +7,42 @@
|
|||||||
%}
|
%}
|
||||||
|
|
||||||
DIGIT [0-9]
|
DIGIT [0-9]
|
||||||
CHAR \\\\n|\\\\t|\\\'|[^'\\\n\t]
|
CHAR \\n|\\t|\\'|[^'\n\t\\]
|
||||||
STRINGVAL CHAR | " "
|
SCHAR \\n|\\t|\\\"|[^\"\n\\]
|
||||||
|
COM ([^*]|\*+[^)*])*
|
||||||
|
|
||||||
|
/* INCOMPLETE */
|
||||||
|
ID [A-Za-z_][0-9A-Za-z_]*
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
{DIGIT}+ {printf( "C_INTEGER: %s (%d)\n", yytext, atoi( yytext ) );}
|
"(*"{COM}"*)" {printf("COMMENT: %s, Token: %d\n", yytext, COMMENT );} // {return COMMENT}
|
||||||
"null" {printf( "C_NULL: %s (%d)\n", yytext, atoi( yytext ) );}
|
|
||||||
'{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 ) );}
|
|
||||||
"{STRINGVAL}+" {printf( "C_STRING: %s (%d)\n", yytext, atoi( yytext ) );}
|
|
||||||
|
|
||||||
|
"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
|
.|\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}
|
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
|
@ -1,23 +1,50 @@
|
|||||||
This is a test
|
|
||||||
9combined 7okens
|
'''
|
||||||
12345
|
'\'
|
||||||
893247892
|
false
|
||||||
combined'DueToUnknownChar _validtoken __validtoken1 _valid_token2 validToken3_
|
'''
|
||||||
true false
|
nullfalse
|
||||||
null while !wrong if when
|
"nulltrue
|
||||||
else type function
|
null
|
||||||
return external as
|
'7'
|
||||||
string _NOte_that_was_not_reserved
|
true
|
||||||
([)]{}:;,->"\
|
'189
|
||||||
+-*/%
|
'\t'
|
||||||
<=
|
'"'
|
||||||
:=
|
'/'
|
||||||
"This is not a valid
|
'\n'
|
||||||
String"
|
'\''
|
||||||
"This is a valid String"
|
'\t'
|
||||||
!|
|
'\\'
|
||||||
..
|
'n'
|
||||||
(* this is a comment *)
|
'\'
|
||||||
(*Not a comment
|
'fdsf'
|
||||||
$^&
|
'
|
||||||
>
|
'
|
||||||
|
' '
|
||||||
|
'''
|
||||||
|
"STRINGwithnotSPaces"
|
||||||
|
' '
|
||||||
|
'\ '
|
||||||
|
|
||||||
|
"J"
|
||||||
|
""
|
||||||
|
" "
|
||||||
|
\"\"
|
||||||
|
"this is a string" 721398 'g' '/n'
|
||||||
|
12893 "this is not a string
|
||||||
|
"{SCHAR}"
|
||||||
|
"SCHAR"
|
||||||
|
"[SCHAR]"
|
||||||
|
"I'd think this is a legal \"string\" that contains \n \t several escaped characters, isn't it?"
|
||||||
|
"I'd think this is a legal \"string\" that contains several \\n \\t escaped characters, isn't it?"
|
||||||
|
|
||||||
|
(* hello *)
|
||||||
|
(* hello *)
|
||||||
|
(* I'd think this is a legal "string" that contains several \n \t
|
||||||
|
escaped characters, isn't it? *)
|
||||||
|
(* \ *)
|
||||||
|
(* *)
|
||||||
|
(*{COMMENT}+ *)
|
||||||
|
(* * *)
|
||||||
|
(* (hello) *)
|
@ -0,0 +1,10 @@
|
|||||||
|
valid1
|
||||||
|
Valid2
|
||||||
|
_valid3
|
||||||
|
_valid_name_4
|
||||||
|
VALID
|
||||||
|
0Invalid
|
||||||
|
1invalid
|
||||||
|
"invalid
|
||||||
|
invalid=
|
||||||
|
String
|
Reference in New Issue
Block a user