Grammars for the specification of links between terms


EBNF grammar

"?" means 0 or 1 times, "*" means 0 to N times, "+" means 1 to N times

Commands     := Command ((";"|".") Command)*
Command      := TermCommand | CGcommand

CGcommand    := CG       | "?" CG   | "^" CG
TermCommand  := TermDecl | "?" Term | "^" Term

TermDecl     := Term RelSignature? Annotation? (LinksOf1Kind ("," LinksOf1Kind)*)?
RelSignature := "(" Term "," Term ")"
Annotation   := "(^" ... "^)"

LinksOf1Kind := LinkKind (DestTerm | TermPartition)+
LinkKind     := ">" | "<" | "!" | "~" | ":" | "_" | Identifier
TermPartition:= "{" DestTerm+ "}"
DestTerm     := Term LinkContext?
LinkContext  := "(" Creator Community? ")"

Term         := Identifier | String
String       := "\"" ..."\""  |  "'" ..."'"  |  "$(" ... ")$"
Identifier   := TermLetter1 TermLetter*
TermLetter1  := [a-z0-9_] | "#"[a-z0-9_]
TermLetter   := [a-z0-9_] | "#" | "-" | "/" | "?" | "&" | "@" | "~" | "'" |"."
                          | "://"  //thus a URL may be a Term
Number       := ("+"|"-")? Digit+ ("." Digit* )?
Digit        := [0-9]

//Additional notes on the lexical parsing:
- white spaces and the HTML imbreakable space encoding " " are ignored
- Java/C++ comments ("/* ... */" and "//...") are ignored
- HTML tags are ignored but the content of HTML comments is parsed
- annotations are enclosed within "(^" and "^)"
- strings may be single quoted, double quoted or enclosed within "$(" and ")$"


Lex&Yacc grammars

%token IDENTIFIER NUMERAL STRING ANNOTATION CG %start COMMANDS %% COMMANDS : COMMAND ';' | COMMANDS COMMAND ';' ; COMMAND : TERM_DECL | CG_COMMAND ; CG_COMMAND : CG | '?' CG ; TERM_DECL : TERM _ANNOT _LINKS ; TERM : TERM_NAME _SIGNATURE ; _ANNOT : | ANNOTATION ; _SIGNATURE : | '(' R_DOMAIN ',' R_RANGE ')' ; R_DOMAIN : IDENTIFIER ; R_RANGE : IDENTIFIER ; _LINKS : | LINKS; LINKS : LINKS1_S | LINKS1_S ',' LINKS ; LINKS1_S : LINK_KIND LINK_DESTS ; LINK_DESTS : LINK_DEST | LINK_DEST LINK_DESTS ; LINK_DEST : DEST_TERM | '{' DEST_TERMS '}' _LINK_CTXT ; DEST_TERMS : DEST_TERM _DEST_TERMS; _DEST_TERMS: | DEST_TERMS; DEST_TERM : DEST_NAME _LINK_CTXT ; DEST_NAME : IDENTIFIER ; _LINK_CTXT : | '(' CREATOR _COMMUNITY ')' ; CREATOR : IDENTIFIER ; _COMMUNITY : | IDENTIFIER ; LINK_KIND : '>' | '<' | '=' | '~' | ':' | '^' | IDENTIFIER ; TERM_NAME : IDENTIFIER | STRING ; %% DIGIT [0-9] ALPHA [a-z] ALNUM [a-z0-9] ANY (.) S ([ \t ]|"&nbsp;")+ IDENT0 ({ALNUM}|"_") IDENT1 ({IDENT0}|"#"{IDENT0}) IDENTn ({IDENT0}|"-"|"/"|"?"|"&"|"@"|"#"|"~"|"'"|"."|"://") IDENT {IDENT1}({IDENTn})* NUMBER ("+"|"-")?{DIGIT}+("."{DIGIT}*)? OTHER_OPER ("=>"|"<=>"|"="|"=<"|">="|">") IDENT_OPER ({IDENT}|"!="|"<="|"=<"|{OTHER_OPER}) ANNOT_ALL "(^"([^\^]|(\^[^\)]))*"^)" ANNOT_END ([^\^]|(\^[^\)]))*"^)" DELIM_STR "$("([^\)]|(\)[^\$]))*")$" DELIM_END ([^\)]|(\)[^\$]))*")$" QSTR1 '([^'\\]|(\\{ANY}))*' QSTR1_END ([^'\\]|(\\{ANY}))*' QSTR2 \"([^"\\]|(\\{ANY}))*\" QSTR2_END ([^"\\]|(\\{ANY}))*\" QUOTED_STR ({QSTR1}|{QSTR2}) ANY_VALUE ({IDENT_OPER}|{QUOTED_STR}) %x ALIAS1 ALIAS2 ANNOT1 DELIM1 C_COMM %% "/*" BEGIN(C_COMM); <C_COMM>"\n" LineNumber++; <C_COMM>"*/" BEGIN(0); <C_COMM>. ; {S} ; "\n" LineNumber++; "//"[^\n]* ;/* skip C++ line comments */ "<!--" ;/* no wk_skipHTMLComments(): content parsed */ "-->" ; "<!" wk_skipTag(); "<"{ALPHA} wk_skipTag(); "(^" BEGIN(ANNOT1); <ANNOT1>{ANNOT_END} {LineNumber+=nbLinesIn(wktext); wktext[wkleng-2]='\0';BEGIN(0);return ANNOTATION;} "$(" BEGIN(DELIM1); <DELIM1>{DELIM_END} {LineNumber+=nbLinesIn(wktext); wktext[wkleng-2]='\0';BEGIN(0);return STRING;} {QUOTED_STR} {LineNumber+=nbLinesIn(wktext); return STRING;} {NUMBER} return NUMERAL; {IDENT} return IDENTIFIER; . return wktext[0]; %%
Philippe Martin
Last modified: Fri Jul 28 20:42:46 MEST 2000