W3C home > Mailing lists > Public > www-validator@w3.org > January 2004

News of javascript Validator

From: incerti auctoris <incertia@hotmail.com>
Date: Fri, 30 Jan 2004 16:50:07 +0000
To: www-validator@w3.org
Message-ID: <BAY2-F1071qh1aQzHkQ0001f3ee@hotmail.com>

I don't suppose you'd be interested in a javascript validator I wrote in
BBC BASIC V? It started as a bracket matcher, then I bolted a few extras on.
I'll get around to converting it into javascript or Perl eventually,
but here's the current source:


REM>"Bracketsb"
:
ONERROR REPORT:PRINT" at ";ERL:END
:
N$=CHR$10+CHR$13
A$="function Start(){//Preloader bits."+N$
A$+="for(w=0;w<=16;w++){    // REVERSE TO => / >="+N$
A$+="yy=String.fromCharCode(w+97);"+N$
A$+="L[w]=new Image();eval(""L[""+w+""]"
A$+=".src='r/l""+yy+"".jpg'"")}"+N$
A$+="}window.onload=Start;"+N$
A$+="/* Comments // again. */"+N$
A$+="function on(w){X[w].src=N[w].src}"+N$

REMA$="{x=""a'{}[]()"";x='a""';x[y]=(5/5);}"+N$
REMA$+="{x[(9)]=5;x[9]=(5)} x=[{y})"+N$
:
REMA$="""L[""+w+""].src='r/l"""
:
Dstr=FALSE:REM Double-Quoted string.
Sstr=FALSE:REM Single-Quoted string.
Rexp=FALSE:REM Regular Expression.
Lcom=FALSE:REM Line comment.
Bcom=FALSE:REM Bracketed comment.
Tree=NOTTRUE:REM Print debugging help.
Show=TRUE:REM Show source.
:
Li=1:REM Current line.
LS=-1:REM Start of current line; for error-printing use.
IFTree ORShow PRINT"Source:"'A$
:
DIM B$(200):B=0
L=LENA$
P$="":PNL=FALSE
FORC=1TO L
Op=FALSE:REM Opening "'/.
X$=MID$(A$,C,1)
RX$=X$
REM Mode decisions:
IFX$=CHR$13 ORX$=CHR$10 NL=TRUE ELSENL=FALSE
IFNL Lcom=FALSE:IFNOTPNL Li+=1:LS=C
IFP$+X$="//" Lcom=TRUE:IFBcom PRINT"Warning: Line Comment inside Bracketed 
Comment";:PROCLine_report
IFP$+X$="/*" B+=1:B$(B)="*":PROCNB:Bcom=TRUE:PROCPTest:IFLcom PRINT"Warning: 
Bracketed Comment inside Line Comment";:PROCLine_report

REM Mode influences:
Comm=(Lcom OR Bcom)
IFComm X$=""

REM Naughty function Check:
IFB>0 ANDX$="f" PROCfunction

REM Bracket Logs/Detects:
NS=NOT(Dstr OR Sstr):REMPRINT;Dstr,;Sstr,;NS
IFNS AND X$="{" B+=1:B$(B)="}":PROCPTest:PROCNested("{")
IFNS AND X$="[" B+=1:B$(B)="]":PROCPTest
IFNS AND X$="(" B+=1:B$(B)=")":PROCPTest
IFX$=CHR$34 AND NS B+=1:B$(B)=X$:Dstr=TRUE:Op=TRUE:PROCPTest
IFX$="'" AND NS B+=1:B$(B)=X$:Sstr=TRUE:Op=TRUE:PROCPTest
REMIFX$="/" B+=1:B$(B)=X$:Op=TRUE
:
REM Further Mode influences(?):

:
REM Bracket Detects:
IFNS AND(X$="}"ORX$="]"ORX$=")") THEN
B$=B$(B):B-=1 :PROCNTest
IFB$<>X$ PROCMismatch("Bracket",B$,X$):END
ENDIF

IFX$=CHR$34ANDNOTSstr ANDNOTOp THEN
B$=B$(B):B-=1 :PROCNTest
Dstr=FALSE
IFB$<>X$ PROCMismatch("Delimiter",B$,X$):END
ENDIF

IFX$="'"ANDNOTDstr ANDNOTOp THEN
B$=B$(B):B-=1 :PROCNTest
Sstr=FALSE
IFB$<>X$ PROCMismatch("Delimiter",B$,X$):END
ENDIF

IFP$+RX$="*/" THEN
B$=B$(B):B-=1 :PROCNTest
IFB$<>"*" PROCMismatch("Comment",B$,"*/"):END
ENDIF

REMIFRexp AND X$="/" ANDNOTOp THEN
REMB$=B$(B):B-=1
REMIFB$<>X$ PROCMismatch("Delimiter",B$,X$):END
REMENDIF


P$=RX$:PNL=NL
NEXT

IFB>0 PROCPremature
PRINT"No serious errors in code."
END
:
DEFPROCMismatch(W$,a$,b$)
IFB<0 PRINT"Suprious closing "b$" bracket found, "; ELSEPRINTW$" mismatch: 
"a$" expected but "b$" found";
PROCLine_report:END
ENDPROC
:
DEFPROCLine_report
PRINT", at line ";Li;":"
D=LS+1:E=C-D-1
REPEATD+=1
X=ASCMID$(A$,D,1)
N=(X=10ORX=13)
IFNOTN VDUX
UNTILN OR D>=L
PRINT'SPC(E);"^"
ENDPROC
:
DEFPROCPTest
Y$=X$:IFY$="*" Y$="/*"
IFTree PRINTSPC(B*2)"+"Y$
ENDPROC
:
DEFPROCNTest
Y$=X$:IFY$="" Y$=B$(B+1)
IFY$="*" Y$="*/"
IFTree PRINTSPC((B+1)*2)"-"Y$
ENDPROC
:
DEFPROCfunction
D=C
D+=1:IFMID$(A$,D,1)<>"u" ENDPROC
D+=1:IFMID$(A$,D,1)<>"n" ENDPROC
D+=1:IFMID$(A$,D,1)<>"c" ENDPROC
D+=1:IFMID$(A$,D,1)<>"t" ENDPROC
D+=1:IFMID$(A$,D,1)<>"i" ENDPROC
D+=1:IFMID$(A$,D,1)<>"o" ENDPROC
D+=1:IFMID$(A$,D,1)<>"n" ENDPROC
PRINT"function Declared inside brackets."
PROCHistory
END
ENDPROC
:
DEFPROCHistory
PRINT"Bracket History: "
FORD=1TO B:A$=B$(D)
B$=FNReverse(A$)
PRINTB$;:NEXT:PRINT
ENDPROC
:
DEFFNReverse(Y$)
R$=Y$
IFY$="}" R$="{"
IFY$="]" R$="["
IFY$=")" R$="("
IFY$="*" R$=" /* "
=R$
:
DEFPROCNested(F$)
IFB=1 ENDPROC
BB$=B$(B-1)
IFBB$<>"}" PRINT"Illegal nesting: "F$" inside 
"FNReverse(BB$);:PROCLine_report:REMEND:REM Treat as 'Warning.
ENDPROC
:
DEFPROCPremature
PRINT"Script ended prematurely: Brackets not ";
IFB>1 PRINT"all ";
PRINT"closed."
PROCHistory
END
ENDPROC
:
DEFPROCNB
IFBcom PRINT"Warning: Nested Comments";:PROCLine_report
ENDPROC
:


EXAMPLE ONE

Source:
function Start(){//Preloader bits.
for(w=0;w<=16;w++){    // REVERSE TO => / >=
yy=String.fromCharCode(w+97);
L[w]=new Image();eval("L["+w+"].src='r/l"+yy+".jpg'")}
}window.onload=Start;
/* Comments // again. */
function on(w){X[w].src=N[w].src}


Warning: Line Comment inside Bracketed Comment, at line 6:
/* Comments // again. */
             ^
No serious errors in code.


EXAMPLE TWO

Source:
function one(){
x="a'{}[]()";x='a"';x[y]=(5/5)
}
function two(){x[(9)]=5;x[9]=(5)} x=[{y})


Illegal nesting: { inside [, at line 4:
function two(){x[(9)]=5;x[9]=(5)} x=[{y})
                                     ^
Bracket mismatch: ] expected but ) found, at line 4:
function two(){x[(9)]=5;x[9]=(5)} x=[{y})
                                        ^

EXAMPLE TWO WITH DEBUGGING HELP ON

  +(
  -)
  +{
    +"
    -"
    +'
    -'
    +[
    -]
    +(
    -)
  -}
  +(
  -)
  +{
    +[
      +(
      -)
    -]
    +[
    -]
    +(
    -)
  -}
  +[
    +{
Illegal nesting: { inside [, at line 4:
function two(){x[(9)]=5;x[9]=(5)} x=[{y})
                                     ^
    -}
  -)
Bracket mismatch: ] expected but ) found, at line 4:
function two(){x[(9)]=5;x[9]=(5)} x=[{y})
                                        ^

Please note that although I have written several fairly complex short
javascripts, I would not yet call myself fluent, so I would welcome
suggestions of common errors to look for.

-Robin H. (Mr.)

_________________________________________________________________
Express yourself with cool emoticons - download MSN Messenger today! 
http://www.msn.co.uk/messenger
Received on Friday, 30 January 2004 16:25:40 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 25 April 2012 12:14:10 GMT