Latex grammar for Rho-calculus specification

22 views
Skip to first unread message

jar...@gmail.com

unread,
Aug 23, 2013, 12:33:15 AM8/23/13
to antlr-di...@googlegroups.com
Hi,
I am trying to specify a grammar that define the rules for write rho calculus expressions in latex, but i have some kind of problems when the parser try to recognize the aplicacion expression (the one that contains the string '\\overline{') because it split the rule and assume that the left ID of the rule is not part of the aplicacion rule. I don't know if the problem is in the way i define the group of expressions with parenthesis, i found that way in internet but I'm not sure if it is the correct, i am new in the use of antlr.

When i run the TestRig i got:

line 10:35 no viable alternative at input 'r_E::y/y\overline{l_E}'
line 10:35 mismatched input '\overline{l_E}' expecting {'(', 'if', '!OSO(', 'OSO(', '\tau/', '\wedge', '\end{equation*}', '\exists ', '\top', ID}

Thanks!!!

Here is the grammar i define:

grammar RhoArq;

//Inicio de documento
documento : ENCABEZADO (LATEX* ecuacion+ LATEX*)+ '\\end{document}';

//Identificador de ecuaciones latex
ecuacion : '\\begin{equation*}' definicion '\\end{equation*}'
| '\\begin{equation}' definicion '\\end{equation}';

//Definiciones
definicion : ID '=' expresion;

//Expresion Rho-Arq
expresion
@init{int open = 1;}
: '(' ( {if (open > 0)}
( expresion+
| ')' {open--;}
)
)
| expresion '\\wedge' expresion
| '\\exists ' ID expresion
| prefijoaplicacion expresion
| ID '::' ID '/' expresion
| ID ':' ID '/' expresion
| aplicacion
| declaracion
| replicacion
| interior
| combinador
| reaccionInterna
| ejecucionExitosa
| ejecucionNoExitosa
| observacion
| observacionRepetida
| NULO
| ID
;

prefijoaplicacion: ID '\\overline{' ID '}/';

//Operadores
aplicacion: ID '\\overline{' ID '}';
NULO: '\\top';
interior: ID '^{(int)}';
combinador: 'if' clausula+ ('else' ID)?;
clausula: '(' guarda 'then' ID ')';
abstraccion: ID '::' ID '/' ID;
reaccionInterna: '\\tau/' ID;
declaracion: '\\exists ' ID ID;
replicacion: ID ':' ID '/' ID;
ejecucionExitosa: ID '^{\\top}';
ejecucionNoExitosa: ID '^{\\bot}';
observacion: 'OSO(' ID ') do ' ID ' else ' ID;
observacionRepetida: '!OSO(' ID ') do ' ID ' else ' ID;


//Operadores logicos
VERDAD: '\\dot{\\top}';
FALSEDAD: '\\bot';
restriccionEcuacional: ID '=' ID;
conjuncion: '(' conjuncion ')' '\\dot{\\wedge}' '(' conjuncion ')'
| '[' conjuncion ']' '\\dot{\\wedge}' '[' conjuncion ']'
| conjuncion '\\dot{\\wedge}' conjuncion
| guarda '\\dot{\\wedge}' guarda;
cuantificadorExistencial: '\\exists ' ID guarda;
guarda: VERDAD
| FALSEDAD
| restriccionEcuacional
| cuantificadorExistencial
| ID
;

ENCABEZADO : '\\documentclass' ('['.*?']')? '{' .*? '}';
LATEX: '\\' [a-z]+ ('['.*?']')? '{' .*? '}';
ID : ([a-zA-Z_{},.]+ [0-9]*)+?
| ([a-zA-Z_{},.]+ [0-9]*)+ '(' [a-zA-Z_,.]+ ')' ;
WS : [ \t\r\n]+ -> skip;


And the latex document i am trying to parse:

\documentclass[10pt,letterpaper,twocolumn]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\author{Alejandro Rico}
\title{Prueba Rho-arq}
\begin{document}
\begin{equation*}
REQ_E(r,l,i)=\exists l_E((r_E::y/y\overline{l_E})\wedge(l_E::i_E/E^{(int)}))
\end{equation*}
\begin{equation*}
PROV_E(p,s)=p_E:x/xs_E
\end{equation*}
\begin{equation*}
E=REQ_E(r,l,i)\wedge PROV_E(p,s)
\end{equation*}
\begin{equation*}
F=p_F:z/z\overline{s_F}
\end{equation*}
\begin{equation*}
C_{FE}=r_E\overline{p_F}
\end{equation*}
\begin{equation*}
S=E \wedge F \wedge C_{FE}
\end{equation*}

\end{document}


Reply all
Reply to author
Forward
0 new messages