first batch of keywords and symbols

This commit is contained in:
Felix Müller 2024-04-15 20:36:13 +02:00
parent 73bfbd15f9
commit 46de25f8ce
3 changed files with 152 additions and 2 deletions

View File

@ -6,6 +6,63 @@
int yylex(); int yylex();
%} %}
/*543fgrsdffsd*/
%% %%
"\n" yyLineNumber++;
":" return(':');
"=" return('=');
"|" return('|');
"!" return('!');
"+" return('+');
"-" return('-');
"*" return('*');
"/" return('/');
"(" return('(');
")" return(')');
"[" return('[');
"]" return(']');
"{" return('{');
"}" return('}');
">" return('>');
"<" return('<');
"int" return(KeyInt);
"float" return(KeyFloat);
"as" return (KeyAs);
"short" return(KeyShort);
"long" return(KeyLong);
"half" return(KeyHalf);
"double" return(KeyDouble);
"signed" return(KeySigned);
"unsigned" return(Keyunsigned);
"ref" return(KeyRef);
"type" return(KeyType);
"local" return(KeyLocal);
"global" return(KeyGlobal);
"static" return(KeyStatic);
"if" return(KeyIf);
"else" return(KeyElse);
"while" return(KeyWhile);
[a-zA-Z_]+ { yylval.string = strdup(yytext); return(Ident); };
[0-9]+ { yylval.num = atoi(yytext); return(ValInt); };
.; .;
%% %%

View File

@ -1,6 +1,13 @@
#include <yacc/parser.tab.h> #include <yacc/parser.tab.h>
#include <stdio.h>
extern FILE* yyin;
int main() { int main() {
FILE* input = fopen("program.gem", "r");
yyin = input;
yyparse(); yyparse();
return 0; return 0;
} }

View File

@ -1,15 +1,101 @@
%{ %{
#include <stdio.h>
extern int yylineno; extern int yylineno;
int yyerror(char*); int yyerror(char*);
extern int yylex(); extern int yylex();
int array[256];
%} %}
%union {
char *string;
int num;
}
%token KeyInt
%token KeyFloat
%token KeyAs
%token <num> ValInt
%token <string> Ident
%token KeyShort
%token KeyLong
%token KeyHalf
%token KeyDouble
%token KeySigned
%token Keyunsigned
%token KeyRef
%token KeyType
%token KeyLocal
%token KeyGlobal
%token KeyStatic
%token KeyIf
%token KeyElse
%token KeyWhile
%% %%
program: ; program: decllist;
decllist: decl
| decllist decl;
decl: '=' {printf("=\n"); };
| ':' {printf(":\n"); };
| '|' {printf("|\n"); };
| '(' {printf("(\n"); };
| ')' {printf(")\n"); };
| '[' {printf("[\n"); };
| ']' {printf("]\n"); };
| '{' {printf("{\n"); };
| '}' {printf("}\n"); };
| '!' {printf("!\n"); };
| '+' {printf("+\n"); };
| '-' {printf("-\n"); };
| '*' {printf("*\n"); };
| '/' {printf("/\n"); };
| Ident {printf("Ident\n"); };
| ValInt {printf("ValInt\n"); };
| KeyInt {printf("KeyInt\n"); };
| KeyFloat {printf("KeyFloat\n"); };
| KeyAs {printf("KeyAs\n"); };
| KeyShort {printf("KeyShort\n"); };
| KeyLong {printf("KeyLong\n"); };
| KeyHalf {printf("KeyHalf\n"); };
| KeyDouble {printf("KeyDouble\n"); };
| KeySigned {printf("KeySigned\n"); };
| Keyunsigned {printf("Keyunsigned\n"); };
| KeyRef {printf("KeyRef\n"); };
| KeyType {printf("KeyType\n"); };
| KeyLocal {printf("KeyLocal\n"); };
| KeyGlobal {printf("KeyGlobal\n"); };
| KeyStatic {printf("KeyStatic\n"); };
| KeyIf {printf("KeyIf\n"); };
| KeyElse {printf("KeyElse\n"); };
| KeyWhile {printf("KeyWhile\n"); };
%% %%
int yyerror(char *s) { int yyerror(char *s) {
return 0; return 0;
} }