From 949c349fae42f40c3ab83829fe14c69181582c91 Mon Sep 17 00:00:00 2001 From: jakebeal Date: Wed, 27 Aug 2008 22:15:50 +0000 Subject: [PATCH] OK. flex++ is evil. I may need to switch back to flex git-svn-id: https://svn.csail.mit.edu/proto@9 96bd3460-b366-48df-bbdf-208d6e4c0fe6 --- src/compiler/enumlexer.cpp | 48 ++-- src/compiler/{enumlexer.cpp => lexer.cpp} | 410 ++++++++++++++++-------------- src/compiler/proto_syntax.flex | 2 +- 3 files changed, 252 insertions(+), 208 deletions(-) copy src/compiler/{enumlexer.cpp => lexer.cpp} (80%) diff --git a/src/compiler/enumlexer.cpp b/src/compiler/enumlexer.cpp index 4e7a762..2f93913 100644 --- a/src/compiler/enumlexer.cpp +++ b/src/compiler/enumlexer.cpp @@ -461,8 +461,14 @@ static yyconst flex_int16_t yy_chk[127] = #define YY_RESTORE_YY_MORE_OFFSET #line 1 "one_enum.flex" /* a flex++ scanner for reading a C file containing one platform enum +Copyright (C) 2005-2008, Jonathan Bachrach, Jacob Beal, and contributors +listed in the AUTHORS file in the MIT Proto distribution's top directory. + +This file is part of MIT Proto, and is distributed under the terms of +the GNU General Public License, with a linking exception, as described +in the file LICENSE in the MIT Proto distribution's top directory. */ -#line 7 "one_enum.flex" +#line 13 "one_enum.flex" #define YY_BREAK { if(error) return 1; } break; #include @@ -494,7 +500,7 @@ protected: int yylex(); // prototype for lexing function }; -#line 498 "enumlexer.cpp" +#line 504 "enumlexer.cpp" #define INITIAL 0 @@ -594,10 +600,10 @@ YY_DECL register char *yy_cp, *yy_bp; register int yy_act; -#line 41 "one_enum.flex" +#line 47 "one_enum.flex" -#line 601 "enumlexer.cpp" +#line 607 "enumlexer.cpp" if ( !(yy_init) ) { @@ -683,7 +689,7 @@ do_action: /* This label is used only to access EOF actions. */ case 1: /* rule 1 can match eol */ YY_RULE_SETUP -#line 43 "one_enum.flex" +#line 49 "one_enum.flex" /* consume whitespace */ YY_BREAK case 2: @@ -691,12 +697,12 @@ case 2: (yy_c_buf_p) = yy_cp -= 1; YY_DO_BEFORE_ACTION; /* set up yytext again */ YY_RULE_SETUP -#line 44 "one_enum.flex" +#line 50 "one_enum.flex" /* consume C++ comments */ YY_BREAK case 3: YY_RULE_SETUP -#line 45 "one_enum.flex" +#line 51 "one_enum.flex" { register int c; /* consume C comments */ for ( ; ; ) { while ( (c = yyinput()) != '*' && c != EOF ) @@ -715,57 +721,57 @@ YY_RULE_SETUP YY_BREAK case 4: YY_RULE_SETUP -#line 61 "one_enum.flex" +#line 67 "one_enum.flex" { if(step==0) step++; else read_error("wrong location of 'typedef'"); } YY_BREAK case 5: YY_RULE_SETUP -#line 62 "one_enum.flex" +#line 68 "one_enum.flex" { if(step==1) step++; else read_error("wrong location of 'enum'"); } YY_BREAK case 6: YY_RULE_SETUP -#line 63 "one_enum.flex" +#line 69 "one_enum.flex" { if(step==2) step++; else read_error("wrong location of '{'"); } YY_BREAK case 7: YY_RULE_SETUP -#line 64 "one_enum.flex" +#line 70 "one_enum.flex" { if(step==3) step++; else read_error("wrong location of '='"); } YY_BREAK case 8: YY_RULE_SETUP -#line 65 "one_enum.flex" +#line 71 "one_enum.flex" { if(step==4) step++; else read_error("wrong location of 'CORE_CMD_OPS'"); } YY_BREAK case 9: YY_RULE_SETUP -#line 66 "one_enum.flex" +#line 72 "one_enum.flex" { if(step==5) step++; else read_error("wrong location of 'MAX_CMD_OPS'"); } YY_BREAK case 10: YY_RULE_SETUP -#line 67 "one_enum.flex" +#line 73 "one_enum.flex" { if(step==6) step++; else read_error("wrong location of '}'"); } YY_BREAK case 11: YY_RULE_SETUP -#line 68 "one_enum.flex" +#line 74 "one_enum.flex" { if(step==7) step++; else read_error("wrong location of 'PLATFORM_OPCODES'"); } YY_BREAK case 12: YY_RULE_SETUP -#line 69 "one_enum.flex" +#line 75 "one_enum.flex" { if(step==8) step++; else read_error("wrong location of ';'"); } YY_BREAK case 13: YY_RULE_SETUP -#line 71 "one_enum.flex" +#line 77 "one_enum.flex" { if(ready_for_entry) read_error("bad comma location"); else ready_for_entry=true; } YY_BREAK case 14: YY_RULE_SETUP -#line 73 "one_enum.flex" +#line 79 "one_enum.flex" { if(!ready_for_entry || (step==2 && !p_ops->empty()) || (step==4 && p_ops->empty())) read_error("Bad constituent"); @@ -775,10 +781,10 @@ YY_RULE_SETUP YY_BREAK case 15: YY_RULE_SETUP -#line 81 "one_enum.flex" +#line 87 "one_enum.flex" ECHO; YY_BREAK -#line 782 "enumlexer.cpp" +#line 788 "enumlexer.cpp" case YY_STATE_EOF(INITIAL): yyterminate(); @@ -1672,7 +1678,7 @@ void zzfree (void * ptr ) #define YYTABLES_NAME "yytables" -#line 81 "one_enum.flex" +#line 87 "one_enum.flex" diff --git a/src/compiler/enumlexer.cpp b/src/compiler/lexer.cpp similarity index 80% copy from src/compiler/enumlexer.cpp copy to src/compiler/lexer.cpp index 4e7a762..96ba552 100644 --- a/src/compiler/enumlexer.cpp +++ b/src/compiler/lexer.cpp @@ -1,6 +1,6 @@ -#line 2 "enumlexer.cpp" +#line 2 "lexer.cpp" -#line 4 "enumlexer.cpp" +#line 4 "lexer.cpp" #define YY_INT_ALIGNED short int @@ -20,7 +20,7 @@ * We will address this in a future release of flex, or omit the C++ scanner * altogether. */ - #define yyFlexLexer zzFlexLexer + #define yyFlexLexer yyFlexLexer /* First, we deal with platform-specific or compiler-specific issues. */ @@ -169,7 +169,20 @@ extern int yyleng; #define EOB_ACT_END_OF_FILE 1 #define EOB_ACT_LAST_MATCH 2 - #define YY_LESS_LINENO(n) + /* Note: We specifically omit the test for yy_rule_can_match_eol because it requires + * access to the local variable yy_act. Since yyless() is a macro, it would break + * existing scanners that call yyless() from OUTSIDE yylex. + * One obvious solution it to make yy_act a global. I tried that, and saw + * a 5% performance hit in a non-yylineno scanner, because yy_act is + * normally declared as a register variable-- so it is not worth it. + */ + #define YY_LESS_LINENO(n) \ + do { \ + int yyl;\ + for ( yyl = n; yyl < yyleng; ++yyl )\ + if ( yytext[yyl] == '\n' )\ + --yylineno;\ + }while(0) /* Return all but the first "n" matched characters back to the input stream. */ #define yyless(n) \ @@ -278,9 +291,9 @@ struct yy_buffer_state */ #define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)] -void *zzalloc (yy_size_t ); -void *zzrealloc (void *,yy_size_t ); -void zzfree (void * ); +void *yyalloc (yy_size_t ); +void *yyrealloc (void *,yy_size_t ); +void yyfree (void * ); #define yy_new_buffer yy_create_buffer @@ -320,7 +333,7 @@ int yyFlexLexer::yylex() return 0; } -#define YY_DECL int EnumLexer::yylex() +#define YY_DECL int SExprLexer::yylex() /* Done after the current pattern has been matched and before the * corresponding action - sets up yytext. @@ -332,8 +345,8 @@ int yyFlexLexer::yylex() *yy_cp = '\0'; \ (yy_c_buf_p) = yy_cp; -#define YY_NUM_RULES 15 -#define YY_END_OF_BUFFER 16 +#define YY_NUM_RULES 14 +#define YY_END_OF_BUFFER 15 /* This struct is not used in this scanner, but its presence is necessary. */ struct yy_trans_info @@ -341,15 +354,12 @@ struct yy_trans_info flex_int32_t yy_verify; flex_int32_t yy_nxt; }; -static yyconst flex_int16_t yy_accept[70] = +static yyconst flex_int16_t yy_accept[34] = { 0, - 0, 0, 16, 15, 1, 13, 15, 14, 12, 7, - 14, 14, 14, 14, 14, 6, 10, 1, 3, 0, - 14, 14, 14, 14, 14, 14, 0, 2, 14, 14, - 14, 14, 14, 14, 14, 14, 5, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, 14, 4, - 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, - 9, 14, 8, 14, 14, 14, 14, 11, 0 + 0, 0, 15, 13, 1, 12, 6, 3, 4, 11, + 7, 11, 11, 9, 13, 11, 5, 12, 1, 11, + 8, 11, 9, 10, 9, 11, 0, 2, 11, 9, + 9, 10, 0 } ; static yyconst flex_int32_t yy_ec[256] = @@ -357,17 +367,17 @@ static yyconst flex_int32_t yy_ec[256] = 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 4, 1, 5, 1, 1, 6, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 7, 1, 8, 1, - 9, 1, 1, 1, 10, 7, 11, 12, 13, 14, - 7, 7, 7, 7, 7, 15, 16, 7, 17, 18, - 7, 19, 20, 21, 7, 7, 7, 22, 7, 7, - 1, 1, 1, 1, 23, 1, 7, 7, 7, 24, - - 25, 26, 7, 7, 7, 7, 7, 7, 27, 28, - 7, 29, 7, 7, 7, 30, 31, 7, 7, 7, - 32, 7, 33, 1, 34, 1, 1, 1, 1, 1, + 1, 2, 4, 4, 4, 4, 4, 4, 5, 6, + 7, 8, 8, 9, 10, 11, 8, 12, 12, 12, + 12, 12, 12, 12, 12, 12, 12, 4, 13, 8, + 8, 8, 8, 14, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, + 4, 4, 4, 4, 8, 16, 15, 15, 15, 15, + + 17, 15, 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 18, 4, 18, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, @@ -384,74 +394,55 @@ static yyconst flex_int32_t yy_ec[256] = 1, 1, 1, 1, 1 } ; -static yyconst flex_int32_t yy_meta[35] = +static yyconst flex_int32_t yy_meta[19] = { 0, - 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 1, 1 + 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, + 2, 2, 1, 1, 2, 1, 2, 1 } ; -static yyconst flex_int16_t yy_base[72] = +static yyconst flex_int16_t yy_base[36] = { 0, - 0, 0, 91, 92, 33, 92, 33, 0, 92, 92, - 73, 79, 73, 59, 54, 92, 92, 38, 92, 82, - 0, 65, 61, 72, 50, 51, 76, 92, 65, 54, - 55, 48, 49, 50, 61, 57, 0, 46, 58, 52, - 50, 41, 49, 52, 44, 36, 49, 37, 43, 0, - 35, 40, 33, 38, 36, 36, 34, 31, 32, 29, - 0, 37, 0, 30, 34, 32, 24, 0, 92, 36, - 41 + 0, 0, 43, 44, 17, 44, 44, 44, 44, 0, + 28, 10, 29, 12, 37, 0, 44, 44, 22, 0, + 44, 27, 0, 14, 15, 26, 34, 44, 24, 0, + 23, 18, 44, 26, 32 } ; -static yyconst flex_int16_t yy_def[72] = +static yyconst flex_int16_t yy_def[36] = { 0, - 69, 1, 69, 69, 69, 69, 69, 70, 69, 69, - 70, 70, 70, 70, 70, 69, 69, 69, 69, 71, - 70, 70, 70, 70, 70, 70, 71, 69, 70, 70, - 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, - 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, - 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, - 70, 70, 70, 70, 70, 70, 70, 70, 0, 69, - 69 + 33, 1, 33, 33, 33, 33, 33, 33, 33, 34, + 34, 34, 34, 12, 35, 34, 33, 33, 33, 34, + 33, 34, 14, 34, 34, 34, 35, 33, 34, 25, + 34, 34, 0, 33, 33 } ; -static yyconst flex_int16_t yy_nxt[127] = +static yyconst flex_int16_t yy_nxt[63] = { 0, - 4, 5, 5, 4, 6, 7, 8, 9, 10, 8, - 11, 8, 8, 8, 8, 12, 8, 13, 8, 8, - 8, 8, 8, 8, 14, 8, 8, 8, 8, 15, - 8, 8, 16, 17, 18, 18, 19, 21, 20, 18, - 18, 27, 27, 68, 67, 66, 65, 64, 63, 62, - 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, - 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, - 41, 40, 39, 38, 37, 36, 35, 34, 28, 33, - 32, 31, 30, 29, 28, 26, 25, 24, 23, 22, - 69, 3, 69, 69, 69, 69, 69, 69, 69, 69, - - 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, - 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, - 69, 69, 69, 69, 69, 69 + 4, 5, 5, 6, 7, 8, 9, 10, 11, 12, + 13, 14, 15, 4, 16, 17, 16, 18, 19, 19, + 22, 23, 25, 19, 19, 24, 30, 20, 26, 32, + 29, 26, 27, 27, 31, 32, 28, 31, 24, 28, + 24, 21, 33, 3, 33, 33, 33, 33, 33, 33, + 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, + 33, 33 } ; -static yyconst flex_int16_t yy_chk[127] = +static yyconst flex_int16_t yy_chk[63] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 5, 5, 7, 70, 7, 18, - 18, 71, 71, 67, 66, 65, 64, 62, 60, 59, - 58, 57, 56, 55, 54, 53, 52, 51, 49, 48, - 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, - 36, 35, 34, 33, 32, 31, 30, 29, 27, 26, - 25, 24, 23, 22, 20, 15, 14, 13, 12, 11, - 3, 69, 69, 69, 69, 69, 69, 69, 69, 69, - - 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, - 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, - 69, 69, 69, 69, 69, 69 + 1, 1, 1, 1, 1, 1, 1, 1, 5, 5, + 12, 12, 14, 19, 19, 24, 25, 34, 14, 32, + 24, 25, 35, 35, 31, 29, 27, 26, 22, 15, + 13, 11, 3, 33, 33, 33, 33, 33, 33, 33, + 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, + 33, 33 } ; +/* Table of booleans, true if rule could match eol. */ +static yyconst flex_int32_t yy_rule_can_match_eol[15] = + { 0, +1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; + /* The intent behind this definition is that it'll catch * any uses of REJECT which flex missed. */ @@ -459,42 +450,102 @@ static yyconst flex_int16_t yy_chk[127] = #define yymore() yymore_used_but_not_detected #define YY_MORE_ADJ 0 #define YY_RESTORE_YY_MORE_OFFSET -#line 1 "one_enum.flex" -/* a flex++ scanner for reading a C file containing one platform enum +#line 1 "proto_syntax.flex" +/* a flex++ scanner for Proto +Copyright (C) 2005-2008, Jonathan Bachrach, Jacob Beal, and contributors +listed in the AUTHORS file in the MIT Proto distribution's top directory. + +This file is part of MIT Proto, and is distributed under the terms of +the GNU General Public License, with a linking exception, as described +in the file LICENSE in the MIT Proto distribution's top directory. + + Used: alphanumeric, *+-./<=>?_ + Special: ;'(),`@ + Reserved: !"#$%&:[\]^{|}~ */ -#line 7 "one_enum.flex" +#line 22 "proto_syntax.flex" #define YY_BREAK { if(error) return 1; } break; -#include -#include -#include "compiler-utils.h" +#include "sexpr.h" +#include "utils.h" -int zzwrap() { return 1; } -extern int yywrap(); - -class EnumLexer : public zzFlexLexer { - bool ready_for_entry, error; int step; list *p_ops; - void read_error(string err) { *cperr << "Platform description file is not a parsable 'single enum' file: " << err << " .\n"; error=true; } +int yywrap() { return 1; } +class SExprLexer : public yyFlexLexer { + SE_List* base; // the implicit wrapping "all" for compilation + stack enclosure; // what SExprs enclose the current parse? + stack wraps; // are these SExprs normal or character macro wrappers? + bool error; + string name; // name of code source (e.g. file, "command-line") + + void compile_error(Attribute* context,string msg) { + *cperr << context->to_str() << ": " << msg << endl; + error=true; + } + public: - EnumLexer(istream *in, ostream *out) : zzFlexLexer(in,out) { - ready_for_entry=true; error=false; step=0; p_ops = new list; + SExprLexer(string name, istream* in=0, ostream* out=0) : yyFlexLexer(in,out) { + error = false; this->name=name; + base = new SE_List(); base->add(new SE_Symbol("ALL")); + enclosure.push(base); wraps.push(false); } - virtual ~EnumLexer() {} // nothing to clean up: p_ops is somebody else's prob + + virtual ~SExprLexer() {} // nothing to clean up: base becomes a problem of others // returns NULL on error - list* tokenize() { + SExpr* tokenize() { yylex(); - if(!error && step<9) { read_error("file not closed by ';'"); } - if(error) { delete p_ops; return NULL; - } else { return p_ops; } + if(enclosure.top()!=base) { + compile_error(enclosure.top()->attributes["CONTEXT"],"Missing right parenthesis"); + } + if(error) { delete base; return NULL; + } else if(base->len()==2) { return base->children[1]; // single SEXpr + } else { return base; } } protected: + Context* context() { return new Context(name,lineno()); } + + // start a new sexpr, contained within the current context + void start_compound_sexpr() { + SE_List *e = new SE_List(); e->attributes["CONTEXT"]=context(); + enclosure.top()->add(e); + enclosure.push(e); wraps.push(false); + } + + void end_compound_sexpr() { + if(wraps.top() && enclosure.top()->children.size()<=1) { + compile_error(enclosure.top()->attributes["CONTEXT"], + "Wrapper macro " + enclosure.top()->op()->to_str() + + " is not applied to anything"); + } else if(enclosure.top()==base) { + compile_error(context(),"Too many right parentheses"); + } else { + enclosure.pop(); wraps.pop(); + if(wraps.top()) { // if the next layer is a macro wrapper, finish it too + end_compound_sexpr(); + } + } + } + + // single character macros like ' create wrappers around the next SExpr + void wrap_next_sexpr(SE_Symbol* symbol) { + symbol->attributes["CONTEXT"]=context(); + SE_List* s = new SE_List(); + s->add(symbol); enclosure.top()->add(s); + enclosure.push(s); wraps.push(true); + } + + void add_sexpr(SExpr* s) { + s->attributes["CONTEXT"]=context(); + enclosure.top()->add(s); + if(wraps.top()) { end_compound_sexpr(); } + } + int yylex(); // prototype for lexing function }; -#line 498 "enumlexer.cpp" +#line 549 "lexer.cpp" #define INITIAL 0 @@ -594,10 +645,10 @@ YY_DECL register char *yy_cp, *yy_bp; register int yy_act; -#line 41 "one_enum.flex" +#line 106 "proto_syntax.flex" -#line 601 "enumlexer.cpp" +#line 652 "lexer.cpp" if ( !(yy_init) ) { @@ -650,13 +701,13 @@ yy_match: while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 70 ) + if ( yy_current_state >= 34 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; ++yy_cp; } - while ( yy_base[yy_current_state] != 92 ); + while ( yy_base[yy_current_state] != 44 ); yy_find_action: yy_act = yy_accept[yy_current_state]; @@ -669,6 +720,16 @@ yy_find_action: YY_DO_BEFORE_ACTION; + if ( yy_act != YY_END_OF_BUFFER && yy_rule_can_match_eol[yy_act] ) + { + int yyl; + for ( yyl = 0; yyl < yyleng; ++yyl ) + if ( yytext[yyl] == '\n' ) + + yylineno++; +; + } + do_action: /* This label is used only to access EOF actions. */ switch ( yy_act ) @@ -683,7 +744,7 @@ do_action: /* This label is used only to access EOF actions. */ case 1: /* rule 1 can match eol */ YY_RULE_SETUP -#line 43 "one_enum.flex" +#line 108 "proto_syntax.flex" /* consume whitespace */ YY_BREAK case 2: @@ -691,94 +752,67 @@ case 2: (yy_c_buf_p) = yy_cp -= 1; YY_DO_BEFORE_ACTION; /* set up yytext again */ YY_RULE_SETUP -#line 44 "one_enum.flex" -/* consume C++ comments */ +#line 109 "proto_syntax.flex" +/* consume comments */ YY_BREAK case 3: YY_RULE_SETUP -#line 45 "one_enum.flex" -{ register int c; /* consume C comments */ - for ( ; ; ) { - while ( (c = yyinput()) != '*' && c != EOF ) - ; /* eat up text of comment */ - if ( c == '*' ) { - while ( (c = yyinput()) == '*' ) ; - if ( c == '/' ) - break; /* found the end */ - } - if ( c == EOF ) { - read_error("file ended w. unclosed C comment"); - break; - } - } - } +#line 111 "proto_syntax.flex" +start_compound_sexpr(); YY_BREAK case 4: YY_RULE_SETUP -#line 61 "one_enum.flex" -{ if(step==0) step++; else read_error("wrong location of 'typedef'"); } +#line 112 "proto_syntax.flex" +end_compound_sexpr(); YY_BREAK case 5: YY_RULE_SETUP -#line 62 "one_enum.flex" -{ if(step==1) step++; else read_error("wrong location of 'enum'"); } +#line 114 "proto_syntax.flex" +wrap_next_sexpr(new SE_Symbol("QUASIQUOTE")); YY_BREAK case 6: YY_RULE_SETUP -#line 63 "one_enum.flex" -{ if(step==2) step++; else read_error("wrong location of '{'"); } +#line 115 "proto_syntax.flex" +wrap_next_sexpr(new SE_Symbol("QUOTE")); YY_BREAK case 7: YY_RULE_SETUP -#line 64 "one_enum.flex" -{ if(step==3) step++; else read_error("wrong location of '='"); } +#line 116 "proto_syntax.flex" +wrap_next_sexpr(new SE_Symbol("COMMA")); YY_BREAK case 8: YY_RULE_SETUP -#line 65 "one_enum.flex" -{ if(step==4) step++; else read_error("wrong location of 'CORE_CMD_OPS'"); } +#line 117 "proto_syntax.flex" +wrap_next_sexpr(new SE_Symbol("COMMA-SPLICE")); YY_BREAK case 9: -YY_RULE_SETUP -#line 66 "one_enum.flex" -{ if(step==5) step++; else read_error("wrong location of 'MAX_CMD_OPS'"); } - YY_BREAK +#line 120 "proto_syntax.flex" case 10: YY_RULE_SETUP -#line 67 "one_enum.flex" -{ if(step==6) step++; else read_error("wrong location of '}'"); } +#line 120 "proto_syntax.flex" +add_sexpr(new SE_Scalar(atof(YYText()))); YY_BREAK case 11: YY_RULE_SETUP -#line 68 "one_enum.flex" -{ if(step==7) step++; else read_error("wrong location of 'PLATFORM_OPCODES'"); } +#line 122 "proto_syntax.flex" +add_sexpr(new SE_Symbol(YYText())); YY_BREAK case 12: YY_RULE_SETUP -#line 69 "one_enum.flex" -{ if(step==8) step++; else read_error("wrong location of ';'"); } +#line 124 "proto_syntax.flex" +compile_error(context(),"Illegal use of reserved character '"+string(YYText())+"'"); YY_BREAK case 13: YY_RULE_SETUP -#line 71 "one_enum.flex" -{ if(ready_for_entry) read_error("bad comma location"); else ready_for_entry=true; } +#line 125 "proto_syntax.flex" +compile_error(context(),"Unrecognized character: '"+string(YYText())+"'"); YY_BREAK case 14: YY_RULE_SETUP -#line 73 "one_enum.flex" -{ if(!ready_for_entry || - (step==2 && !p_ops->empty()) || - (step==4 && p_ops->empty())) read_error("Bad constituent"); - else { p_ops->push_back(string(YYText())); - ready_for_entry=false; - } } - YY_BREAK -case 15: -YY_RULE_SETUP -#line 81 "one_enum.flex" +#line 127 "proto_syntax.flex" ECHO; YY_BREAK -#line 782 "enumlexer.cpp" +#line 816 "lexer.cpp" case YY_STATE_EOF(INITIAL): yyterminate(); @@ -1062,7 +1096,7 @@ int yyFlexLexer::yy_get_next_buffer() b->yy_ch_buf = (char *) /* Include room in for 2 EOB chars. */ - zzrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ); + yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ); } else /* Can't grow it, we don't own it. */ @@ -1137,7 +1171,7 @@ int yyFlexLexer::yy_get_next_buffer() while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 70 ) + if ( yy_current_state >= 34 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; @@ -1165,11 +1199,11 @@ int yyFlexLexer::yy_get_next_buffer() while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 70 ) + if ( yy_current_state >= 34 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - yy_is_jam = (yy_current_state == 69); + yy_is_jam = (yy_current_state == 33); return yy_is_jam ? 0 : yy_current_state; } @@ -1206,6 +1240,10 @@ int yyFlexLexer::yy_get_next_buffer() *--yy_cp = (char) c; + if ( c == '\n' ){ + --yylineno; + } + (yytext_ptr) = yy_bp; (yy_hold_char) = *yy_cp; (yy_c_buf_p) = yy_cp; @@ -1275,6 +1313,11 @@ int yyFlexLexer::yy_get_next_buffer() *(yy_c_buf_p) = '\0'; /* preserve yytext */ (yy_hold_char) = *++(yy_c_buf_p); + if ( c == '\n' ) + + yylineno++; +; + return c; } @@ -1349,7 +1392,7 @@ int yyFlexLexer::yy_get_next_buffer() { YY_BUFFER_STATE b; - b = (YY_BUFFER_STATE) zzalloc(sizeof( struct yy_buffer_state ) ); + b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); if ( ! b ) YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); @@ -1358,7 +1401,7 @@ int yyFlexLexer::yy_get_next_buffer() /* yy_ch_buf has to be 2 characters longer than the size given because * we need to put in 2 end-of-buffer characters. */ - b->yy_ch_buf = (char *) zzalloc(b->yy_buf_size + 2 ); + b->yy_ch_buf = (char *) yyalloc(b->yy_buf_size + 2 ); if ( ! b->yy_ch_buf ) YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); @@ -1383,9 +1426,9 @@ int yyFlexLexer::yy_get_next_buffer() YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; if ( b->yy_is_our_buffer ) - zzfree((void *) b->yy_ch_buf ); + yyfree((void *) b->yy_ch_buf ); - zzfree((void *) b ); + yyfree((void *) b ); } extern "C" int isatty (int ); @@ -1510,7 +1553,7 @@ void yyFlexLexer::yyensure_buffer_stack(void) * immediate realloc on the next call. */ num_to_alloc = 1; - (yy_buffer_stack) = (struct yy_buffer_state**)zzalloc + (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc (num_to_alloc * sizeof(struct yy_buffer_state*) ); @@ -1527,7 +1570,7 @@ void yyFlexLexer::yyensure_buffer_stack(void) int grow_size = 8 /* arbitrary grow size */; num_to_alloc = (yy_buffer_stack_max) + grow_size; - (yy_buffer_stack) = (struct yy_buffer_state**)zzrealloc + (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc ((yy_buffer_stack), num_to_alloc * sizeof(struct yy_buffer_state*) ); @@ -1548,10 +1591,10 @@ void yyFlexLexer::yyensure_buffer_stack(void) new_size = (yy_start_stack_depth) * sizeof( int ); if ( ! (yy_start_stack) ) - (yy_start_stack) = (int *) zzalloc(new_size ); + (yy_start_stack) = (int *) yyalloc(new_size ); else - (yy_start_stack) = (int *) zzrealloc((void *) (yy_start_stack),new_size ); + (yy_start_stack) = (int *) yyrealloc((void *) (yy_start_stack),new_size ); if ( ! (yy_start_stack) ) YY_FATAL_ERROR( @@ -1616,11 +1659,11 @@ yyFlexLexer::~yyFlexLexer() } /* Destroy the stack itself. */ - zzfree((yy_buffer_stack) ); + yyfree((yy_buffer_stack) ); (yy_buffer_stack) = NULL; delete [] (yy_state_buf); - zzfree((yy_start_stack) ); + yyfree((yy_start_stack) ); } @@ -1648,12 +1691,12 @@ static int yy_flex_strlen (yyconst char * s ) } #endif -void *zzalloc (yy_size_t size ) +void *yyalloc (yy_size_t size ) { return (void *) malloc( size ); } -void *zzrealloc (void * ptr, yy_size_t size ) +void *yyrealloc (void * ptr, yy_size_t size ) { /* The cast to (char *) in the following accommodates both * implementations that use char* generic pointers, and those @@ -1665,24 +1708,19 @@ void *zzrealloc (void * ptr, yy_size_t size ) return (void *) realloc( (char *) ptr, size ); } -void zzfree (void * ptr ) +void yyfree (void * ptr ) { - free( (char *) ptr ); /* see zzrealloc() for (char *) cast */ + free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ } #define YYTABLES_NAME "yytables" -#line 81 "one_enum.flex" +#line 127 "proto_syntax.flex" -list* read_enum(istream* in, ostream* out=NULL) { - string dump; - if(out==NULL) out=new ostringstream(); - EnumLexer lex(in,out); - return lex.tokenize(); -} -list* read_enum(string in) { - return read_enum(new istringstream(in)); -} +SExpr* read_sexpr(string name, string in) +{ return read_sexpr(name,new istringstream(in)); } +SExpr* read_sexpr(string name, istream* in, ostream* out) +{ SExprLexer lex(name,in,out); return lex.tokenize(); } diff --git a/src/compiler/proto_syntax.flex b/src/compiler/proto_syntax.flex index af67f02..6dd520a 100644 --- a/src/compiler/proto_syntax.flex +++ b/src/compiler/proto_syntax.flex @@ -24,7 +24,7 @@ SPECIAL [;'(),`@] #include "sexpr.h" #include "utils.h" -//int yywrap() { return 1; } +int yywrap() { return 1; } class SExprLexer : public yyFlexLexer { SE_List* base; // the implicit wrapping "all" for compilation -- 2.11.4.GIT