X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=src%2Fftacmp%2Ffta.l;h=bb2b76947000bd633614979d7df2d40d5c40acba;hb=f6f278dfd4bca7effd6f452d38ce74cf109d41f4;hp=fcdd28f2079ad222a55bd2b2c1a0624f44d590c2;hpb=07495effe193ca3f73c3bf0ce417068f9ac9dcdd;p=com%2Fgs-lite.git diff --git a/src/ftacmp/fta.l b/src/ftacmp/fta.l index fcdd28f..bb2b769 100644 --- a/src/ftacmp/fta.l +++ b/src/ftacmp/fta.l @@ -1,313 +1,315 @@ -/* ------------------------------------------------ -Copyright 2014 AT&T Intellectual Property - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - ------------------------------------------- */ - - -/* - MUST COMPILE WITH - flex -PFtaParser -oftalexer.cc fta.l - (or equivalent). -*/ - -%{ -/* - * AT&T lex can't handle this lexer due to lex bugs. It works with flex - * 2.3.7, pclex 2.0.5, and MKS lex 3.1a. - */ - - #include "parse_fta.h" - #include "parse_schema.h" - #include - - - -#include "fta.tab.cc.h" - -/* - Some includes that flex doesn't include as standard, - but which are needed. -*/ - -#include -#include - - -// Prevent flex from defining yywrap as extern "C" - -#define YY_SKIP_YYWRAP - -/* No lex lib, supply the yywrap fcn. that normally resides there -*/ - -int FtaParserwrap(){return(1);} - -extern int FtaParserdebug; - - -/* - These variables are used for error reporting: - flex_fta_lineno : the line currently being parsed when the error occurs. - flex_fta_ch : the character on the line where the error occurs - flex_fta_linebuf : store the line for reporting. - - NOTE : 1) the fixed size flex_fta_linebuf buffer is dangerous. - 2) You might get pointed to a place shortly after - where the syntax error occurs. It is close enough - for now. -*/ - -int flex_fta_lineno = 1; -int flex_fta_ch = 0; -char flex_fta_linebuf[200000]; - -char *flex_fta_stringinput = NULL; -int flex_fta_stringinput_ptr = 0; -FILE *flex_fta_fileinput = NULL; -int my_FtaParser_yyinput(char *buf, int max_size); - - - -void FtaParsererror(char *s){ - int i; - fprintf(stderr,"On line %d, char %d: %s (token %s):\n%s\n", - flex_fta_lineno, flex_fta_ch, s, FtaParsertext, flex_fta_linebuf ); - for(i=0;i>" { flex_fta_ch+=FtaParserleng; FtaParserlval.strval = strdup(yytext); return SHIFT_OP; } - -"=" | -"<>" | -"<" | -">" | -"<=" | -">=" { flex_fta_ch+=FtaParserleng; FtaParserlval.strval = strdup(yytext); return COMPARISON; } - -[%&|!+*/:(),.\[\]$@#] { flex_fta_ch+=FtaParserleng; return yytext[0]; } -"-" { flex_fta_ch+=FtaParserleng; return yytext[0]; } -"~" { flex_fta_ch+=FtaParserleng; return yytext[0]; } - - /* names */ - -[A-Za-z_][A-Za-z0-9_]* { flex_fta_ch+=FtaParserleng; FtaParserlval.strval = strdup(yytext); return NAME; } - - /* numbers */ - -[0-9]+ | -[0-9]+UL { flex_fta_ch+=FtaParserleng; FtaParserlval.strval = strdup(yytext); return INTNUM; } - -[0-9]+ULL { flex_fta_ch+=FtaParserleng; FtaParserlval.strval = strdup(yytext); return LONGINTNUM; } - -[0-9]+"."[0-9]* | -"."[0-9]* | -[0-9]+[eE][+-]?[0-9]+ | -[0-9]+"."[0-9]*[eE][+-]?[0-9]+ | -"."[0-9]*[eE][+-]?[0-9]+ { flex_fta_ch+=FtaParserleng; FtaParserlval.strval = strdup(yytext); return APPROXNUM; } - - /* strings */ - -'[^'\n]*' { - - int c; - - FtaParserlval.strval = strdup(FtaParsertext+1); - - c = yyinput(); - - unput(c); /* just peeking */ - if(c != '\'') { - flex_fta_ch+=FtaParserleng; - FtaParserlval.strval[FtaParserleng-2] = '\0'; - return STRING_TOKEN; - } else - yymore(); - } - -'[^'\n]*$ { flex_fta_ch+=FtaParserleng; FtaParsererror("Unterminated string"); } - - /* */ - /* Newline : advance the error reporting line number */ - /* and grab the next line into flex_fta_linebuf */ - /* */ - -\n.* {flex_fta_ch=0; flex_fta_lineno++; - strcpy(flex_fta_linebuf,FtaParsertext+1); - yyless(1); - } - -[ \t\r]+ {flex_fta_ch+=FtaParserleng; } /* white space */ - -"--".*$ {flex_fta_ch+=FtaParserleng; }; /* comment */ -"//".*$ {flex_fta_ch+=FtaParserleng; }; /* comment */ - -.|\n {flex_fta_ch+=FtaParserleng; fprintf(stderr,"Warning: unknown token (ignored)\n"); FtaParsererror(yytext);} - -%% - -int my_FtaParser_yyinput(char *buf, int max_size){ - int c = 0; - int inchar = 0; - - if(flex_fta_stringinput != NULL){ - while(c + + + +#include "fta.tab.cc.h" + +/* + Some includes that flex doesn't include as standard, + but which are needed. +*/ + +#include +#include + + +// Prevent flex from defining yywrap as extern "C" + +#define YY_SKIP_YYWRAP + +/* No lex lib, supply the yywrap fcn. that normally resides there +*/ + +//int FtaParserwrap(){return(1);} + +extern int FtaParserdebug; + + +/* + These variables are used for error reporting: + flex_fta_lineno : the line currently being parsed when the error occurs. + flex_fta_ch : the character on the line where the error occurs + flex_fta_linebuf : store the line for reporting. + + NOTE : 1) the fixed size flex_fta_linebuf buffer is dangerous. + 2) You might get pointed to a place shortly after + where the syntax error occurs. It is close enough + for now. +*/ + +int flex_fta_lineno = 1; +int flex_fta_ch = 0; +char flex_fta_linebuf[200000]; + +char *flex_fta_stringinput = NULL; +int flex_fta_stringinput_ptr = 0; +FILE *flex_fta_fileinput = NULL; +int my_FtaParser_yyinput(char *buf, int max_size); + + + +void FtaParsererror(char *s){ + int i; + fprintf(stderr,"On line %d, char %d: %s (token %s):\n%s\n", + flex_fta_lineno, flex_fta_ch, s, FtaParsertext, flex_fta_linebuf ); + for(i=0;i>" { flex_fta_ch+=FtaParserleng; FtaParserlval.strval = strdup(yytext); return SHIFT_OP; } + +"=" | +"<>" | +"<" | +">" | +"<=" | +">=" { flex_fta_ch+=FtaParserleng; FtaParserlval.strval = strdup(yytext); return COMPARISON; } + +[%&|!+*/:(),.\[\]$@#] { flex_fta_ch+=FtaParserleng; return yytext[0]; } +"-" { flex_fta_ch+=FtaParserleng; return yytext[0]; } +"~" { flex_fta_ch+=FtaParserleng; return yytext[0]; } + + /* names */ + +[A-Za-z_][A-Za-z0-9_]* { flex_fta_ch+=FtaParserleng; FtaParserlval.strval = strdup(yytext); return NAME; } + + /* numbers */ + +[0-9]+ | +[0-9]+UL { flex_fta_ch+=FtaParserleng; FtaParserlval.strval = strdup(yytext); return INTNUM; } + +[0-9]+ULL { flex_fta_ch+=FtaParserleng; FtaParserlval.strval = strdup(yytext); return LONGINTNUM; } + +[0-9]+"."[0-9]* | +"."[0-9]* | +[0-9]+[eE][+-]?[0-9]+ | +[0-9]+"."[0-9]*[eE][+-]?[0-9]+ | +"."[0-9]+[eE][+-]?[0-9]+ { flex_fta_ch+=FtaParserleng; FtaParserlval.strval = strdup(yytext); return APPROXNUM; } + + /* strings */ + +'[^'\n]*' { + + int c; + + FtaParserlval.strval = strdup(FtaParsertext+1); + + c = yyinput(); + + unput(c); /* just peeking */ + if(c != '\'') { + flex_fta_ch+=FtaParserleng; + FtaParserlval.strval[FtaParserleng-2] = '\0'; + return STRING_TOKEN; + } else + yymore(); + } + +'[^'\n]*$ { flex_fta_ch+=FtaParserleng; FtaParsererror("Unterminated string"); } + + /* */ + /* Newline : advance the error reporting line number */ + /* and grab the next line into flex_fta_linebuf */ + /* */ + +\n.* {flex_fta_ch=0; flex_fta_lineno++; + strcpy(flex_fta_linebuf,FtaParsertext+1); + yyless(1); + } + +[ \t\r]+ {flex_fta_ch+=FtaParserleng; } /* white space */ + +"--".*$ {flex_fta_ch+=FtaParserleng; }; /* comment */ +"//".*$ {flex_fta_ch+=FtaParserleng; }; /* comment */ + +.|\n {flex_fta_ch+=FtaParserleng; fprintf(stderr,"Warning: unknown token (ignored)\n"); FtaParsererror(yytext);} + +%% + +int my_FtaParser_yyinput(char *buf, int max_size){ + int c = 0; + int inchar = 0; + + if(flex_fta_stringinput != NULL){ + while(c