için basit bir Bison dilbilgisine ihtiyacınız var Bison yardımına baktım ve bunu yazdım, ama tamamen doğru olduğundan emin değilim. Ayrıca Lexical Analyzer'ı (Flex
aracı olmalı) kullanan bir yylex()
'a ihtiyacım var. Bağlamsız gramerlerle ilgili bazı temel şeyleri biliyorum. Ama onları doğru bir şekilde nasıl uygulayacağımı bilmiyorum! :( HTML
%{
#include <stdio.h>
int yylex(void);
int yyerror(char const *);
%}
%token NUM_TOKEN FILENAME_TOKEN COLOR_TOKEN NAME_TOKEN
/* Html Grammer follows... */
%%
/* Any html tag follow this pattern: */
EXPRESSION:
'<' TAG CLUSER '>' INNER_EXPRESSION "</" TAG '>' ;
/* Some html tags: */
TAG:
"a" |
"html" |
"head" |
"link" |
"div" |
"input"|
"from" |
"title"|
"img" |
"table"|
"td" |
"tr" ;
CLUSER:
ALIGN|
CLASS|
ID|
SRC|
TEPY|
ACTION|
HREF|
REL|
/* € (Eplsilone) */
;
ALIGN:
"align" '=' "left"|
"align" '=' "right"|
"align" '=' "center"
;
CLASS:
"class" '=' NAME_TOKEN
;
ID:
"id" '=' NAME_TOKEN
;
SRC:
"src" '=' FILENAME_TOKEN
;
TEPY:
"type" '=' CONT
;
ACTION:
"action" '=' FILENAME_TOKEN
;
HREF:
"href" '=' '\"#\"'|
"href" '=' FILENAME_TOKEN
;
REL:
"rel" '=' "stylesheet"|
"rel" '=' "\"stylesheet\""
;
DOMIN:
"px"|
"mm"|
"cm"|
"inch"
;
PAS:
"php"|
"asp"|
"aspx"|
"css"
;
CONT:
"button"|
"checkbox"|
"text"|
"password"|
"file"|
"submit"
;
INNER_EXPRESSION:
EXPRESSION|
/* € (Eplsilone) */
;
/* Html grammer ends. */
%%
Bu
Bison'ın çıktısı:? O olacak değilE:\Program Files\GnuWin32\bin>bison "E:\Dev-Cpp\HtmlBison\html.y" -o "E:\html.c"
E:\Dev-Cpp\HtmlBison\html.y: warning: 2 nonterminals useless in grammar
E:\Dev-Cpp\HtmlBison\html.y: warning: 8 rules useless in grammar
E:\\Dev-Cpp\\HtmlBison\\html.y:83.1-5: warning: nonterminal useless in grammar:
DOMIN
E:\\Dev-Cpp\\HtmlBison\\html.y:90.1-3: warning: nonterminal useless in grammar:
PAS
E:\\Dev-Cpp\\HtmlBison\\html.y:84.7-10: warning: rule useless in grammar: DOMIN:
"px"
E:\\Dev-Cpp\\HtmlBison\\html.y:85.7-10: warning: rule useless in grammar: DOMIN:
"mm"
E:\\Dev-Cpp\\HtmlBison\\html.y:86.7-10: warning: rule useless in grammar: DOMIN:
"cm"
E:\\Dev-Cpp\\HtmlBison\\html.y:87.7-12: warning: rule useless in grammar: DOMIN:
"inch"
E:\\Dev-Cpp\\HtmlBison\\html.y:91.6-10: warning: rule useless in grammar: PAS: "
php"
E:\\Dev-Cpp\\HtmlBison\\html.y:92.6-10: warning: rule useless in grammar: PAS: "
asp"
E:\\Dev-Cpp\\HtmlBison\\html.y:93.6-11: warning: rule useless in grammar: PAS: "
aspx"
E:\\Dev-Cpp\\HtmlBison\\html.y:94.6-10: warning: rule useless in grammar: PAS: "
css"
m4: cannot open `Files\GnuWin32/share/bison': No such file or directory
m4: cannot open `E:\Program': No such file or directory
m4: cannot open `Files\GnuWin32/share/bison/m4sugar/m4sugar.m4': No such file or
directory
Tam bir HTML ayrıştırıcısı Ben sadece CSS
stilleri veya JavaScripts
veya JavaScripts
veyaolmadan çok basit HTML belgelerini doğrulamak istiyorum this NOT: Çözüm bir Bizon grameri olmalıdır!
Neden bir SGML/XML ayrıştırıcısı kullanmıyorsunuz? – ThiefMaster
Oh ve dev-cpp'den kurtul. Bkz. Http://www.jasonbadams.net/20081218/why-you-shouldnt-use-dev-c/ – ThiefMaster
@ThiefMaster: İyi bağlantı +1 – leppie