summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.org25
-rw-r--r--src/frontend/lexer.l13
-rw-r--r--src/frontend/parser.y9
-rwxr-xr-xull4
4 files changed, 34 insertions, 17 deletions
diff --git a/README.org b/README.org
index 16f12c1..0604e2a 100644
--- a/README.org
+++ b/README.org
@@ -1,18 +1,23 @@
+* Run Instructions
+
+The =manifest.scm= file provides the ideal build environment automatically to Guix users. flex, pkg-config, bison, make, and gcc are required to compile the frontend into a shared object file with =make all=, and guile is required to run the =ull= script.
+
+Running the ./ull script will print allowed arguments, which follows the interface prescribed by the book //Writing a C Compiler// by Nora Sandler.
+
* General
-This compiler was made following the general guidelines provided in /Writing a C Compiler/ by Nora Sandler.
-It is written from scratch solely using tools distributed with Guile.
+This compiler was made following the general guidelines provided in //Writing a C Compiler// by Nora Sandler.
+
+Since this a functional-programing/guile learning project, I utilized flex and bison to allow use of the Guile/C interface. Development takes a functionality-first approach---memory leaks and other undesired behavior likely.
* Feature Agenda
-** TODO Important
+** Current Issues
-- [ ] Reasonable parser error messages
-- [X] Rewrite deprecated temporary file generation method
-- [X] Cleanup temp files after process end
+- [ ] Memleak related to driver.c, haven't figured out how to test this yet
- [ ] More parenthesis
-** TODO Features [2/19]
+** TODO Major Features [2/19]
- [X] Trivial Programs
- [X] Unary Operators
@@ -34,3 +39,9 @@ It is written from scratch solely using tools distributed with Guile.
- [ ] Dynamic Memory Allocation
- [ ] Structures
- [ ] A Multitude Of Optimizations
+
+** Fixed
+
+- [X] Reasonable parser error messages
+- [X] Rewrite deprecated temporary file generation method
+- [X] Cleanup temp files after process end
diff --git a/src/frontend/lexer.l b/src/frontend/lexer.l
index 5b72086..40f6196 100644
--- a/src/frontend/lexer.l
+++ b/src/frontend/lexer.l
@@ -9,7 +9,8 @@
%option yylineno
DIGIT [0-9]
-ALPHA [[:alpha:]_]
+PREID [a-zA-Z_]
+PSTID [a-zA-Z0-9_]
/*** rules section ***/
%%
@@ -30,12 +31,18 @@ ALPHA [[:alpha:]_]
"void" {return VOID;}
"return" {return RET;}
-{DIGIT}+ {yylval.ival = atol(yytext); return NUMBER;}
-{ALPHA}+ {
+{PREID}{PSTID}* {
yylval.sval = strdup(yytext);
return WORD;
}
+{DIGIT}+ {yylval.ival = atol(yytext); return NUMBER;}
+
+{PSTID}+ {
+ printf("Error at line %d: invalid identifier \"%s\"\n", yylineno, yytext);
+ return YYerror;
+}
+
[[:space:]]+ {/* discard */}
. {
printf("Error at line %d: unrecognized symbol \"%s\"\n", yylineno, yytext);
diff --git a/src/frontend/parser.y b/src/frontend/parser.y
index aa58f64..bd5d127 100644
--- a/src/frontend/parser.y
+++ b/src/frontend/parser.y
@@ -66,10 +66,6 @@ exp: term {
add_child($$, $1);
add_child($$, $3);
}
-| un_op exp {
- $$ = create_expr($1);
- add_child($$, $2);
- }
;
term: factor {
@@ -90,6 +86,10 @@ term: factor {
add_child($$, $1);
add_child($$, $3);
}
+| un_op exp {
+ $$ = create_expr($1);
+ add_child($$, $2);
+ }
;
factor: NUMBER {
@@ -113,4 +113,3 @@ un_op: COMP {
void yyerror(Node **root, const char *msg) {
printf("** Line %d: %s\n", yylineno, msg);
}
-
diff --git a/ull b/ull
index 004d7e5..a6e6c28 100755
--- a/ull
+++ b/ull
@@ -120,8 +120,8 @@ Returns #f on a failure, #t on a success."
;; call the backend
(begin (display "Parser reported success\n")
(let ((program (backend c-ast tack? generate? write?)))
- (when write?
+ (when (and write? (not tack?) (not generate?))
(write program assembly-file-name)
;; call postprocessing
(postprocess assembly-file-name executable-file-name))))
- (display "Tokenizer successful. "))))))))
+ (display "Tokenizer reported success\n"))))))))