-
Notifications
You must be signed in to change notification settings - Fork 0
/
Zaza.g4
73 lines (53 loc) · 1.92 KB
/
Zaza.g4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
grammar Zaza;
programa : (clase | funcion | declaracion_var | expr)* EOF;
clase : 'clase' ID 'empieza' ID cuerpo_clase 'fin' ID;
cuerpo_clase : (declaracion_var | funcion )*
clase_constructor
(declaracion_var | funcion )*
;
clase_constructor: funcion;
funcion : 'proceso' ID '(' parametros? ')' 'empieza' ID cuerpo_funcion 'fin' ID;
cuerpo_funcion : (declaracion_var | expr)*;
parametros : parametro (',' parametro)*;
parametro : tipo_dato ID;
declaracion_var : tipo_dato ID ('=' expr)?;
tipo_dato : 'numero' | 'caracter' | 'texto' | 'booleano';
condicional:
'si' expr 'entonces' expr*
('sino' expr*)?
'fin' 'si'
;
bucle:
'bucle' (bucle_while | bucle_repeticion) 'entonces' expr* 'fin' 'bucle'
;
bucle_while:
'mientras' expr
;
bucle_repeticion:
'repetir' NUMERO
;
expr : asignacion
| expr operador expr
| declaracion_var
| llamada_funcion
| valor
| '(' expr ')'
| condicional
| bucle
| mostrar
;
// funciones basicas
mostrar:
'mostrar' '(' (expr (',' expr)*)? ')'
;
asignacion : ID '=' expr;
operador : '+' | '-' | '*' | '/' | '==' | '!=' | '<' | '>' | '<=' | '>=';
llamada_funcion : ID '(' argumentos? ')';
argumentos : expr (',' expr)*;
valor : NUMERO | CARACTER | TEXTO | BOOLEANO | ID;
ID : [a-zA-Z_][a-zA-Z0-9_]*;
NUMERO : [0-9]+;
CARACTER : '\'' [a-zA-Z] '\'';
TEXTO : '"' .*? '"';
BOOLEANO : 'True' | 'False';
WS : [ \t\r\n]+ -> skip;