From 4821fe92aa56edc34b0f2c5c63ff4e6ac6519e1c Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Thu, 26 Oct 2006 14:22:01 +0000 Subject: [PATCH] *** empty log message *** --- ase/awk/makefile.cl | 4 +- ase/awk/parse.c | 73 +++++++++++++++++++++++++++++---- ase/lsp/read.c | 99 ++++++++++++++++++++++++++++++++++++++++++++- ase/test/awk/awk.c | 4 +- ase/test/awk/x.awk | 26 +++++++----- 5 files changed, 184 insertions(+), 22 deletions(-) diff --git a/ase/awk/makefile.cl b/ase/awk/makefile.cl index 3e3a9199..21c0e488 100644 --- a/ase/awk/makefile.cl +++ b/ase/awk/makefile.cl @@ -22,9 +22,9 @@ JAVACFLAGS = -classpath ../.. all: lib jni -lib: $(OBJS) +lib: $(C_OBJS) $(LD) /lib @<< -/nologo /out:$(OUT).lib $(OBJS) +/nologo /out:$(OUT).lib $(C_OBJS) << jni: $(JNI_OBJS) $(JAVA_OBJS) diff --git a/ase/awk/parse.c b/ase/awk/parse.c index 99e60e7c..6f371cd3 100644 --- a/ase/awk/parse.c +++ b/ase/awk/parse.c @@ -1,5 +1,5 @@ /* - * $Id: parse.c,v 1.195 2006-10-26 09:27:15 bacon Exp $ + * $Id: parse.c,v 1.196 2006-10-26 14:21:40 bacon Exp $ */ #include @@ -281,11 +281,11 @@ static struct __bvent __bvtab[] = }; #define GET_CHAR(awk) \ - do { if (__get_char(awk) == -1) return -1; } while(0) + do { if (__get_char (awk) == -1) return -1; } while(0) #define GET_CHAR_TO(awk,c) \ do { \ - if (__get_char(awk) == -1) return -1; \ + if (__get_char (awk) == -1) return -1; \ c = (awk)->src.lex.curc; \ } while(0) @@ -1247,12 +1247,52 @@ awk->parse.nl_semicolon = 1; else if (MATCH(awk,TOKEN_PRINT)) { if (__get_token(awk) == -1) return ASE_NULL; - nde = __parse_print (awk); + if (MATCH (awk, TOKEN_LPAREN)) + { + if (__get_token(awk) == -1) return ASE_NULL; + nde = __parse_print (awk); + if (nde == ASE_NULL) return ASE_NULL; + + if (!MATCH (awk, TOKEN_RPAREN)) + { + ase_awk_clrpt (awk, nde); + PANIC (awk, ASE_AWK_ERPAREN); + } + if (__get_token(awk) == -1) + { + ase_awk_clrpt (awk, nde); + return ASE_NULL; + } + } + else + { + nde = __parse_print (awk); + } } else if (MATCH(awk,TOKEN_PRINTF)) { if (__get_token(awk) == -1) return ASE_NULL; - nde = __parse_printf (awk); + if (MATCH (awk, TOKEN_LPAREN)) + { + if (__get_token(awk) == -1) return ASE_NULL; + nde = __parse_printf (awk); + if (nde == ASE_NULL) return ASE_NULL; + + if (!MATCH (awk, TOKEN_RPAREN)) + { + ase_awk_clrpt (awk, nde); + PANIC (awk, ASE_AWK_ERPAREN); + } + if (__get_token(awk) == -1) + { + ase_awk_clrpt (awk, nde); + return ASE_NULL; + } + } + else + { + nde = __parse_printf (awk); + } } else { @@ -2227,7 +2267,6 @@ static ase_awk_nde_t* __parse_primary (ase_awk_t* awk) if (MATCH(awk,TOKEN_IDENT)) { /* getline var */ - var = __parse_primary (awk); if (var == ASE_NULL) return ASE_NULL; } @@ -3221,6 +3260,8 @@ static ase_awk_nde_t* __parse_print (ase_awk_t* awk) static ase_awk_nde_t* __parse_printf (ase_awk_t* awk) { /* TODO: implement this... */ +ASE_AWK_ASSERT (awk, !"printf not implemented yet"); +awk->errnum = ASE_AWK_EINTERNAL; return ASE_NULL; } @@ -3297,10 +3338,26 @@ static int __get_token (ase_awk_t* awk) { SET_TOKEN_TYPE (awk, TOKEN_EOF); } - else if (ASE_AWK_ISDIGIT (awk, c) || c == ASE_T('.')) + else if (ASE_AWK_ISDIGIT (awk, c)/*|| c == ASE_T('.')*/) { if (__get_number (awk) == -1) return -1; } + else if (c == ASE_T('.')) + { + if (__get_char (awk) == -1) return -1; + c = awk->src.lex.curc; + + if (ASE_AWK_ISDIGIT (awk, c)) + { + if (__unget_char (awk, c) == -1) return -1; + if (__get_number (awk) == -1) return -1; + } + else + { + awk->errnum = ASE_AWK_ELXCHR; + return -1; + } + } else if (ASE_AWK_ISALPHA (awk, c) || c == ASE_T('_')) { int type; @@ -4066,7 +4123,7 @@ static int __skip_comment (ase_awk_t* awk) return 1; /* c-style comment */ } - if (__unget_char(awk,c) == -1) return -1; /* error */ + if (__unget_char (awk, c) == -1) return -1; /* error */ awk->src.lex.curc = ASE_T('/'); return 0; diff --git a/ase/lsp/read.c b/ase/lsp/read.c index 98648534..7398b2d0 100644 --- a/ase/lsp/read.c +++ b/ase/lsp/read.c @@ -1,5 +1,5 @@ /* - * $Id: read.c,v 1.24 2006-10-26 09:31:28 bacon Exp $ + * $Id: read.c,v 1.25 2006-10-26 14:22:01 bacon Exp $ */ #include @@ -347,6 +347,7 @@ static int read_token (ase_lsp_t* lsp) return 0; } +#if 0 static int read_number (ase_lsp_t* lsp, int negative) { ase_long_t ivalue = 0; @@ -387,6 +388,102 @@ static int read_number (ase_lsp_t* lsp, int negative) return 0; } +#endif + +static int __read_number (ase_lsp_t* lsp, int negative) +{ + ase_cint_t c; + + ASE_LSP_ASSERT (lsp, ASE_LSP_STR_LEN(&lsp->token.name) == 0); + SET_TOKEN_TYPE (lsp, TOKEN_INT); + + c = lsp->src.lex.curc; + + if (c == ASE_T('0')) + { + ADD_TOKEN_CHAR (lsp, c); + GET_CHAR_TO (lsp, c); + + if (c == ASE_T('x') || c == ASE_T('X')) + { + /* hexadecimal number */ + do + { + ADD_TOKEN_CHAR (lsp, c); + GET_CHAR_TO (lsp, c); + } + while (ASE_LSP_ISXDIGIT (lsp, c)); + + return 0; + } + else if (c == ASE_T('b') || c == ASE_T('B')) + { + /* binary number */ + do + { + ADD_TOKEN_CHAR (lsp, c); + GET_CHAR_TO (lsp, c); + } + while (c == ASE_T('0') || c == ASE_T('1')); + + return 0; + } + else if (c != '.') + { + /* octal number */ + while (c >= ASE_T('0') && c <= ASE_T('7')) + { + ADD_TOKEN_CHAR (lsp, c); + GET_CHAR_TO (lsp, c); + } + + return 0; + } + } + + while (ASE_LSP_ISDIGIT (lsp, c)) + { + ADD_TOKEN_CHAR (lsp, c); + GET_CHAR_TO (lsp, c); + } + + if (c == ASE_T('.')) + { + /* floating-point number */ + SET_TOKEN_TYPE (lsp, TOKEN_REAL); + + ADD_TOKEN_CHAR (lsp, c); + GET_CHAR_TO (lsp, c); + + while (ASE_LSP_ISDIGIT (lsp, c)) + { + ADD_TOKEN_CHAR (lsp, c); + GET_CHAR_TO (lsp, c); + } + } + + if (c == ASE_T('E') || c == ASE_T('e')) + { + SET_TOKEN_TYPE (lsp, TOKEN_REAL); + + ADD_TOKEN_CHAR (lsp, c); + GET_CHAR_TO (lsp, c); + + if (c == ASE_T('+') || c == ASE_T('-')) + { + ADD_TOKEN_CHAR (lsp, c); + GET_CHAR_TO (lsp, c); + } + + while (ASE_LSP_ISDIGIT (lsp, c)) + { + ADD_TOKEN_CHAR (lsp, c); + GET_CHAR_TO (lsp, c); + } + } + + return 0; +} static int read_ident (ase_lsp_t* lsp) { diff --git a/ase/test/awk/awk.c b/ase/test/awk/awk.c index 5d170047..533ed384 100644 --- a/ase/test/awk/awk.c +++ b/ase/test/awk/awk.c @@ -1,5 +1,5 @@ /* - * $Id: awk.c,v 1.102 2006-10-24 04:48:52 bacon Exp $ + * $Id: awk.c,v 1.103 2006-10-26 14:22:01 bacon Exp $ */ #include @@ -641,7 +641,7 @@ static int __main (int argc, xp_char_t* argv[]) /*ASE_AWK_DBLSLASHES |*/ ASE_AWK_SHADING | ASE_AWK_IMPLICIT | ASE_AWK_SHIFT | ASE_AWK_EXTIO | ASE_AWK_BLOCKLESS | ASE_AWK_STRINDEXONE | - ASE_AWK_STRIPSPACES | ASE_AWK_NEWLINE; + ASE_AWK_STRIPSPACES /*| ASE_AWK_NEWLINE*/; if (argc <= 1) { diff --git a/ase/test/awk/x.awk b/ase/test/awk/x.awk index 1586af1f..1c3f0635 100644 --- a/ase/test/awk/x.awk +++ b/ase/test/awk/x.awk @@ -1,11 +1,19 @@ -BEGIN + +main () { - /* - print 1 - | - "test"; - */ - print 1 - | - 1; + print (("%f", 1.0)); } + +BEGIN { + #print 1 + #| + #"test"; +# */ + + #print 1 | + # 1; + + print .0; + print 10; +} +