summaryrefslogtreecommitdiffstats
path: root/parser.h
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2016-10-18 05:42:58 -0700
committerKaz Kylheku <kaz@kylheku.com>2016-10-18 05:42:58 -0700
commit37636d9b1ceae173635d18043e21f446dfbd2490 (patch)
tree87bb18340363df6aa405aa7e8dea45b3229239ec /parser.h
parentf91ef728d1149d7a849d7c818b3fdc03c61847ad (diff)
downloadtxr-37636d9b1ceae173635d18043e21f446dfbd2490.tar.gz
txr-37636d9b1ceae173635d18043e21f446dfbd2490.tar.bz2
txr-37636d9b1ceae173635d18043e21f446dfbd2490.zip
Adding notation for cycles and shared structure.
This commit implements the parse-side support for handling a notation that exists in ANSI Common Lisp for specifying objects with cycles and shared substructure. * parser.h (struct parser): New members, circ_ref_hash and circ_count. (circref_s, parser_resolve_circ, parser_circ_def, parser_circ_ref): Declared. * parser.c (circref_s): New symbol variable. (parser_mark): Visit the new circ_ref_hash member of the parser structure. (parser_common_init): Initialize new members circ_ref_hash and circ_count of parser structure. (patch_ref, circ_backpatch): New static functions. (parser_resolve_circ, parser_circ_def, parser_circ_ref): New functions. (circref): New static function. (parse_init): Initialize circref_s as sys:circref symbol. Register sys:circref function. * parser.l (grammar): Scan #<num>= and #<num># notation as tokens, extracting their numeric value. * parser.y (HASH_N_EQUALS, HASH_N_HASH): New token types. (i_expr, n_expr): Adding phrases for hash-equalsign and hash-hash syntax. (yybadtoken): Handle new token types in switch. (parse_once): Call parser_resolve_circ after parsing to rewrite any remaining #<num># references in the structure to the objects they denote. (parse): Reset new struct parse members to initial state. Call parser_resolve_circ after parsing to rewrite any remaining #<num># references.
Diffstat (limited to 'parser.h')
-rw-r--r--parser.h10
1 files changed, 7 insertions, 3 deletions
diff --git a/parser.h b/parser.h
index e7bc8c6d..a12d45ee 100644
--- a/parser.h
+++ b/parser.h
@@ -54,6 +54,8 @@ struct parser {
val name;
val prepared_msg;
val syntax_tree;
+ val circ_ref_hash;
+ cnum circ_count;
scanner_t *scanner;
struct yy_token recent_tok;
struct yy_token tok_pushback[4];
@@ -66,8 +68,7 @@ enum prime_parser { prime_lisp, prime_interactive, prime_regex };
extern const int have_yydebug;
extern const wchar_t *spec_file;
extern val form_to_ln_hash;
-extern val parser_s;
-extern val unique_s;
+extern val parser_s, unique_s, circref_s;
void yydebug_onoff(int);
void yyerror(scanner_t *scanner, parser_t *, const char *s);
void yyerr(scanner_t *scanner, const char *s);
@@ -87,10 +88,13 @@ void parser_l_init(void);
void open_txr_file(val spec_file, val *txr_lisp_p, val *name, val *stream);
void prime_parser(parser_t *, val name, enum prime_parser);
void prime_parser_post(parser_t *, enum prime_parser);
-void prime_scanner(scanner_t *, enum prime_parser);
#ifdef SPACE
int parser_callgraph_circ_check(struct circ_stack *rs, val obj);
#endif
+void prime_scanner(scanner_t *, enum prime_parser);
+void parser_resolve_circ(parser_t *);
+void parser_circ_def(parser_t *, val num, val expr);
+val parser_circ_ref(parser_t *, val num);
void scrub_scanner(scanner_t *, int yy_char, wchar_t *lexeme);
int parse_once(val stream, val name, parser_t *parser);
int parse(parser_t *parser, val name, enum prime_parser);