home *** CD-ROM | disk | FTP | other *** search
/ ittybittycomputers.com / www.ittybittycomputers.com.tar / www.ittybittycomputers.com / Essays / Turk2.txt < prev    next >
Text File  |  2006-10-18  |  4KB  |  177 lines

  1. # Grammar of the Turk/2 Programming Language -- 2003 February 13
  2.  
  3.  Identifier -> ID;
  4.  
  5.  QualIdent -> (Identifier ( "." Identifier )* | "this" | "super") ;
  6.  
  7.  Literal
  8.    -> NUM # IntegerLiteral
  9.    -> FLT # FloatingPointLiteral
  10.    -> CHR # CharacterLiteral
  11.    -> STR # StringLiteral
  12.    -> "true" | "false" # BooleanLiteral
  13.    -> "null" ; # NullLiteral
  14.  
  15.  ConstExpn -> Expression ;
  16.  
  17.  Expression -> BoolExpn | CatExpn ;
  18.  
  19.  BoolExpn -> BoolTerm ("||" BoolTerm)* ;
  20.  
  21.  BoolTerm -> BoolPrim ("&&" BoolPrim)* ;
  22.  
  23.  BoolPrim -> CatExpn (RelOp CatExpn)? ;
  24.  
  25.  CatExpn -> BitExpn ("#" BitExpn)* ;
  26.  
  27.  BitExpn -> BitTerm ("|" BitTerm)* ;
  28.  
  29.  BitTerm -> BitFact ("^" BitFact)* ;
  30.  
  31.  BitFact -> BitPrim ("&" BitPrim)* ;
  32.  
  33.  BitPrim -> MathExpn ("<<" MathExpn | ">>" MathExpn | ">>>" MathExpn) ;
  34.  
  35.  MathExpn -> Term ("+" Term | "-" Term)* ;
  36.  
  37.  Term -> Primary ("*" Primary | "/" Primary | "%" Primary)* ;
  38.  
  39.  Primary
  40.    -> "!" Primary
  41.    -> "~" Primary
  42.    -> "+" Primary
  43.    -> "-" Primary
  44.    -> "(" Expression ")"
  45.    -> QualIdent Arguments
  46.    -> LeftExpn
  47.    -> "new" Creator
  48.    -> ArrayInitializer
  49.    -> Literal ;
  50.  
  51.  Arguments -> "(" (Expression ( "," Expression )*)? ")" ;
  52.  
  53.  RelOp -> "==" | "!=" | "<" | ">" | "<=" | ">=" | "instanceof" ;
  54.  
  55.  LeftExpn -> QualIdent  Selector* ;
  56.  
  57.  Selector -> "." Identifier | "[" Expression "]" ;
  58.  
  59.  Type -> TypeName  ("[" "]")* ;
  60.  
  61.  TypeName -> Identifier | BasicType ;
  62.  
  63.  BasicType
  64.    -> "byte"
  65.    -> "short"
  66.    -> "int"
  67.    -> "long"
  68.    -> "char"
  69.    -> "float"
  70.    -> "double"
  71.    -> "boolean" ;
  72.  
  73.  Creator -> TypeName ( ("[" Expression "]")*  | Arguments ) ;
  74.  
  75.  ArrayInitializer -> "{" VarInitializer ("," VarInitializer)* "}" ;
  76.  
  77.  VarInitializer -> ArrayInitializer | Expression ;
  78.  
  79.  ParExpression -> "(" Expression ")" ;
  80.  
  81.  Block -> "{" LocalVarDecln* Statement* "}" ;
  82.  
  83.  LocalVarDecln -> "final"? Type  VarDeclor ( "," VarDeclor )* ";" ;
  84.  
  85.  Statement
  86.    -> Block
  87.    -> "if" ParExpression Statement ("else" Statement)?
  88.    -> "for" Identifier "=" Expression "," Expression ("," Expression)?
  89.         "do" Statement
  90.    -> "while" ParExpression Statement
  91.    -> "do" Statement "while" ParExpression   ";"
  92.    -> "try" Block ( CatchClause+ | CatchClause* "finally" Block )
  93.    -> "switch" ParExpression "{" SwitchBlockGroup* "}"
  94.    -> "synchronized" ParExpression Block
  95.    -> "return" Expression? ";"
  96.    -> "throw" Expression   ";"
  97.    -> "break" # (Identifier)?
  98.    -> "continue" # (Identifier)?
  99.    -> LeftExpn "=" Expression ";"
  100.    -> ";" ;
  101.  
  102.  CatchClause -> "catch" "(" FormalParameter ")" Block ;
  103.  
  104.  SwitchBlockGroup -> SwitchLabel Statement* ;
  105.  
  106.  SwitchLabel -> "case" ConstExpn (".." ConstExpn)?  ":" | "default" ":" ;
  107.  
  108.  ModifiersOpt -> Modifier* ;
  109.  
  110.  Modifier
  111.    -> "public"
  112.    -> "protected"
  113.    -> "private"
  114.    -> "static"
  115.    -> "abstract"
  116.    -> "final"
  117.    -> "native"
  118.    -> "synchronized"
  119.    -> "transient"
  120.    -> "volatile"
  121.    -> "strictfp" ;
  122.  
  123.  VarDeclor -> Identifier  ("=" VarInitializer)? ;
  124.  
  125.  CompilationUnit
  126.    -> ("package" QualIdent ";")? ImportDeclaration* TypeDeclaration* ;
  127.  
  128.  ImportDeclaration -> "import" QualIdent ( "." "*" )? ";" ;
  129.  
  130.  TypeDeclaration
  131.    -> ModifiersOpt (ClassDecln | InterfaceDeclaration)
  132.    -> ";" ;
  133.  
  134.  ClassDecln -> ("class" | "type") Identifier ClassOrTypeDecln ;
  135.  
  136.  ClassOrTypeDecln
  137.    -> "=" NewType ";"
  138.    -> ("extends" Type)? ("implements" TypeList)?  "{" ClassBodyDecln* "}" ;
  139.  
  140.  TypeList -> Type ( "," Type)* ;
  141.  
  142.  NewType
  143.    -> "{" IdentList "}"
  144.    -> ConstExpn ".." ConstExpn
  145.    -> Type ;
  146.  
  147.  IdentList -> Identifier ( "," Identifier)* ;
  148.  
  149.  ClassBodyDecln -> ModifiersOpt MemberDecl ;
  150.  
  151.  MemberDecl
  152.    -> TypeDeclaration # ClassOrInterfaceDeclaration
  153.    -> Identifier MethodRest # ConstructorDeclaratorRest
  154.    -> "void" Identifier MethodRest
  155.    -> Type Identifier ( MethodRest | "=" VarInitializer ";" | ";") ;
  156.  
  157.  MethodRest -> MethodHeader (Block | ";" ) ;
  158.  
  159.  MethodHeader -> FormalParams ("throws" QualIdenList)? ;
  160.  
  161.  QualIdenList -> QualIdent ("," QualIdent)* ;
  162.  
  163.  InterfaceDeclaration
  164.    -> "interface" Identifier ("extends" TypeList)? "{" InterBodyDecln* "}" ;
  165.  
  166.  InterBodyDecln -> ModifiersOpt InterfaceMemberDecl | ";" ;
  167.  
  168.  InterfaceMemberDecl
  169.    -> "void" Identifier MethodHeader ";"
  170.    -> Type Identifier (MethodHeader | "=" VarInitializer | ) ";" ;
  171.  
  172.  FormalParams -> "(" (FormParam ( "," FormParam)*)? ")" ;
  173.  
  174.  FormParam -> "final"? Type Identifier ; # ("final"|"static")?
  175.  
  176. # ------------------------------------------------------------------------
  177.