[38] | 1 | /* |
---|
| 2 | * conv_f8tof1_scanner.l |
---|
| 3 | * L-systemToF1 |
---|
| 4 | * |
---|
| 5 | * Created by Maciej Wajcht on 08-03-28. |
---|
| 6 | * Copyright 2008 __MyCompanyName__. All rights reserved. |
---|
| 7 | * |
---|
| 8 | */ |
---|
| 9 | %{ |
---|
| 10 | #include "lexglobal.h" |
---|
| 11 | #include "conv_f8tof1_grammar.h" |
---|
| 12 | #include <string.h> |
---|
| 13 | #include <math.h> |
---|
| 14 | |
---|
| 15 | YYSTYPE yylval; |
---|
| 16 | int line = 1, col = 1; |
---|
| 17 | //int yyFlexLexer::yywrap(void) { |
---|
| 18 | int yywrap(void) { |
---|
| 19 | return 1; |
---|
| 20 | } |
---|
| 21 | %} |
---|
| 22 | %% |
---|
| 23 | |
---|
| 24 | n[0-9]+ { col += yyleng; |
---|
| 25 | yylval.strVal = yytext; |
---|
| 26 | return PARAM_NAME; |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | P[0-9]+ { col += yyleng; |
---|
| 30 | yylval.strVal = yytext; |
---|
| 31 | return PROD_NAME; |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | -?[0-9]+(\.[0-9]+)? { col += yyleng; |
---|
| 35 | //yylval.dblVal = atof(yytext); |
---|
| 36 | yylval.strVal = yytext; |
---|
| 37 | return DOUBLE_VAL; |
---|
| 38 | } |
---|
| 39 | |
---|
[45] | 40 | [ \t\r]+ { col += yyleng; } /* ignore but count white space */ |
---|
[38] | 41 | |
---|
| 42 | "=" { col += yyleng; yylval.strVal = yytext; return ASSIGN; } |
---|
| 43 | |
---|
| 44 | "<" { col += yyleng; yylval.strVal = yytext; return LESS; } |
---|
| 45 | "<=" { col += yyleng; yylval.strVal = yytext; return LESS_EQUAL; } |
---|
| 46 | "==" { col += yyleng; yylval.strVal = yytext; return EQUAL; } |
---|
| 47 | "!=" { col += yyleng; yylval.strVal = yytext; return NOT_EQUAL; } |
---|
| 48 | ">=" { col += yyleng; yylval.strVal = yytext; return GREATER_EQUAL; } |
---|
| 49 | ">" { col += yyleng; yylval.strVal = yytext; return GREATER; } |
---|
| 50 | |
---|
[39] | 51 | [X\[\]\^RrLlAaCcFfMmSsIiQqWwEe] { col += yyleng; |
---|
[38] | 52 | yylval.strVal = yytext; |
---|
| 53 | return COMMAND; |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | \\\[.*\\\] { col += yyleng; |
---|
| 57 | yylval.strVal = yytext; |
---|
| 58 | return NEURON; |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | "{" { col += yyleng; yylval.strVal = yytext; return FORLOOP_BEGIN; } |
---|
| 62 | "}" { col += yyleng; yylval.strVal = yytext; return FORLOOP_END; } |
---|
| 63 | |
---|
| 64 | "(" { col += yyleng; yylval.strVal = yytext; return LPAREN; } |
---|
| 65 | ")" { col += yyleng; yylval.strVal = yytext; return RPAREN; } |
---|
| 66 | |
---|
| 67 | "-"{3} { col += yyleng; yylval.strVal = yytext; return DELIMETER; } |
---|
| 68 | |
---|
| 69 | ":" { col += yyleng; yylval.strVal = yytext; return SEMICOLON; } |
---|
| 70 | "|" { col += yyleng; yylval.strVal = yytext; return PIPE; } |
---|
| 71 | "," { col += yyleng; yylval.strVal = yytext; return COMMA; } |
---|
| 72 | |
---|
| 73 | "+" { col += yyleng; yylval.strVal = yytext; return PLUS; } |
---|
| 74 | "-" { col += yyleng; yylval.strVal = yytext; return MINUS; } |
---|
| 75 | "*" { col += yyleng; yylval.strVal = yytext; return TIMES; } |
---|
| 76 | "/" { col += yyleng; yylval.strVal = yytext; return DIV; } |
---|
| 77 | |
---|
| 78 | \n { col = 0; ++line; yylval.strVal = "\\n"; return NEWLINE; } |
---|
| 79 | |
---|
| 80 | . { col += yyleng; yylval.strVal = yytext; return -1; } |
---|
| 81 | |
---|
| 82 | %% |
---|
| 83 | /** |
---|
| 84 | * reset the line and column count |
---|
| 85 | */ |
---|
| 86 | void reset_lexer(void) |
---|
| 87 | { |
---|
| 88 | line = 1; |
---|
| 89 | col = 1; |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | /** |
---|
| 93 | * yyerror() is invoked when the lexer or the parser encounter |
---|
| 94 | * an error. The error message is passed via *s |
---|
| 95 | */ |
---|
| 96 | void yyerror(char *s) |
---|
| 97 | { |
---|
| 98 | printf("error: %s at line: %d col: %d\n",s,line,col); |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | /*int yywrap(void) |
---|
| 102 | { |
---|
| 103 | return 1; |
---|
| 104 | }*/ |
---|