Skip to content

Instantly share code, notes, and snippets.

@elrui
Last active October 8, 2021 02:03
Show Gist options
  • Save elrui/c2a119982e2b7057fde6afa12acff8d9 to your computer and use it in GitHub Desktop.
Save elrui/c2a119982e2b7057fde6afa12acff8d9 to your computer and use it in GitHub Desktop.
Gramática para reconocer integers and floats
?start: num
num: integer
| float
| "-" num -> neg // Este cubre el caso de los números negativos
integer: /[1-9][0-9]*/ // Cualquier entero que no tenga ceros a la izquierda
| /(0)/ // El entero cero
float: /(\.)[0-9]*/ // Cualquier secuencia de dígitos que comience en .
| /(0)(\.)[0-9]*/ // Cualquier float menor a 1
| /[1-9]+[0-9]*(\.)[0-9]*/ // Cualquier float mayor o igual a 1
// Es válido que un float termine en . sin nada después
%import common.WS_INLINE
%ignore " "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment