more parser updates

This commit is contained in:
Miek Gieben 2011-07-11 21:44:07 +02:00
parent 8c477c5c60
commit afa896ff14
1 changed files with 29 additions and 6 deletions

35
dns.l
View File

@ -1,6 +1,8 @@
package main
package main
import "fmt"
import "fmt"
var debug = true
var lastOwner = string
CHAR [A-Za-z0-9/+=a.{}]
BLANK [ \t]
@ -18,25 +20,34 @@ BLANK [ \t]
BEGIN(INITIAL)
}
<INITIAL>^{CHAR}+ {
<INITIAL>^{CHAR}+ {
YOUT("qname")
yylval = yytext
lastOwner = yylval
BEGIN(classttl)
return QNAME
}
<INITIAL>^{BLANK}+ {
YOUT("qname.")
// Return qname TOK, and fix yytext
yylval = lastOwner
BEGIN(classttl)
return QNAME
}
<classttl>{CHAR}+ {
yylval = yytext
switch yycheckit(yytext) {
case 0:
YOUT("{qtype:" + yytext + "}")
BEGIN(rest)
return QTYPE
case 1:
YOUT("qclass")
return QCLASS
case 2:
YOUT("ttl")
return TTL
}
}
<classttl>{BLANK}+ {
@ -45,6 +56,8 @@ BLANK [ \t]
<rest>{CHAR}+ {
YOUT("str")
yylval = yytext
return STR
}
<rest>{BLANK}+ {
YOUT(".")
@ -52,6 +65,7 @@ BLANK [ \t]
<rest>\n {
YOUT("NL\n")
BEGIN(INITIAL)
return NL
}
%%
@ -68,9 +82,18 @@ func yycheckit(s string) int {
func YOUT(s string) {
fmt.Printf("%s", s)
if debug {
fmt.Printf("%s", s)
}
}
func main() {
yylex()
type yyLex int
func (yyLex) Lex(yylval *yySymType) int {
yylex()
return 0
}
func (yyLex) Error(s string) {
println(s)
}