Described with YACC format:
1 type : BYTE
2 | WORD
3 | DWORD
4 name : NAME
5 number : NUMBER
6 | C_H_NUM
7 | C_O_NUM
8 | LIT_CH
9 const_str : CONST_STRING
10 expression : name
11 | name '[' expression ']'
12 | ch_funz
13 | number
14 | CHECK '(' expression ')'
15 | CONV '(' expression ')'
16 | CONV16 '(' expression ')'
17 | CONV24 '(' expression ')'
18 | CONV32 '(' expression ')'
19 | '(' expression ')'
20 | expression '+' expression
21 | expression LSHIFT expression
22 | expression RSHIFT expression
23 | expression NOT_EQ expression
24 | expression MIU expression
25 | expression MAU expression
26 | expression MIN expression
27 | expression MAG expression
28 | expression EQ expression
29 | expression AND expression
30 | expression OR expression
31 | expression '-' expression
32 | expression '*' expression
33 | expression '/' expression
34 | expression '%' expression
35 | '-' expression
36 | NOT expression
37 | assignment
38 | SIZEOF '(' name ')'
39 | OFFSETOF '(' name ')'
40 | GETVMVAR '(' const_str ')'
41 | COMMAND '(' const_str ')'
42 | LEN '(' name ')'
43 | STRLEN '(' name ')'
44 assignment: name '=' expression
45 | name '[' expression ']' '=' expression
46 ch_funz : name '(' l_express ')'
47 | name '(' ')'
48 l_express : expression
49 | l_express ',' expression
50 program : llines
51 |
52 llines : declarations
53 | c_function
54 | llines declarations
55 | llines c_function
56 declaration : prototype
57 prototype : type name '(' ')' ';'
58 | type name '(' l_variables ')' ';'
59 | ARRAY name ';'
60 l_variables : type name
61 | name
62 | l_variables ',' type name
63 | l_variables ',' name
64 def_var : def_v ';'
65 def_v : type name
66 | def_v ',' name
67 | type error
68 l_instructions : l_instructions instruction
69 | instruction
70 | error
71 instruction: instr ';'
72 | construction
73 | def_var
74 | '{' l_instructions '}'
75 | '{' '}'
76 construction : c_do
77 | c_while
78 | c_if
79 | c_for
80 do : DO
81 while : WHILE
82 for : FOR
83 if : IF
84 else : ELSE
86 c_do : do instruction WHILE '(' expression ')' ';'
87 | do instruction WHILE error
89 c_while : while '(' expression ')' instruction
90 | while error
91 t_if :
92 c_if : if '(' expression ')' t_if instruction
94 c_if : if '(' expression ')' t_if instruction else instruction
95 | if error
99 c_for : for '(' expression ';' expression ';' expression ')' instruction
100 | for error
102 c_function : tipo nome '(' ')' '{' l_instructions '}'
104 c_function : tipo nome '(' l_variables ')' '{' l_instructions '}'
105 | tipo nome '(' error ')'
106 instr : CONTINUE
107 | BREAK
108 | expression
109 | TITLE '(' cost_str ')'
110 | TITLE '(' cost_str ',' l_express ')'
111 | PRINT '(' cost_str ',' l_express ')'
112 | PRINT '(' cost_str ')'
113 | APRINT '(' cost_str ',' nome ')'
114 | CLEAR '(' name ')'
115 | RETURN expression
116 | RESETLOG '(' ')'
117 | RESETLOG '(' expression ',' expression ')'
118 | RESETLOG '(' expression ',' expression ',' expression ')'
119 | prototype
| Low Precedence | |
| Operators | It is associated with the term on the: |
| '=' | right |
| OR | left |
| AND | left |
| EQ,NOT_EQ,'<','>',MIU,MAU | left |
| LSHIFT,RSHIFT | left |
| '+','-' | left |
| '*','/','%' | left |
| NOT,MENO_UNARIO | right |
| CH_FUNZ | left |
| High Precedence | |
LEX format:
SPACE ([\t\r\n ])
SPACES ({SPACE}*)
LETTER ([a-zA-Z])
DIGIT ([0-9])
F_DIGIT ([1-9])
DECIMAL ({DIGIT}*{F_DIGIT}|0)
UNTIL_END ([^\n]*)
R_REM (\/\/)
HEX ((("0x")|("0X"))([a-fA-F]|{DIGIT})+)
OCT (("0")([0-7])+)
INTEGER ({F_DIGIT}{DIGIT}*)
VAR_NAME ((("_")|{LETTER})({LETTER}|{DIGIT}|("_"))*)
CONST_STRING (\"[^\"\n]*\")
CONST_INT_SHORT ({INTEGER}|[0])
QUOTE \'([^\\']|\\[^'\\]+|\\\\)\'
OP ([-+=*/{}();,:%])|("\[")|("\]")
VAR ({VAR_NAME})
COMMENT ("/*"([^*]*|"*"+[^*/])"*"+\/)
COMMENT_L ("//".*)
%%
\xd /* Discards LF*/
{COMMENT} {/* Discards comment */ }
{COMMENTO_L} {/* Discards comment */ }
do {return DO; }
if {return IF; }
else {return ELSE; }
while {return WHILE; }
for {return FOR; }
return {return RETURN; }
break {return BREAK; }
continue {return CONTINUE; }
array {return ARRAY; }
byte {return BYTE; }
word {return WORD; }
dword {return DWORD; }
sizeof {return SIZEOF; }
offsetof {return OFFSETOF; }
getvmvar {return GETVMVAR; }
printf {return PRINT; }
aprintf {return APRINT; }
clear {return CLEAR; }
arrlen {return LEN; }
strlen {return STRLEN; }
resetlog {CHSAY("RESETLOG");return RESETLOG; }
title {return TITLE; }
check {return CHECK; }
conv {return CONV; }
conv16 {return CONV16; }
conv24 {return CONV24; }
conv32 {return CONV32; }
{CONST_STRING} {return CONST_STRING; }
{CONST_INT_SHORT} {return NUMBER; }
{HEX} {return C_H_NUM; }
{OCT} {return C_O_NUM; }
{QUOTE} {return LIT_CH; }
"<" {return MIN;}
">" {return MAG;}
AND {return AND;}
"&" {return AND;}
"&&" {return AND;}
OR {return OR;}
"|" {return OR;}
"||" {return OR;}
NOT {return NOT;}
"!" {return NOT;}
"~" {return NOT;}
{OP} {return *yytext; }
"==" {return EQ; }
"!=" {return NOT_EQ; }
">=" {return MAU; }
"<=" {return MIU; }
"<<" {return LSHIFT; }
">>" {return RSHIFT; }
{VAR} {return NAME;}
{SPACE}+ {}
. {printf("Scanner error at line %d\n",yylineno);return (SC_ERROR);}
%%
'AND' can be written : 'AND', '&&', '&'
'OR' can be written : 'OR', '||', '|'
'NOT' can be written : 'NOT', '!', '~'
'=' can't be written '=='. In file xFF, double equal means comparison while single equal means assignment.