Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/fgen Some bugfixes and enhancements. Support for ca...
details: https://anonhg.NetBSD.org/src/rev/892d1ad92932
branches: trunk
changeset: 751917:892d1ad92932
user: eeh <eeh%NetBSD.org@localhost>
date: Mon Feb 08 20:14:55 2010 +0000
description:
Some bugfixes and enhancements. Support for case .. of and fix calculation
of branch offsets.
diffstat:
usr.bin/fgen/fgen.h | 15 +-
usr.bin/fgen/fgen.l | 470 +++++++++++++++++++++++++++++++++------------------
2 files changed, 311 insertions(+), 174 deletions(-)
diffs (truncated from 1035 to 300 lines):
diff -r bdd1f5a693b4 -r 892d1ad92932 usr.bin/fgen/fgen.h
--- a/usr.bin/fgen/fgen.h Mon Feb 08 19:11:18 2010 +0000
+++ b/usr.bin/fgen/fgen.h Mon Feb 08 20:14:55 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fgen.h,v 1.8 2009/10/19 18:12:37 snj Exp $ */
+/* $NetBSD: fgen.h,v 1.9 2010/02/08 20:14:55 eeh Exp $ */
/*
* fgen.h -- stuff for the fcode tokenizer.
*
@@ -38,8 +38,8 @@
#define TOKEN struct tok
#define YY_DECL TOKEN* yylex(void)
-#define FCODE 0xF00DBABE
-#define MACRO 0xFEEDBABE
+#define FCODE 0x000FC0DE
+#define MACRO 0x0000F00D
/* Defined fcode and string. */
struct fcode {
@@ -82,12 +82,12 @@
TOK_PSTRING,
TOK_TOKENIZE,
TOK_COMMENT,
- TOK_ENDCOMMENT,
TOK_COLON,
TOK_SEMICOLON,
TOK_TOSTRING,
/* These are special */
+ TOK_ABORT_S,
TOK_AGAIN,
TOK_ALIAS,
TOK_GETTOKEN,
@@ -101,9 +101,12 @@
TOK_DEFER,
TOK_DO,
TOK_ELSE,
+ TOK_END0,
TOK_ENDCASE,
TOK_ENDOF,
TOK_EXTERNAL,
+ TOK_FCODE_VERSION2,
+ TOK_FCODE_END,
TOK_FIELD,
TOK_HEADERLESS,
TOK_HEADERS,
@@ -111,14 +114,16 @@
TOK_LEAVE,
TOK_LOOP,
TOK_OF,
+ TOK_OFFSET16,
TOK_REPEAT,
+ TOK_STARTX,
TOK_THEN,
TOK_TO,
TOK_UNTIL,
TOK_VALUE,
TOK_VARIABLE,
+ TOK_VERSION1,
TOK_WHILE,
- TOK_OFFSET16,
/* Tokenizer directives */
TOK_BEGTOK,
diff -r bdd1f5a693b4 -r 892d1ad92932 usr.bin/fgen/fgen.l
--- a/usr.bin/fgen/fgen.l Mon Feb 08 19:11:18 2010 +0000
+++ b/usr.bin/fgen/fgen.l Mon Feb 08 20:14:55 2010 +0000
@@ -1,5 +1,5 @@
%{
-/* $NetBSD: fgen.l,v 1.33 2009/10/29 14:49:03 christos Exp $ */
+/* $NetBSD: fgen.l,v 1.34 2010/02/08 20:14:55 eeh Exp $ */
/* FLEX input for FORTH input file scanner */
/*
* Copyright (c) 1998 Eduardo Horvath.
@@ -42,16 +42,15 @@
#endif
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: fgen.l,v 1.33 2009/10/29 14:49:03 christos Exp $");
+__RCSID("$NetBSD: fgen.l,v 1.34 2010/02/08 20:14:55 eeh Exp $");
#endif
%}
-%option yylineno noinput
+%option yylineno
-decimal [0-9.]
-hex [0-9A-Fa-f.]
-octal [0-7.]
+hex [0-9A-Fa-f]
+hexdot [0-9A-Fa-f.]
white [ \t\n\r\f]
tail {white}
@@ -90,6 +89,7 @@
int offsetsize = 8;
int defining = 0;
int tokenizer = 0;
+int need_end0 = 1;
#define PSTKSIZ 1024
Cell parse_stack[PSTKSIZ];
@@ -101,7 +101,8 @@
int debug = 0;
#define ASSERT if (debug) assert
-#define STATE(y, x) do { if (debug) printf( "%ld State %s: token `%s'\n", outpos, x, y); } while (0)
+#define STATE(y, x) do { if (debug) printf( "%lx State %s: token `%s'\n", outpos, x, y); } while (0)
+int mark_fload = 0;
%}
@@ -125,7 +126,7 @@
\\[^\n]*\n /* end of line comment -- keep looping */ { STATE(yytext, "EOL comment"); }
--?{hex}+ { ltoken.type = TOK_NUMBER; ltoken.text = yytext;
+-?{hex}{hexdot}* { ltoken.type = TOK_NUMBER; ltoken.text = yytext;
return <oken; }
\'.\' { ltoken.type = TOK_C_LIT; ltoken.text = yytext; return <oken; }
@@ -139,12 +140,12 @@
\.\"{white}*(\\\"|[^"])*\" { ltoken.type = TOK_PSTRING; ltoken.text = yytext;
return <oken; }
+[aA][bB][oO][rR][tT]\"{white}*(\\\"|[^"])*\" { ltoken.type = TOK_ABORT_S;
+ ltoken.text = yytext; return <oken; }
+
"(" { ltoken.type = TOK_COMMENT; ltoken.text = yytext;
return <oken; }
-")" { ltoken.type = TOK_ENDCOMMENT; ltoken.text = yytext;
- return <oken; }
-
":" { ltoken.type = TOK_COLON; ltoken.text = yytext;
return <oken; }
@@ -199,6 +200,9 @@
[eE][lL][sS][eE] { ltoken.type = TOK_ELSE; ltoken.text = yytext;
return <oken; }
+[eE][nN][dD]0 { ltoken.type = TOK_END0; ltoken.text = yytext;
+ return <oken; }
+
[eE][nN][dD][cC][aA][sS][eE] { ltoken.type = TOK_ENDCASE; ltoken.text = yytext;
return <oken; }
@@ -208,6 +212,13 @@
[eE][xX][tT][eE][rR][nN][aA][lL] { ltoken.type = TOK_EXTERNAL; ltoken.text = yytext;
return <oken; }
+[fF][cC][oO][dD][eE]-[vV][eE][rR][sS][iI][oO][nN]2 {
+ ltoken.type = TOK_FCODE_VERSION2; ltoken.text = yytext;
+ return <oken; }
+
+[fF][cC][oO][dD][eE]-[eE][nN][dD] { ltoken.type = TOK_FCODE_END; ltoken.text = yytext;
+ return <oken; }
+
[fF][iI][eE][lL][dD] { ltoken.type = TOK_FIELD; ltoken.text = yytext;
return <oken; }
@@ -241,9 +252,15 @@
[oO][fF] { ltoken.type = TOK_OF; ltoken.text = yytext;
return <oken; }
+[oO][fF][fF][sS][eE][tT]16 { ltoken.type = TOK_OFFSET16; ltoken.text = yytext;
+ return <oken; }
+
[rR][eE][pP][eE][aA][tT] { ltoken.type = TOK_REPEAT; ltoken.text = yytext;
return <oken; }
+[sS][tT][aA][rR][tT][0124] { ltoken.type = TOK_STARTX; ltoken.text = yytext;
+ return <oken; }
+
[tT][hH][eE][nN] { ltoken.type = TOK_THEN; ltoken.text = yytext;
return <oken; }
@@ -259,10 +276,10 @@
[vV][aA][rR][iI][aA][bB][lL][eE] { ltoken.type = TOK_VARIABLE; ltoken.text = yytext;
return <oken; }
-[wW][hH][iI][lL][eE] { ltoken.type = TOK_WHILE; ltoken.text = yytext;
+[vV][eE][rR][sS][iI][oO][nN]1 { ltoken.type = TOK_VERSION1; ltoken.text = yytext;
return <oken; }
-offset16 { ltoken.type = TOK_OFFSET16; ltoken.text = yytext;
+[wW][hH][iI][lL][eE] { ltoken.type = TOK_WHILE; ltoken.text = yytext;
return <oken; }
tokenizer\[ { ltoken.type = TOK_BEGTOK; ltoken.text = yytext;
@@ -274,7 +291,7 @@
\]tokenizer { ltoken.type = TOK_ENDTOK; ltoken.text = yytext;
return <oken; }
-fload { ltoken.type = TOK_FLOAD; ltoken.text = yytext;
+[fF][lL][oO][aA][dD] { ltoken.type = TOK_FLOAD; ltoken.text = yytext;
return <oken; }
@@ -297,6 +314,7 @@
void tokenize(YY_BUFFER_STATE);
int emit(const char *);
int spit(long);
+int offspit(long);
void sspit(const char *);
int apply_macros(YY_BUFFER_STATE, const char *);
int main(int argc, char *argv[]);
@@ -501,7 +519,7 @@
{ "c,", 0x00d0, 0, NULL, NULL },
{ "w,", 0x00d1, 0, NULL, NULL },
{ "l,", 0x00d2, 0, NULL, NULL },
- { "'", 0x00d3, 0, NULL, NULL },
+ { ",", 0x00d3, 0, NULL, NULL },
{ "um*", 0x00d4, 0, NULL, NULL },
{ "um/mod", 0x00d5, 0, NULL, NULL },
{ "d+", 0x00d8, 0, NULL, NULL },
@@ -549,7 +567,7 @@
{ "mask", 0x0124, 0, NULL, NULL },
{ "get-msecs", 0x0125, 0, NULL, NULL },
{ "ms", 0x0126, 0, NULL, NULL },
- { "find-device", 0x0127, 0, NULL, NULL },
+ { "finish-device", 0x0127, 0, NULL, NULL },
{ "decode-phys", 0x0128, 0, NULL, NULL },
{ "map-low", 0x0130, 0, NULL, NULL },
{ "sbus-intr>cpu", 0x0131, 0, NULL, NULL },
@@ -699,15 +717,15 @@
{ "blank", "bl fill", 0, NULL, NULL },
{ "/c*", "chars", 0, NULL, NULL },
{ "ca1+", "char+", 0, NULL, NULL },
- { "carret", "b(lit) 00 00 00 0x0d", 0, NULL, NULL },
- { ".d", "base @ swap 0x0a base ! . base !", 0, NULL, NULL },
+ { "carret", "b(lit) 00 00 00 h# 0d", 0, NULL, NULL },
+ { ".d", "base @ swap d# 0a base ! . base !", 0, NULL, NULL },
{ "decode-bytes", ">r over r@ + swap r@ - rot r>", 0, NULL, NULL },
{ "3drop", "drop 2drop", 0, NULL, NULL },
{ "3dup", "2 pick 2 pick 2 pick", 0, NULL, NULL },
{ "erase", "0 fill", 0, NULL, NULL },
{ "false", "0", 0, NULL, NULL },
- { ".h", "base @ swap 0x10 base ! . base !", 0, NULL, NULL },
- { "linefeed", "b(lit) 00 00 00 0x0a", 0, NULL, NULL },
+ { ".h", "base @ swap d# 10 base ! . base !", 0, NULL, NULL },
+ { "linefeed", "b(lit) 00 00 00 d# 0a", 0, NULL, NULL },
{ "/n*", "cells", 0, NULL, NULL },
{ "na1+", "cell+", 0, NULL, NULL },
{ "not", "invert", 0, NULL, NULL },
@@ -767,6 +785,8 @@
void
push(Cell val)
{
+ if (debug > 1)
+ printf("push %lx\n", (long)val);
parse_stack[parse_stack_ptr++] = val;
if (parse_stack_ptr >= PSTKSIZ) {
(void)printf( "Parse stack overflow\n");
@@ -778,6 +798,8 @@
pop(void)
{
ASSERT(parse_stack_ptr);
+ if (debug > 1)
+ printf("pop %lx\n", (long)parse_stack[parse_stack_ptr-1]);
return parse_stack[--parse_stack_ptr];
}
@@ -795,21 +817,23 @@
{
int res = strcmp(dict->name, new->name);
-#ifdef DEBUG
new->type = FCODE;
ASSERT(dict->type == FCODE);
-#endif
- /* Don't allow duplicate entries. */
- if (!res) return (0);
+ if (!res) {
+ /*
+ * Duplicate entry. Give the old name the new FCode
+ * number.
+ */
+ dict->num = new->num;
+ return (0);
+ }
if (res < 0) {
if (dict->l)
return fadd(dict->l, new);
else {
-#ifdef DEBUG
- if (debug > 1)
+ if (debug > 5)
(void)printf( "fadd: new FCode `%s' is %lx\n",
new->name, new->num);
-#endif
new->l = new->r = NULL;
dict->l = new;
}
@@ -817,11 +841,9 @@
if (dict->r)
return fadd(dict->r, new);
else {
Home |
Main Index |
Thread Index |
Old Index