Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

protomake.l

Go to the documentation of this file.
00001 %{
00008 #include <map>
00009 #include <stdio.h>
00010 #include <stdlib.h>
00011 #include <string.h>
00012 using namespace std;
00013 
00014 #include "nodes/protomake.h"
00015 enum EtherType {AUTHOR, EMAIL, NAME, PORT, TRANSPORT};
00016 struct EtherInfoType
00017 {
00018     EtherType type;
00019     char *string;
00020 };
00021 
00023 #include "protomakeParse.hpp"
00024 
00026 int lines;
00027 
00032 static char *formatMultiString(char *);
00033 %}
00034 
00035 id                      [a-zA-Z][a-zA-Z0-9]*
00036 
00037 string          \"[^\"\n]*\"
00038 termString      \/[^\"\n]+\/
00039 pString         [^\"\n]*[ \t]*
00040 mString         \"({pString}\\\n)+{pString}\"
00041 number          [0-9]+
00042 white           [ \t]
00043 
00044 %%
00045 
00046 #.*\n           { /** Coments */ lines++; }
00047 external    { return tEXTERNAL; }
00048 message         { return tMESSAGE; }
00049 import          { return tIMPORT; }
00050 begin           { return tBEGIN; }
00051 end                     { return tEND; }
00052 bits            { return tBITS; }
00053 bytes           { return tBYTES; }
00054 string          { return tSTRTYPE; }
00055 blanks          { return tBLANKS; }
00056 process         { return tPROCESS; }
00057 global          { return tGLOBAL; }
00058 const           { return tCONST; }
00059 var                     { return tVAR; }
00060 integer         { return tINTEGER; }
00061 address         { return tADDRESS; }
00062 client_address  { return tCLIENTADDRESS; }
00063 server_address  { return tSERVERADDRESS; }
00064 array           { return tARRAY; }
00065 of                      { return tOF; }
00066 rcv                     { return tRCV; }
00067 from            { return tFROM; }
00068 timeout         { return tTIMEOUT; }
00069 skip            { return tSKIP; }
00070 send            { return tSEND; }
00071 to                      { return tTO; }
00072 if                      { return tIF; }
00073 fi                      { return tFI; }
00074 do                      { return tDO; }
00075 od                      { return tOD; }
00076 act                     { return tACT; }
00077 in                      { return tIN; }
00078 start           { return tSTART; }
00079 stop            { return tSTOP; }
00080 behavior        { return tBEHAVIOR; }
00081 
00082 "+"                     { yylval.string = strdup(yytext); return tPLUS; }
00083 "-"                     { yylval.string = strdup(yytext); return tMINUS; }
00084 "*"                     { yylval.string = strdup(yytext); return tTIMES; }
00085 "/"                     { yylval.string = strdup(yytext); return tDIVIDE; }
00086 "&"                     { yylval.string = strdup(yytext); return tBAND; }
00087 "|"                     { yylval.string = strdup(yytext); return tBOR; }
00088 "~"                     { yylval.string = strdup(yytext); return tNEG; }
00089 "<>"            { yylval.string = strdup(yytext); return tDIFFERENT; }
00090 "<="            { yylval.string = strdup(yytext); return tLTE; }
00091 ">="            { yylval.string = strdup(yytext); return tGTE; }
00092 "="                     { yylval.string = strdup(yytext); return tEQUAL; }
00093 "<"                     { yylval.string = strdup(yytext); return tLT; }
00094 ">"                     { yylval.string = strdup(yytext); return tGT; }
00095 "[]"            { return tGUARD; }
00096 "["                     { return tLBRACKET; }
00097 "]"                     { return tRBRACKET; }
00098 "("                     { return tLPAR; }
00099 ")"                     { return tRPAR; }
00100 ","                     { return tCOMMA; }
00101 ":"                     { return tCOLON; }
00102 ";"                     { return tSCOLON; }
00103 "->"            { return tACTION; }
00104 "."                     { return tDOT; }
00105 ".."            { return tRANGE; }
00106 ":="            { return tASSIGN; }
00107 
00108 {number}        { yylval.number = atoi(yytext); return tNUMBER; }
00109 {id}            { yylval.string = strdup(yytext); return tID; }
00110 {termString} { yylval.string = strdup(yytext); return tTERMSTRING; }
00111 {string}        { yylval.string = strdup(yytext); return tSTRING; }
00112 {mString}       { yylval.string = formatMultiString(yytext); return tSTRING; }
00113 
00114 
00115 {white}+        { /* ignore */ }
00116 \n                      { /** line counter */ lines++; }
00117 .                       { printf("Erro na linha %d: %s!\n", lines + 1, yytext); exit(0);}
00118 
00119 %%
00120 
00122 static char *formatMultiString(char *s)
00123 {
00124         char *str = (char *) malloc(strlen(s) + 1);     
00125         char *token;
00126 
00127         str[0] = '\0';
00128         token = strtok(s, "\\\n");
00129         do
00130         {
00131                 strcat(str, token);
00132         } while ((token = strtok(NULL, "\\\n")));
00133 
00134 
00135         return str;
00136 }

Generated on Mon Dec 1 17:36:18 2003 for Protomake by doxygen1.3