Hi, I am trying to implement a parser with Gocc. This is the file with the
definition of the grammar.
/* *************************** LEXER **************************** */
!espacio_en_blanco: '\t' | '\n' | '\r' | ' ' ;
!comentario: '#' { . } '\n' ;
_letra: 'A'-'Z' | 'a'-'z' | '_' ;
_digito: '0'-'9' ;
_alfa: _letra | _digito ;
cadena: '"' {_alfa | ' ' | '!' | '.' } '"' ;
entero: '0' | '1'-'9' {_digito} ;
multi: '/' '*' ;
mkdisk: 'm' 'k' 'd' 'i' 's' 'k' ;
rmdisk: 'r' 'm' 'd' 'i' 's' 'k' ;
fdisk: 'f' 'd' 'i' 's' 'k' ;
mount: 'm' 'o' 'u' 'n' 't' ;
unmount: 'u' 'n' 'm' 'o' 'u' 'n' 't' ;
rep: 'r' 'e' 'p' ;
size: 's' 'i' 'z' 'e' ;
fit: 'f' 'i' 't' ;
unit: 'u' 'n' 'i' 't' ;
path: 'p' 'a' 't' 'h' ;
type: 't' 'y' 'p' 'e' ;
delete: 'd' 'e' 'l' 'e' 't' 'e' ;
name: 'n' 'a' 'm' 'e' ;
add: 'a' 'd' 'd' ;
id: 'i' 'd' ;
mbr: 'm' 'b' 'r' ;
disk: 'd' 'i' 's' 'k' ;
identificador: _letra {_alfa} ;
gn: '-' ;
igl: '=' ;
/* *************************************************************** */
/* ************************* PARSER ************************** */
<<
import(
"fmt"
)
>>
Cmd: Mkdisk << fmt.Println("Axioma") >> ;
Mkdisk: mkdisk OpcMkdisk << fmt.Println("Instrucción reconocida.")
>> ;
OpcMkdisk: OpcMkdisk Opc << fmt.Println("Producción recursiva.") >>
| Opc << fmt.Println("Se ejecuta primero.") >> ;
Opc: Size
| Path
| Unit
| MLinea ;
Size: gn size << fmt.Println("SIZE") >> ;
Path: gn path << fmt.Println("PATH") >> ;
Unit: gn unit << fmt.Println("UNIT") >> ;
MLinea: gn fit << fmt.Println("ML") >> ;
/* *************************************************************** */
The test method is as follows:
func main() {
texto := "mkdisk -size -path -unit -fit"
p := parser.NewParser()
s := lexer.NewLexer([]byte(texto))
res, err := p.Parse(s)
if err != nil {
fmt.Println("Se produjo un error.")
} else if res != nil {
fmt.Println("Se reconoció la instrucción.")
}
}
However the parse input, I am not able to correctly read the latest
production of Opc (MLinea) and a syntax error. I think the definition is
correct, but I don't get the desired result.
What am I doing wrong?
Thanks
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/c0f2ea89-827e-4df5-9a20-7d6d340f4d36n%40googlegroups.com.