| 1 | %{ |
|---|
| 2 | //======================================================================= |
|---|
| 3 | // Copyright 2001 University of Notre Dame. |
|---|
| 4 | // Author: Lie-Quan Lee |
|---|
| 5 | // |
|---|
| 6 | // Distributed under the Boost Software License, Version 1.0. (See |
|---|
| 7 | // accompanying file LICENSE_1_0.txt or copy at |
|---|
| 8 | // http://www.boost.org/LICENSE_1_0.txt) |
|---|
| 9 | //======================================================================= |
|---|
| 10 | |
|---|
| 11 | // Include this first, since it declares YYSTYPE which will |
|---|
| 12 | // be defined in "*parser.h" if not previosly declared here. |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | #include "yystype.h" |
|---|
| 16 | #define YY_DECL int yylex(YYSTYPE* lvalp) |
|---|
| 17 | |
|---|
| 18 | // When GRAPHVIZ_DIRECTED is declared it means Boost.Build is used. |
|---|
| 19 | // Headers for directed and undirected graphs are both generated, and |
|---|
| 20 | // have different names. |
|---|
| 21 | #ifdef GRAPHVIZ_DIRECTED |
|---|
| 22 | #if GRAPHVIZ_DIRECTED == 0 |
|---|
| 23 | #define yyerror bgl_undir_error |
|---|
| 24 | #include "graphviz_graph_parser.hpp" |
|---|
| 25 | #else |
|---|
| 26 | #define yyerror bgl_dir_error |
|---|
| 27 | #include "graphviz_digraph_parser.hpp" |
|---|
| 28 | #endif |
|---|
| 29 | #else |
|---|
| 30 | #error Need to define the GRAPHVIZ_DIRECTED macro to either 0 or 1 |
|---|
| 31 | #endif |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | #include <string> |
|---|
| 35 | #include <iostream> |
|---|
| 36 | |
|---|
| 37 | static std::string literal; |
|---|
| 38 | static void begin_literal(); |
|---|
| 39 | static void add_string(const char* str); |
|---|
| 40 | static void end_literal(); |
|---|
| 41 | |
|---|
| 42 | %} |
|---|
| 43 | |
|---|
| 44 | %option noyywrap |
|---|
| 45 | %x Comment |
|---|
| 46 | %x Literal |
|---|
| 47 | |
|---|
| 48 | DIGIT [0-9] |
|---|
| 49 | ALPHABET [a-zA-Z_] |
|---|
| 50 | NUMBER [-+]?({DIGIT}+(\.{DIGIT}*)?|\.{DIGIT}+)([eE][-+]?{DIGIT}+)? |
|---|
| 51 | VARIABLE {ALPHABET}+({DIGIT}|{ALPHABET})* |
|---|
| 52 | ID {VARIABLE}|{NUMBER} |
|---|
| 53 | |
|---|
| 54 | %% |
|---|
| 55 | |
|---|
| 56 | "/*" { BEGIN Comment; } |
|---|
| 57 | <Comment>"*/" { BEGIN INITIAL; } |
|---|
| 58 | <Comment>.* ; |
|---|
| 59 | "//".*$ ; |
|---|
| 60 | "#".*$ ; |
|---|
| 61 | "digraph" { return DIGRAPH_T; } |
|---|
| 62 | "graph" { return GRAPH_T; } |
|---|
| 63 | "node" { return NODE_T; } |
|---|
| 64 | "edge" { return EDGE_T; } |
|---|
| 65 | "strict" ; |
|---|
| 66 | "subgraph" { return SUBGRAPH_T; } |
|---|
| 67 | "->"|"--" { return EDGEOP_T; } |
|---|
| 68 | {ID} { lvalp->ptr = (void*)(new std::string(yytext)); return ID_T; } |
|---|
| 69 | ["] { BEGIN Literal; begin_literal(); } |
|---|
| 70 | <Literal>["] { BEGIN INITIAL; end_literal(); lvalp->ptr = (void*)(new std::string(literal)); return ID_T; } |
|---|
| 71 | <Literal>[\\][\n] ; |
|---|
| 72 | <Literal>([^"\\]*|[\\].) { add_string(yytext); } |
|---|
| 73 | [ \t] ; |
|---|
| 74 | \n ; |
|---|
| 75 | \r ; |
|---|
| 76 | . { return yytext[0]; } |
|---|
| 77 | %% |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | void begin_literal() { |
|---|
| 81 | literal = ""; |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | void add_string(const char* str) { |
|---|
| 85 | literal += str; |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | void end_literal() { |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | void yyerror(char *str) |
|---|
| 92 | { |
|---|
| 93 | std::cout << str << std::endl; |
|---|
| 94 | } |
|---|