Author: kjs
Date: Mon Apr 9 03:50:40 2007
New Revision: 18059
Modified:
trunk/compilers/pirc/src/jsonout.c
trunk/compilers/pirc/src/pirlexer.c
Log:
compilers/pirc:
* add some comments to jsonout.c
* fix bug in lexer: now numbers are parsed correctly.
Modified: trunk/compilers/pirc/src/jsonout.c
==============================================================================
--- trunk/compilers/pirc/src/jsonout.c (original)
+++ trunk/compilers/pirc/src/jsonout.c Mon Apr 9 03:50:40 2007
@@ -21,6 +21,22 @@
#define dedent(D) D->indent -= INDENT
+/*
+
+=head1 JSON BACK END INTERNALS
+
+
+
+=cut
+
+
+Structure target holds names of C<target>s so they can be emitted later.
+This is necessary in cases like: "(a,b,c) = foo(1,2,3)", where a, b and c
+are targets. This might prove not to be necessary later, as I haven't thought
+out this back-end completely. It's a bit of trial and error, how to fill in
+the vtable methods efficiently.
+
+*/
typedef struct target {
char *name;
struct target *next;
@@ -32,14 +48,26 @@
*
*/
typedef struct emit_data {
- FILE *outfile;
- int indent;
+ FILE *outfile; /* output file */
+ int indent; /* keep track of indention */
+ /* has the first item in a list already been emitted? If so, we need a
comma as separator */
int need_comma;
- struct target *targets;
+ struct target *targets; /* list of targets for temp. storage */
} emit_data;
-/* helper methods */
+
+/*
+
+=head1 HELPER METHODS
+
+
+=cut
+
+*/
+
+
+
target *
new_target(char *name) {
target *t = (target *)malloc(sizeof(target));
@@ -54,7 +82,13 @@
data->targets = t;
}
-/* Implementation of methods */
+/*
+
+=head1 VTABLE METHODS
+
+=cut
+
+*/
static void
json_init(emit_data *data) {
Modified: trunk/compilers/pirc/src/pirlexer.c
==============================================================================
--- trunk/compilers/pirc/src/pirlexer.c (original)
+++ trunk/compilers/pirc/src/pirlexer.c Mon Apr 9 03:50:40 2007
@@ -543,6 +543,7 @@
*/
static void
print_buffer(lexer_state *lexer) {
+ fprintf(stderr, "token buffer: [%s]\n", lexer->token_chars);
fprintf(stderr, "Rest of buffer of file '%s'\n", lexer->curfile->filename);
fprintf(stderr, "[%s]", lexer->curfile->curchar);
}
@@ -1186,6 +1187,8 @@
=cut
*/
+
+
if (isalpha(c) || c == '_' ) { /* check for identifier, op, invocant
or label */
do {
buffer_char(lexer, c);
@@ -1255,23 +1258,16 @@
buffer_char(lexer, c);
c = read_char(lexer->curfile);
- if (isdigit(c)) { /* integer or float */
- do {
- buffer_char(lexer, c);
- c = read_char(lexer->curfile);
- }
- while (isdigit(c));
+ while (isdigit(c)) {
+ buffer_char(lexer, c);
+ c = read_char(lexer->curfile);
+ }
- /* it is a different char, either '.', ' ' or something else */
- if (c == '.') { /* floating point number */
- buffer_char(lexer, c);
- read_digits(lexer);
- return T_NUMBER_CONSTANT;
- }
- else {
- unread_char(lexer->curfile); /* put back last read char. */
- return T_INTEGER_CONSTANT;
- }
+ /* it is a different char, either '.', ' ' or something else */
+ if (c == '.') { /* floating point number */
+ buffer_char(lexer, c);
+ read_digits(lexer);
+ return T_NUMBER_CONSTANT;
}
else if (c == 'b' || c == 'B') { /* 0b<digit>+ or 0B<digit>+ */
buffer_char(lexer, c);