This page shows the syntactic level and lexical level which the LFF parser uses to analyze LFF files.
The following grammar is presented in the YACC format. The terminal symbol are written as capital letters, while the not terminal symbol are written as small letters.
1 file : header packet_formats trailer
2 hdr_init : HEADER
3 header : hdr_init structs ENDHH hdefs
4 trailer : TRAILER structs ENDHT
6 packet_formats : pheader pdefs psdefs pudefs pwdefs pddefs $$1 ptrailer
8 packet_formats : packet_formats pheader pdefs psdefs pudefs pwdefs pddefs $$2 ptrailer
9 pheader : PHEADER structs ENDPH
10 ptrailer : PTRAILER structs ENDPT
11 str : str def
12 | def
13 structs : str
14 |
15 def : BYTE NAME
16 | WORD NAME
17 | DWORD NAME
18 hdefs : hdefs1 hdefs2
19 hdefs1 : MUSTINVERT ':' expression
20 hdefs2 : LINKTYPE ':' expression
21 string : STRING
22 pdefs : PLEN ':' expression LEN ':' expression TYPE ':' expression CHECK ':' expression FIRSTPROTOCOL ':' stringa
23 psdefs : SECS ':' expression
24 |
25 pudefs : USECS ':' expression
26 |
27 pwdefs : WRITTEN ':' expression
28 |
29 pddefs : DISCARDED ':' expression
30 |
31 expression : NAME
32 | NUMBER
33 | NUMBER_H
34 | '(' expression ')'
35 | expression '+' expression
36 | expression MIU expression
37 | expression MAU expression
38 | expression '<' expression
39 | expression '>' expression
40 | expression NOT_EQ expression
41 | expression '=' expression
42 | expression AND expression
43 | expression OR expression
44 | expression '-' expression
45 | expression '*' expression
46 | expression '/' expression
47 | expression '%' expression
48 | '-' expression
49 | NOT expression
'file' is the beginning symbol.
Here it is the table which shows the priority order of the operators in the expressions:
| Low priority | |
| Operators | The operator is associated to the expression on the: |
| OR | left |
| AND | left |
| '=',NOT_EQ,'<','>',MIU,MAU | left |
| '+','-' | left |
| '*','/','%' | left |
| NOT,MENO_UNARIO | right |
| High priority | |
Here it is a summary of the scanner which recognize the file tokens. This summary is presented in the LEX format.
SPACE ([\t\r\n ])
SPACES ({SPACE}*)
LETTER ([a-zA-Z])
DIGIT ([0-9])
F_DIGIT ([1-9])
DECIMAL ({DIGIT}*{F_DIGIT}|0)
HEX ((("0x")|("0X"))([a-fA-F]|{DIGIT})+)
INTEGER ({F_DIGIT}{DIGIT}*)
VAR_NAME ((("_")|{LETTER})({LETTER}|{DIGIT}|("_"))*)
COST_INT_CORTO ({INTERO}|[0])
OP ([-+=*/%()<>:])
VAR ({VAR_NAME})
COMMENT ("/*"([^*]*|"*"+[^*/])"*"+\/)
COST_STRING (\"[^\"\n]*\")
%%
BYTE {return BYTE;}
WORD {return WORD;}
DWORD {return DWORD;}
AND {return AND;}
"&" {return AND;}
"&&" {return AND;}
OR {return OR;}
"|" {return OR;}
"||" {return OR;}
NOT {return NOT;}
"!" {return NOT;}
"~" {return NOT;}
TYPE {return TYPE;}
CHECK {return CHECK;}
PLEN {return PLEN;}
L'EN {return L'EN;}
SECS {return SECS;}
USECS {return USECS;}
WRITTEN {return WRITTEN;}
DISCARDED {return DISCARDED;}
FIRSTPROTOCOL {return FIRSTPROTOCOL;}
HEADER {return HEADER;}
TRAILER {return TRAILER;}
PHEADER {return PHEADER;}
PTRAILER {return PTRAILER;}
ENDHH {return ENDHH;}
ENDPH {return ENDPH;}
ENDHT {return ENDHT;}
ENDPT {return ENDPT;}
NOT {return NOT;}
"!=" {return NOT_EQ;}
"<=" {return MIU;}
">=" {return MAU;}
MUSTINVERT {return MUSTINVERT;}
LINKTYPE {return LINKTYPE;}
{HEX} {return NUMBER_H;}
{COST_INT_CORTO} {return NUMBER;}
{COMMENT} {/*the comments are ignored*/ }
{OP} {return yytext[0];}
{VAR} {return NAME;}
{COST_STRING} {return STRING;}
{SPACE}+ {/*the spaces are ignored*/}
. {printf("Scanner error at line %d\n",yylineno);return (-1);}
%%
'AND' can be written : 'AND', '&&', '&'
'OR' can be written : 'OR', '||', '|'
'NOT' can be written : 'NOT', '!', '~'
'=' can be written : '==', '='