Skip to content

Commit 5e41f74

Browse files
committed
initial compiler
1 parent 7bfeb52 commit 5e41f74

File tree

9 files changed

+3693
-0
lines changed

9 files changed

+3693
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.output
2+
*.o

exec.sh

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
cd JavaTownCompiler
2+
rm out/javat
3+
bison -dv javat.y
4+
flex -l javat.l
5+
gcc -o out/javat javat.tab.c lex.yy.c

javat.l

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
%option noyywrap
2+
3+
%{
4+
#include <stdio.h>
5+
#define YY_DECL int yylex()
6+
#include "javat.tab.h"
7+
%}
8+
9+
%%
10+
[ \t] ; // ignore all space
11+
"public" { return PUBLIC; }
12+
"private" { return PRIVATE; }
13+
"class" { return CLASS; }
14+
[A-Za-z_] { yylval.string = strdup(yytext); return LETTER; }
15+
[A-Za-z_]+[A-Za-z0-9_$]* { yylval.string = strdup(yytext); return WORD; }
16+
[0-9]+\.[0-9]+ { yylval.floating = atof(yytext); return FLOAT; }
17+
[0-9]+[A-Za-z_]+[A-Za-z0-9_$]* { return DISALLOWED_INDENTIFIER; }
18+
[0-9]+ { yylval.number = atoi(yytext); return INT; }
19+
";" { return SEMICOLON; }
20+
"+" { return ADD; }
21+
"-" { return SUBT; }
22+
"*" { return MULT; }
23+
"/" { return DIV; }
24+
"(" { return LPAR; }
25+
")" { return RPAR; }
26+
"{" { return LBRACE; }
27+
"}" { return RBRACE; }
28+
\""" { return QUOTE; }
29+
"=" { return EQUALS; }
30+
"\n" { return NEW; }
31+
%%

0 commit comments

Comments
 (0)