[brlcad-commits] SF.net SVN: brlcad:[48121] brlcad/trunk/src/other
Open Source Solid Modeling CAD
Brought to you by:
brlcad
From: <n_...@us...> - 2011-12-21 22:52:28
|
Revision: 48121 http://brlcad.svn.sourceforge.net/brlcad/?rev=48121&view=rev Author: n_reed Date: 2011-12-21 22:52:20 +0000 (Wed, 21 Dec 2011) Log Message: ----------- initial build of step express parser using perplex scanner Modified Paths: -------------- brlcad/trunk/src/other/step/include/express/lexact.h brlcad/trunk/src/other/step/src/express/CMakeLists.txt brlcad/trunk/src/other/step/src/express/expparse.y brlcad/trunk/src/other/step/src/express/express.c brlcad/trunk/src/other/step/src/express/lexact.c brlcad/trunk/src/other/step/src/express/yyvars.c brlcad/trunk/src/other/step.dist Added Paths: ----------- brlcad/trunk/src/other/step/src/express/expscan.l brlcad/trunk/src/other/step/src/express/parse_data.h Removed Paths: ------------- brlcad/trunk/src/other/step/src/express/expscan.re Modified: brlcad/trunk/src/other/step/include/express/lexact.h =================================================================== --- brlcad/trunk/src/other/step/include/express/lexact.h 2011-12-21 22:14:46 UTC (rev 48120) +++ brlcad/trunk/src/other/step/include/express/lexact.h 2011-12-21 22:52:20 UTC (rev 48121) @@ -100,18 +100,16 @@ /* function prototypes */ /***********************/ -extern int yylex PROTO((void)); /* the scanner */ - extern void SCANinitialize PROTO((void)); -extern int SCANprocess_real_literal PROTO((void)); -extern int SCANprocess_integer_literal PROTO((void)); -extern int SCANprocess_binary_literal PROTO((void)); +extern int SCANprocess_real_literal PROTO((const char *)); +extern int SCANprocess_integer_literal PROTO((const char *)); +extern int SCANprocess_binary_literal PROTO((const char *)); extern int SCANprocess_logical_literal PROTO((char *)); -extern int SCANprocess_identifier_or_keyword PROTO((void)); -extern int SCANprocess_string PROTO((void)); -extern int SCANprocess_encoded_string PROTO((void)); -extern int SCANprocess_semicolon PROTO((int)); -extern void SCANsave_comment PROTO((void)); +extern int SCANprocess_identifier_or_keyword PROTO((const char *)); +extern int SCANprocess_string PROTO((const char *)); +extern int SCANprocess_encoded_string PROTO((const char *)); +extern int SCANprocess_semicolon PROTO((const char *, int)); +extern void SCANsave_comment PROTO((const char *)); extern Boolean SCANread PROTO((void)); #if macros_bit_the_dust extern void SCANdefine_macro PROTO((char *, char *)); Modified: brlcad/trunk/src/other/step/src/express/CMakeLists.txt =================================================================== --- brlcad/trunk/src/other/step/src/express/CMakeLists.txt 2011-12-21 22:14:46 UTC (rev 48120) +++ brlcad/trunk/src/other/step/src/express/CMakeLists.txt 2011-12-21 22:52:20 UTC (rev 48121) @@ -5,18 +5,12 @@ find_package(LEMON) LEMON_TARGET(ExpParser expparse.y expparse.c expparse.h) -LEX_TARGET(ExpScanner expscan.re ${CMAKE_CURRENT_BINARY_DIR}/expscan.c COMPILE_FLAGS "-l") +PERPLEX_TARGET(ExpScanner expscan.l ${CMAKE_CURRENT_BINARY_DIR}/expscan.c ${CMAKE_CURRENT_BINARY_DIR}/expscan.h) +ADD_PERPLEX_LEMON_DEPENDENCY(ExpScanner ExpParser) -# replace with ADD_RE2C_LEMON_DEPENDENCY(ExpScanner ExpParser) -# when expscan.re is really an re2c input and not a lex input -#MESSAGE(STATUS "depends on: ${LEMON_ExpParser_OUTPUT_HEADER}") -#MESSAGE(STATUS "outputs were: ${LEMON_ExpParser_OUTPUTS}") - -SET_SOURCE_FILES_PROPERTIES(${LEX_ExpScanner_OUTPUTS} PROPERTIES OBJECT_DEPENDS ${LEMON_ExpParser_OUTPUT_HEADER}) - set(EXPRESS_SOURCES ${LEMON_ExpParser_OUTPUT_SOURCE} - ${LEX_ExpScanner_OUTPUTS} + ${PERPLEX_ExpScanner_OUTPUTS} symbol.c type.c variable.c Modified: brlcad/trunk/src/other/step/src/express/expparse.y =================================================================== --- brlcad/trunk/src/other/step/src/express/expparse.y 2011-12-21 22:14:46 UTC (rev 48120) +++ brlcad/trunk/src/other/step/src/express/expparse.y 2011-12-21 22:52:20 UTC (rev 48121) @@ -2,6 +2,7 @@ %include { #include <assert.h> #include "token_type.h" +#include "parse_data.h" int yyerrstatus = 0; #define yyerrok (yyerrstatus = 0) @@ -98,6 +99,7 @@ #include "express/schema.h" #include "express/entity.h" #include "express/resolve.h" +#include "expscan.h" extern int print_objects_while_running; @@ -124,21 +126,15 @@ /* differentiated from other schemas parsed earlier */ Linked_List PARSEnew_schemas; - extern int yylineno; + int yylineno; static int PARSEchunk_start; - static void yyerror PROTO((char *)); - static void yyerror2 PROTO((char CONST *)); + static void yyerror(const char*, char *string); + static void yyerror2(const char*, char CONST *t); Boolean yyeof = False; -#ifdef FLEX - extern char *yytext; -#else /* LEX */ - extern char yytext[]; -#endif /*FLEX*/ - #define MAX_SCOPE_DEPTH 20 /* max number of scopes that can be nested */ static struct scope { @@ -195,6 +191,8 @@ } } /* include */ +%extra_argument { parse_data_t parseData } + %type case_action { Case_Item } %type case_otherwise { Case_Item } %type entity_body { struct entity_body } @@ -2026,7 +2024,7 @@ } if (EXPRESSignore_duplicate_schemas && schema) { - SCANskip_to_end_schema(); + SCANskip_to_end_schema(parseData.scanner); PUSH_SCOPE_DUMMY(); } else { schema = SCHEMAcreate(); @@ -2461,13 +2459,12 @@ %include { static void -yyerror(string) -char *string; +yyerror(const char *yytext, char *string) { char buf[200]; Symbol sym; - strcpy (buf, string); + strcpy(buf, string); if (yyeof) { strcat(buf, " at end of input"); @@ -2486,8 +2483,7 @@ } static void -yyerror2(t) -char CONST *t; /* token or 0 to indicate no more tokens */ +yyerror2(const char *yytext, char CONST *t) /* token or 0 to indicate no more tokens */ { char buf[200]; Symbol sym; @@ -2515,7 +2511,7 @@ } if (0 == strlen(tokens)) { - yyerror("syntax error"); + yyerror(yytext, "syntax error"); } sym.line = yylineno - (yytext[0] == '\n'); sym.filename = current_filename; Modified: brlcad/trunk/src/other/step/src/express/express.c =================================================================== --- brlcad/trunk/src/other/step/src/express/express.c 2011-12-21 22:14:46 UTC (rev 48120) +++ brlcad/trunk/src/other/step/src/express/express.c 2011-12-21 22:52:20 UTC (rev 48121) @@ -82,10 +82,12 @@ #include "express/scope.h" #include "token_type.h" #include "expparse.h" +#include "expscan.h" +#include "parse_data.h" void *ParseAlloc(void *(*mallocProc)(size_t)); void ParseFree(void *parser, void (*freeProc)(void*)); -void Parse(void *parser, int tokenID, YYSTYPE data); +void Parse(void *parser, int tokenID, YYSTYPE data, parse_data_t parseData); Linked_List EXPRESS_path; int EXPRESSpass; @@ -232,7 +234,6 @@ char *KW_WHILE = "WHILE"; char *KW_XOR = "XOR"; -extern FILE *yyin; extern Express yyexpresult; static Error ERROR_ref_nonexistent; @@ -593,15 +594,17 @@ static /* start parsing a new schema file */ Express -PARSERrun(char *filename,FILE *fp) +PARSERrun(char *filename, FILE *fp) { extern void SCAN_lex_init PROTO((char *,FILE *)); extern YYSTYPE yylval; extern int yyerrstatus; int tokenID; + parse_data_t parseData; - /* FIXME: should be using bu_malloc */ void *parser = ParseAlloc(malloc); + perplex_t scanner = perplexFileScanner(fp); + parseData.scanner = scanner; if (print_objects_while_running & OBJ_PASS_BITS) { fprintf(stdout,"parse (pass 0)\n",EXPRESSpass); @@ -611,15 +614,14 @@ fprintf(stdout,"parse: %s (schema file)\n",filename); } - yyin = fp; - SCAN_lex_init(filename,fp); + SCAN_lex_init(filename, fp); parserInitState(); yyerrstatus = 0; - while ((tokenID = yylex()) > 0) { - Parse(parser, tokenID, yylval); + while ((tokenID = yylex(scanner)) > 0) { + Parse(parser, tokenID, yylval, parseData); } - Parse(parser, 0, yylval); + Parse(parser, 0, yylval, parseData); /* want 0 on success, 1 on invalid input, 2 on memory exhaustion */ if (yyerrstatus != 0) { @@ -630,7 +632,7 @@ } EXPRESSpass = 1; - /* FIXME: should be using bu_free */ + perplexFree(scanner); ParseFree(parser, free); return yyexpresult; Copied: brlcad/trunk/src/other/step/src/express/expscan.l (from rev 48075, brlcad/trunk/src/other/step/src/express/expscan.re) =================================================================== --- brlcad/trunk/src/other/step/src/express/expscan.l (rev 0) +++ brlcad/trunk/src/other/step/src/express/expscan.l 2011-12-21 22:52:20 UTC (rev 48121) @@ -0,0 +1,341 @@ +static char rcsid[] = "$Id: expscan.l,v 1.12 1997/05/29 20:17:34 sauderd Exp $"; + +/* + * Lex source for Fed-X lexical analyzer. + * + * This software was developed by U.S. Government employees as part of + * their official duties and is not subject to copyright. + * + * $Log: expscan.l,v $ + * Revision 1.12 1997/05/29 20:17:34 sauderd + * Made some changes to Symbol (to be Symbol_) and false and true to be False + * and True. These changes affect the generated expscan.c file so that it will + * compile. + * + * Revision 1.11 1994/11/22 18:32:39 clark + * Part 11 IS; group reference + * + * Revision 1.10 1994/05/12 17:22:23 libes + * added #ifdefs for flex + * + * Revision 1.9 1994/05/12 17:18:10 libes + * made flex understand multiple files + * + * Revision 1.8 1994/05/11 19:50:00 libes + * numerous fixes + * + * Revision 1.7 1993/10/15 18:47:26 libes + * CADDETC certified + * + * Revision 1.5 1993/02/22 21:46:33 libes + * fixed unmatched_open_comment handler + * + * Revision 1.4 1992/08/18 17:11:36 libes + * rm'd extraneous error messages + * + * Revision 1.3 1992/06/08 18:05:20 libes + * prettied up interface to print_objects_when_running + * + * Revision 1.2 1992/05/31 08:30:54 libes + * multiple files + * + * Revision 1.1 1992/05/28 03:52:25 libes + * Initial revision + * + * Revision 1.4 1992/05/05 19:49:03 libes + * final alpha + * + * Revision 1.3 1992/02/12 07:02:49 libes + * do sub/supertypes + * + * Revision 1.2 1992/02/09 00:49:04 libes + * does ref/use correctly + * + * Revision 1.1 1992/02/05 08:40:30 libes + * Initial revision + * + * Revision 1.0.1.1 1992/01/22 02:47:57 libes + * copied from ~pdes + * + * Revision 4.9 1991/06/14 20:49:12 libes + * removed old infinity, added backslash + * + * Revision 4.8.1.1 1991/05/16 04:07:57 libes + * made scanner (under lex) understand hooks for doing include directive + * + * Revision 4.8.1.0 1991/05/16 01:10:15 libes + * branch for fixes to old code + * + * Revision 4.8 1991/05/03 21:09:02 libes + * Added sanity check to make sure lex/flex match -DLEX/FLEX + * + * Revision 4.7 1991/05/02 05:49:18 libes + * fixed bug in testing for exceeding open_comment[nesting_level] + * + * Revision 4.6 1991/04/29 19:44:40 libes + * Print all open comments rather than just one. + * + * Revision 4.5 1991/04/29 15:39:02 libes + * Changed commenting style (back) as per SNC who claims that N9 meant to + * say that tail remarks cannot occur in an open comment, nor can nested + * comments begin in a tail remark. + * + * Revision 4.4 1991/04/29 15:01:46 libes + * Add bounds checking to nesting level history + * + * Revision 4.3 1991/04/26 20:12:50 libes + * Made scanner work with lex + * Simulated exclusive states with inclusive states + * Fixed line counting + * Speeded up whitespace matching + * Convert unknown chars to whitespace + * Disabled default rule matching (enabled "jamming") + * Enabled detection/diagnostics of unterminated comments and strings literals + * Enabled detection/diagnostics of unexpected close comments + * Disabled detection/diagnostics of nested comments + * + * Revision 4.2 1990/12/18 14:00:04 clark + * Cosmetic changes + * + * Revision 4.1 90/09/13 16:29:00 clark + * BPR 2.1 alpha + * + */ + +#include "express/basic.h" +#include "express/error.h" +#include "express/lexact.h" +#include "express/express.h" +#include "expparse.h" +#include "expscan.h" + +enum { INITIAL, code, comment, return_end_schema }; + +extern void yyerror(); +extern int yylineno; +extern Boolean yyeof; +static int nesting_level; + +/* can't imagine this will ever be more than 2 or 3 - DEL */ +#define MAX_NESTED_COMMENTS 20 +static struct Symbol_ open_comment[MAX_NESTED_COMMENTS]; + +static inline +int +SCANnextchar(char* buffer) +{ + extern Boolean SCANread(void); +#ifdef keep_nul + static int escaped = 0; +#endif + + if (SCANtext_ready || SCANread()) { +#ifdef keep_nul + if (!*SCANcurrent) { + buffer[0] = SCAN_ESCAPE; + *SCANcurrent = '0'; + return 1; + } else if ((*SCANcurrent == SCAN_ESCAPE) && !escaped) { + escaped = 1; + buffer[0] = SCAN_ESCAPE; + return 1; + } + SCANbuffer.numRead--; +#endif + buffer[0] = *(SCANcurrent++); + if (!isascii(buffer[0])) { + ERRORreport_with_line(ERROR_nonascii_char,yylineno, + 0xff & buffer[0]); + buffer[0] = ' '; /* substitute space */ + } + return 1; + } else + return 0; +} + +#undef yywrap +static int +yywrap() +{ + int i; + + for (i = 0; i < nesting_level && i < MAX_NESTED_COMMENTS; i++) { + ERRORreport_with_symbol(ERROR_unmatched_open_comment, + &open_comment[i]); + /* maybe not all, but at least some will be reported - DEL */ + } + return 1; +} + +#define NEWLINE (yylineno++) + +/* when lex looks ahead over a newline, error messages get thrown off */ +/* Fortunately, we know when that occurs, so adjust for it by this hack */ +#define LINENO_FUDGE (yylineno - 1) + +/* added for re-initializing parser -snc 22-Apr-1992 */ +void +SCAN_lex_init(char *filename, FILE *fp) { + int i; + + /* return to initial scan buffer */ + SCAN_current_buffer = 0; + *(SCANcurrent = SCANbuffer.text) = '\0'; + SCANbuffer.readEof = False; + SCANbuffer.file = fp; + SCANbuffer.filename = (filename ? filename : ""); + current_filename = SCANbuffer.filename; +} +%% +digit = [0-9]; +integer = digit+; +letter = [A-Za-z]; +id_char = [A-Za-z0-9_]; + +<> => code + +/* Added * at the end of next rule (to make lexer faster) - DEL */ +<*>[\t ]* { } +<*>'\n' { NEWLINE; } + +<code>"--"[^\n]*'\n' { + NEWLINE; + SCANsave_comment(yytext); +} + +<*>"(*" :=> comment { + /* nested comment errors will occur with most deeply nested - DEL */ + if (nesting_level < MAX_NESTED_COMMENTS) { + open_comment[nesting_level].line = yylineno; + open_comment[nesting_level].filename = current_filename; + } + nesting_level++; +} + +<code> { + +/* real literal (like, think it'll fly?!) */ +(integer)'.'(integer)?([eE][+-]?(integer))? { + return SCANprocess_real_literal(yytext); +} + +/* integer literal */ +integer { + return SCANprocess_integer_literal(yytext); +} + +/* binary literal */ +"\%"[01]+ { + return SCANprocess_binary_literal(yytext); +} + +/* identifier/keyword */ +(letter)(id_char)* { + return SCANprocess_identifier_or_keyword(yytext); +} + +/* bad identifier */ +[_A-Za-z]id_char* { + ERRORreport_with_line(ERROR_bad_identifier, yylineno, yytext); + return SCANprocess_identifier_or_keyword(yytext); +} + +/* string literal */ +"'"([^'\n]|"''")*"'" { + /* ' keep font-lock happy */ + return SCANprocess_string(yytext); +} + +"'"([^'\n]|"''")*'\n' { + ERRORreport_with_line(ERROR_unterminated_string, LINENO_FUDGE); + NEWLINE; + return SCANprocess_string(yytext); +} + +'"'[^\"\n]*'"' { + return SCANprocess_encoded_string(yytext); +} + +'"'[^\"\n]*'\n' { + ERRORreport_with_line(ERROR_unterminated_string, LINENO_FUDGE); + NEWLINE; + return SCANprocess_encoded_string(yytext); +} + +';'[ \t]*"--"[^\n]*'\n' { + NEWLINE; + return SCANprocess_semicolon(yytext, 1); +} + +";" { return SCANprocess_semicolon(yytext, 0); } +":=" { return TOK_ASSIGNMENT; } +":" { return TOK_COLON; } +"," { return TOK_COMMA; } +"||" { return TOK_CONCAT_OP; } +"." { return TOK_DOT; } +"=" { return TOK_EQUAL; } +"**" { return TOK_EXP; } +"|" { return TOK_SUCH_THAT; } +"<*" { return TOK_ALL_IN; } +">=" { return TOK_GREATER_EQUAL; } +">" { return TOK_GREATER_THAN; } +"?" { return TOK_QUESTION_MARK; } +":=:" { return TOK_INST_EQUAL; } +":<>:" { return TOK_INST_NOT_EQUAL; } +"[" { return TOK_LEFT_BRACKET; } +"{" { return TOK_LEFT_CURL; } +"(" { return TOK_LEFT_PAREN; } +"<=" { return TOK_LESS_EQUAL; } +"<" { return TOK_LESS_THAN; } +"-" { return TOK_MINUS; } +"<>" { return TOK_NOT_EQUAL; } +"+" { return TOK_PLUS; } +"/" { return TOK_REAL_DIV; } +"]" { return TOK_RIGHT_BRACKET; } +"}" { return TOK_RIGHT_CURL; } +")" { return TOK_RIGHT_PAREN; } +"*" { return TOK_TIMES; } +"\\" { return TOK_BACKSLASH; } + +} /* <code> */ + +<return_end_schema>'X' => code { + return TOK_END_SCHEMA; +} + +<comment>"*)" { + if (0 == --nesting_level) { + YYSETCONDITION(code); + } +} + +<code>"*)" { + ERRORreport_with_line(ERROR_unmatched_close_comment, yylineno); +} + +<comment> { + +'\n' { NEWLINE; } +[^*()\n]* { } +[*()] { } + +} /* <comment> */ + +/* As per N15, 7.1.5.3, all other recognized chars are incorrect - DEL */ +<code>[$%&@\^{}~] { + ERRORreport_with_line(ERROR_unexpected_character,yylineno,yytext[0]); +} + +/* ... and unrecognized characters are treated as whitespace - DEL */ +<*>[^] { } + +%% +void +SCANskip_to_end_schema(perplex_t scanner) +{ + while (yylex(scanner) != TOK_END_SCHEMA); + + perplexUnput(scanner, 'X'); /* any old character */ + + YYSETCONDITION(return_end_schema); +} Deleted: brlcad/trunk/src/other/step/src/express/expscan.re =================================================================== --- brlcad/trunk/src/other/step/src/express/expscan.re 2011-12-21 22:14:46 UTC (rev 48120) +++ brlcad/trunk/src/other/step/src/express/expscan.re 2011-12-21 22:52:20 UTC (rev 48121) @@ -1,478 +0,0 @@ -%{ - -static char rcsid[] = "$Id: expscan.l,v 1.12 1997/05/29 20:17:34 sauderd Exp $"; - -/* - * Lex source for Fed-X lexical analyzer. - * - * This software was developed by U.S. Government employees as part of - * their official duties and is not subject to copyright. - * - * $Log: expscan.l,v $ - * Revision 1.12 1997/05/29 20:17:34 sauderd - * Made some changes to Symbol (to be Symbol_) and false and true to be False - * and True. These changes affect the generated expscan.c file so that it will - * compile. - * - * Revision 1.11 1994/11/22 18:32:39 clark - * Part 11 IS; group reference - * - * Revision 1.10 1994/05/12 17:22:23 libes - * added #ifdefs for flex - * - * Revision 1.9 1994/05/12 17:18:10 libes - * made flex understand multiple files - * - * Revision 1.8 1994/05/11 19:50:00 libes - * numerous fixes - * - * Revision 1.7 1993/10/15 18:47:26 libes - * CADDETC certified - * - * Revision 1.5 1993/02/22 21:46:33 libes - * fixed unmatched_open_comment handler - * - * Revision 1.4 1992/08/18 17:11:36 libes - * rm'd extraneous error messages - * - * Revision 1.3 1992/06/08 18:05:20 libes - * prettied up interface to print_objects_when_running - * - * Revision 1.2 1992/05/31 08:30:54 libes - * multiple files - * - * Revision 1.1 1992/05/28 03:52:25 libes - * Initial revision - * - * Revision 1.4 1992/05/05 19:49:03 libes - * final alpha - * - * Revision 1.3 1992/02/12 07:02:49 libes - * do sub/supertypes - * - * Revision 1.2 1992/02/09 00:49:04 libes - * does ref/use correctly - * - * Revision 1.1 1992/02/05 08:40:30 libes - * Initial revision - * - * Revision 1.0.1.1 1992/01/22 02:47:57 libes - * copied from ~pdes - * - * Revision 4.9 1991/06/14 20:49:12 libes - * removed old infinity, added backslash - * - * Revision 4.8.1.1 1991/05/16 04:07:57 libes - * made scanner (under lex) understand hooks for doing include directive - * - * Revision 4.8.1.0 1991/05/16 01:10:15 libes - * branch for fixes to old code - * - * Revision 4.8 1991/05/03 21:09:02 libes - * Added sanity check to make sure lex/flex match -DLEX/FLEX - * - * Revision 4.7 1991/05/02 05:49:18 libes - * fixed bug in testing for exceeding open_comment[nesting_level] - * - * Revision 4.6 1991/04/29 19:44:40 libes - * Print all open comments rather than just one. - * - * Revision 4.5 1991/04/29 15:39:02 libes - * Changed commenting style (back) as per SNC who claims that N9 meant to - * say that tail remarks cannot occur in an open comment, nor can nested - * comments begin in a tail remark. - * - * Revision 4.4 1991/04/29 15:01:46 libes - * Add bounds checking to nesting level history - * - * Revision 4.3 1991/04/26 20:12:50 libes - * Made scanner work with lex - * Simulated exclusive states with inclusive states - * Fixed line counting - * Speeded up whitespace matching - * Convert unknown chars to whitespace - * Disabled default rule matching (enabled "jamming") - * Enabled detection/diagnostics of unterminated comments and strings literals - * Enabled detection/diagnostics of unexpected close comments - * Disabled detection/diagnostics of nested comments - * - * Revision 4.2 1990/12/18 14:00:04 clark - * Cosmetic changes - * - * Revision 4.1 90/09/13 16:29:00 clark - * BPR 2.1 alpha - * - */ - -#include "express/basic.h" -#include "express/error.h" -#include "express/lexact.h" -#include "express/express.h" -#include "expparse.h" - -extern void yyerror(); -extern int yylineno; -extern Boolean yyeof; -static int nesting_level; - -/* can't imagine this will ever be more than 2 or 3 - DEL */ -#define MAX_NESTED_COMMENTS 20 -static struct Symbol_ open_comment[MAX_NESTED_COMMENTS]; - -static inline -int -SCANnextchar(char* buffer) -{ - extern Boolean SCANread(void); -#ifdef keep_nul - static int escaped = 0; -#endif - - if (SCANtext_ready || SCANread()) { -#ifdef keep_nul - if (!*SCANcurrent) { - buffer[0] = SCAN_ESCAPE; - *SCANcurrent = '0'; - return 1; - } else if ((*SCANcurrent == SCAN_ESCAPE) && !escaped) { - escaped = 1; - buffer[0] = SCAN_ESCAPE; - return 1; - } - SCANbuffer.numRead--; -#endif - buffer[0] = *(SCANcurrent++); - if (!isascii(buffer[0])) { - ERRORreport_with_line(ERROR_nonascii_char,yylineno, - 0xff & buffer[0]); - buffer[0] = ' '; /* substitute space */ - } - return 1; - } else - return 0; -} - - -#undef yywrap -static int -yywrap() -{ - int i; - - for (i=0;i<nesting_level && i<MAX_NESTED_COMMENTS;i++) { - ERRORreport_with_symbol(ERROR_unmatched_open_comment, - &open_comment[i]); - /* maybe not all, but at least some will be reported - DEL */ - } - return 1; -} - -#ifdef FLEX_SCANNER - -#ifdef LEX -))))this line will generate an error during compilation intentionally - DEL -You used flex (in make_rules) but compiled with -DLEX (in Makefile)! -#endif - -#define YY_USER_INIT BEGIN code; /* DEL */ - -#undef YY_DECL -#define YY_DECL int yylex(void) - -/* here's the hook for the preprocessor */ -#undef YY_INPUT -#define YY_INPUT(buf, result, max_size) \ - (result) = SCANnextchar(buf) - -/* I don't believe this is used anymore, but not sure */ -/* in any case, experimental code above that attempts to skip over */ -/* initial non-Express code explicitly refers to YY_INPUT */ -#ifdef slow_yylineno -#undef YY_INPUT -#define YY_INPUT(buf,result,max_size) \ - result = (((buf[0] = getc(yyin)) == '\n') \ - ? (NEWLINE, 1) \ - : ((buf[0] == EOF) ? ((yyeof = True), YY_NULL) : 1)) -#endif /*slow_yylineno*/ - -/*#define NEWLINE ((SCANbol = SCANtell()), yylineno++)*/ -#define NEWLINE yylineno++ -#define LINENO_FUDGE yylineno - -#else /* !FLEX_SCANNER (i.e, LEX) */ - -#ifdef FLEX -))))this line will generate an error during compilation intentionally - DEL -You used lex (in make_rules) but compiled with -DFLEX (in Makefile)! -#endif - -#undef input -#undef unput - -/* max page size 100 is guaranteed, but lex code uses BUFSIZ! - DEL */ -static char unchar[BUFSIZ]; /* one char for lex unput storage */ -static char *unchar_p = unchar; /* whether unchar is in use */ - -static int first_time = True; - -static int -input() { - char c; - - if (unchar_p == unchar) { - /* no chars pushed back */ - if (!SCANnextchar(&c)) return(0); - if (c == '\n') { - yylineno++; -/* SCANbol = SCANtell();*/ - } - return(c); - } else { - unchar_p--; - if (*unchar_p == '\n') yylineno++; - return(*unchar_p); - } -} - -/* if paranoid, should check that bounds are never exceeded, but maybe */ -/* lex does this for us? lex is not documented well enough to know */ -#define unput(c) {yytchar=(c);if(yytchar=='\n')yylineno--;*unchar_p++=yytchar;} -/* really shouldn't use yytchar since it isn't part of the defined interface */ - - -/* lex counts line for us, so turn this into a no-op - DEL */ -#define NEWLINE -/* when lex looks ahead over a newline, error messages get thrown off */ -/* Fortunately, we know when that occurs, so adjust for it by this hack */ -#define LINENO_FUDGE (yylineno-1) - -#endif - -#ifdef FLEX_SCANNER -void exp_flex_init(); -#endif - -/* added for re-initializing parser -snc 22-Apr-1992 */ -void -SCAN_lex_init(char *filename,FILE *fp) { - int i; - - /* return to initial scan buffer */ - SCAN_current_buffer = 0; - *(SCANcurrent = SCANbuffer.text) = '\0'; - SCANbuffer.readEof = False; - SCANbuffer.file = fp; - SCANbuffer.filename = (filename?filename:""); - current_filename = SCANbuffer.filename; - - /* empty all scan buffers */ -/* for (i = 0; i < SCAN_NESTING_DEPTH; ++i)*/ -/* SCAN_buffers[i].text[0] = '\0';*/ - -#ifdef FLEX_SCANNER - exp_flex_init(); -#endif - -#ifndef FLEX_SCANNER - /* initialize un-got character pointer to start of buffer */ - unchar_p = unchar; - - first_time = True; -#endif -} - - -%} - -%s comment code return_end_schema - -digit [0-9] -integer {digit}+ -letter [A-Za-z] -id_char [A-Za-z0-9_] - -%% - -%{ -#ifndef FLEX_SCANNER -if (first_time) { - BEGIN code; - first_time = False; -} -#endif -%} - -%{ -/* Added * at the end of next rule (to make lexer faster) - DEL */ -%} -[\t ]* ; -\n { NEWLINE; } - -<code>"--"[^\n]*\n { NEWLINE; SCANsave_comment(); } - -"(*" { - /* nested comment errors will occur with most deeply nested - DEL */ - if (nesting_level < MAX_NESTED_COMMENTS) { - open_comment[nesting_level].line = yylineno; - open_comment[nesting_level].filename = current_filename; - } - nesting_level++; - BEGIN comment; -} - -%{ -/* real literal (like, think it'll fly?!) */ -%} - -<code>{integer}"."{integer}?([eE][+-]?{integer})? { - return SCANprocess_real_literal(); -} - -%{ -/* integer literal */ -%} - -<code>{integer} { - return SCANprocess_integer_literal(); -} - -%{ -/* binary literal */ -%} - -<code>"\%"[01]+ { - return SCANprocess_binary_literal(); -} - -%{ -/* identifier/keyword */ -%} - -<code>{letter}{id_char}* { - return SCANprocess_identifier_or_keyword(); -} - -%{ -/* bad identifier */ -%} - -<code>[_A-Za-z]{id_char}* { - ERRORreport_with_line(ERROR_bad_identifier,yylineno,yytext); - return SCANprocess_identifier_or_keyword(); -} - -%{ -/* string literal */ -%} - -<code>'([^'\n]|'')*' { /* ' keep font-lock happy */ - return SCANprocess_string(); -} - -<code>'([^'\n]|'')*\n { - ERRORreport_with_line(ERROR_unterminated_string,LINENO_FUDGE); - NEWLINE; - return SCANprocess_string(); -} - -<code>\"[^\"\n]*\" { - return SCANprocess_encoded_string(); -} - -<code>\"[^\"\n]*\n { - ERRORreport_with_line(ERROR_unterminated_string,LINENO_FUDGE); - NEWLINE; - return SCANprocess_encoded_string(); -} - - -<code>";"[ \t]*"--"[^\n]*\n { - NEWLINE; - return SCANprocess_semicolon(1); -} -<code>";" { return SCANprocess_semicolon(0); } - -<code>":=" { return TOK_ASSIGNMENT; } -<code>":" { return TOK_COLON; } -<code>"," { return TOK_COMMA; } -<code>"||" { return TOK_CONCAT_OP; } -<code>"." { return TOK_DOT; } -<code>"=" { return TOK_EQUAL; } -<code>"**" { return TOK_EXP; } -<code>"|" { return TOK_SUCH_THAT; } -<code>"<*" { return TOK_ALL_IN; } -<code>">=" { return TOK_GREATER_EQUAL; } -<code>">" { return TOK_GREATER_THAN; } -<code>"?" { return TOK_QUESTION_MARK; } -<code>":=:" { return TOK_INST_EQUAL; } -<code>":<>:" { return TOK_INST_NOT_EQUAL; } -<code>"[" { return TOK_LEFT_BRACKET; } -<code>"{" { return TOK_LEFT_CURL; } -<code>"(" { return TOK_LEFT_PAREN; } -<code>"<=" { return TOK_LESS_EQUAL; } -<code>"<" { return TOK_LESS_THAN; } -<code>"-" { return TOK_MINUS; } -<code>"<>" { return TOK_NOT_EQUAL; } -<code>"+" { return TOK_PLUS; } -<code>"/" { return TOK_REAL_DIV; } -<code>"]" { return TOK_RIGHT_BRACKET; } -<code>"}" { return TOK_RIGHT_CURL; } -<code>")" { return TOK_RIGHT_PAREN; } -<code>"*" { return TOK_TIMES; } -<code>"\\" { return TOK_BACKSLASH; } - -<return_end_schema>X { - BEGIN code; - return TOK_END_SCHEMA; -} - -<comment>"*)" { - if (0 == --nesting_level) BEGIN code; -} - -<code>"*)" { - ERRORreport_with_line(ERROR_unmatched_close_comment,yylineno); -} - -<comment>\n { NEWLINE; } -<comment>[^*()\n]* ; -<comment>[*()] ; - -%{ -/* As per N15, 7.1.5.3, all other recognized chars are incorrect - DEL */ -%} -<code>[$%&@\^{}~] { - ERRORreport_with_line(ERROR_unexpected_character,yylineno,yytext[0]); -} - -%{ -/* ... and unrecognized characters are treated as whitespace - DEL */ -%} -. ; - -%% -void -SCANskip_to_end_schema() -{ - while (yylex() != TOK_END_SCHEMA); - - unput('X'); /* any old character */ - - BEGIN return_end_schema; -} - -#ifdef FLEX_SCANNER -/* required because yy_init isn't known when we need to re-init it */ -void -exp_flex_init() -{ - /* yy_init is what tells flex to reinitialize its buffers */ - -# if (YY_FLEX_MAJOR_VERSION==2 && YY_FLEX_MINOR_VERSION==5 && YY_FLEX_SUBMINOR_VERSION>=33) - /* flex 2.5.33 flips the polarity of this flag */ - yy_init = 0; -# else - yy_init = 1; -# endif -} -#endif Modified: brlcad/trunk/src/other/step/src/express/lexact.c =================================================================== --- brlcad/trunk/src/other/step/src/express/lexact.c 2011-12-21 22:14:46 UTC (rev 48120) +++ brlcad/trunk/src/other/step/src/express/lexact.c 2011-12-21 22:52:20 UTC (rev 48121) @@ -1,6 +1,3 @@ -#include "token_type.h" -extern YYSTYPE yylval; - static char rcsid[] = "$Id: lexact.c,v 1.10 1997/09/24 20:05:38 dar Exp $"; /* @@ -58,16 +55,19 @@ #include <ctype.h> /*#include <strings.h>*/ #include "express/lexact.h" - #include "string.h" #include "express/linklist.h" #include "stack.h" #include "express/hash.h" #include "express/express.h" -#include "expparse.h" #include "express/dict.h" #include "express/memory.h" +#include "token_type.h" +#include "expparse.h" +#include "expscan.h" +extern YYSTYPE yylval; + Scan_Buffer SCAN_buffers[SCAN_NESTING_DEPTH]; int SCAN_current_buffer = 0; char* SCANcurrent; @@ -84,14 +84,7 @@ extern int yylineno; -extern FILE* yyin; -#ifdef FLEX -extern char* yytext; -#else /* LEX */ -extern char yytext[]; -#endif /*FLEX*/ - #define SCAN_COMMENT_LENGTH 256 static char last_comment_[256] = ""; static char *last_comment = 0; @@ -303,23 +296,23 @@ } int -SCANprocess_real_literal(void) +SCANprocess_real_literal(const char *yytext) { sscanf(yytext, "%lf", &(yylval.rVal)); return TOK_REAL_LITERAL; } int -SCANprocess_integer_literal(void) +SCANprocess_integer_literal(const char *yytext) { sscanf(yytext, "%d", &(yylval.iVal)); return TOK_INTEGER_LITERAL; } int -SCANprocess_binary_literal(void) +SCANprocess_binary_literal(const char *yytext) { - yylval.binary = SCANstrdup(yytext+1); /* drop '%' prefix */ + yylval.binary = SCANstrdup(yytext + 1); /* drop '%' prefix */ return TOK_BINARY_LITERAL; } @@ -337,21 +330,21 @@ } int -SCANprocess_identifier_or_keyword(void) +SCANprocess_identifier_or_keyword(const char *yytext) { char *test_string; struct keyword_entry *k; - int len; - char *src, *dest; + int len; + char *src, *dest; - /* make uppercase copy */ - len = strlen(yytext); - dest = test_string = (char *)malloc(len+1); - for (src=yytext;*src;src++,dest++) { - *dest = (islower(*src)?toupper(*src):*src); - } - *dest = '\0'; + /* make uppercase copy */ + len = strlen(yytext); + dest = test_string = (char *)malloc(len+1); + for (src=yytext;*src;src++,dest++) { + *dest = (islower(*src)?toupper(*src):*src); + } + *dest = '\0'; /* check for language keywords */ k = (struct keyword_entry *)DICTlookup(keyword_dictionary,test_string); @@ -406,18 +399,18 @@ } int -SCANprocess_string(void) +SCANprocess_string(const char *yytext) { char *s, *d; /* source, destination */ /* strip off quotes */ - yylval.string = SCANstrdup(yytext+1); /* remove 1st single quote */ + yylval.string = SCANstrdup(yytext + 1); /* remove 1st single quote */ /* change pairs of quotes to single quotes */ for (s = d = yylval.string;*s;) { if (*s != '\'') { *d++ = *s++; - } else if (0 == strncmp(s,"''",2)) { + } else if (0 == strncmp(s, "''", 2)) { *d++ = '\''; s += 2; } else if (*s == '\'') { @@ -434,13 +427,13 @@ } int -SCANprocess_encoded_string(void) +SCANprocess_encoded_string(const char *yytext) { char *s, *d; /* source, destination */ int count; /* strip off quotes */ - yylval.string = SCANstrdup(yytext+1); /* remove 1st double quote */ + yylval.string = SCANstrdup(yytext + 1); /* remove 1st double quote */ s = strrchr(yylval.string,'"'); if (s) *s = '\0'; /* remove last double quote */ @@ -462,8 +455,9 @@ } int -SCANprocess_semicolon(int commentp) +SCANprocess_semicolon(const char *yytext, int commentp) { + if (commentp) { strcpy(last_comment_, strchr(yytext, '-')); yylval.string = last_comment_; @@ -479,7 +473,7 @@ } void -SCANsave_comment(void) +SCANsave_comment(const char *yytext) { strcpy(last_comment_, yytext); last_comment = last_comment; @@ -523,7 +517,7 @@ if (SCAN_current_buffer == 0) { done = True; fclose(SCANbuffer.file); /* close yyin */ - SCANbuffer.file = yyin = NULL; + SCANbuffer.file = NULL; } else { SCANpop_buffer(); } Added: brlcad/trunk/src/other/step/src/express/parse_data.h =================================================================== --- brlcad/trunk/src/other/step/src/express/parse_data.h (rev 0) +++ brlcad/trunk/src/other/step/src/express/parse_data.h 2011-12-21 22:52:20 UTC (rev 48121) @@ -0,0 +1,7 @@ +#ifndef PARSE_DATA +#define PARSE_DATA +#include "expscan.h" +typedef struct parse_data { + perplex_t scanner; +} parse_data_t; +#endif Property changes on: brlcad/trunk/src/other/step/src/express/parse_data.h ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Modified: brlcad/trunk/src/other/step/src/express/yyvars.c =================================================================== --- brlcad/trunk/src/other/step/src/express/yyvars.c 2011-12-21 22:14:46 UTC (rev 48120) +++ brlcad/trunk/src/other/step/src/express/yyvars.c 2011-12-21 22:52:20 UTC (rev 48121) @@ -18,8 +18,6 @@ #include <stdio.h> -/* FILE *yyin = {stdin}, *yyout = {stdout}; */ - int expyylineno = 1; void Modified: brlcad/trunk/src/other/step.dist =================================================================== --- brlcad/trunk/src/other/step.dist 2011-12-21 22:14:46 UTC (rev 48120) +++ brlcad/trunk/src/other/step.dist 2011-12-21 22:52:20 UTC (rev 48121) @@ -20,8 +20,9 @@ src/express/README src/express/conf.h src/express/expparse.y -src/express/expscan.re +src/express/expscan.l src/express/exptoks.h +src/express/parse_data.h src/express/stack.h src/express/token_type.h src/express/y.tok.h This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |