######################################################################## # Grammaire lexicale ######################################################################## input = { inputelement }. inputelement = whitespace | comment | token. token = ident | number | string | "(" | ")" | ... /* à compléter */ comment = "/" "/" { cchar }. ident = letter { letter | digit | "_" }. number = digit { digit }. string = "\"" { schar } "\"". whitespace = " " | "\t" | "\f" | "\n". letter = "a" | ... | "z" | "A" | ... | "Z". digit = "0" | ... | "9". cchar = tout caractère excepté "\n". schar = tout caractère excepté "\n" et "\"". ######################################################################## # Grammaire syntaxique ######################################################################## Program = { Declaration ";" } Expression. Declaration = "def" ident "(" [ Formals ] ")" ":" Type "=" Expression. Formals = Formal { "," Formal }. Formal = ident ":" Type. Type = "Unit" | "Int" | "List" "[" Type "]" | "(" [ Type { "," Type } ] ")" Type. Statement = "var" Formal "=" Expression | "while" "(" Expression ")" Expression | Expression. Expression = "if" "(" Expression ")" Expression [ "else" Expression ] | ident "=" Expression | OrExpression. OrExpression = AndExpression | OrExpression "|" AndExpression. AndExpression = CmpExpression | AndExpression "&" CmpExpression. CmpExpression = ListExpression [ CompOp ListExpression ]. CompOp = "==" | "!=" | "<" | ">" | "<=" | ">=". ListExpression = SumExpression | SumExpression "::" ListExpression. SumExpression = Term | SumExpression SumOp Term. SumOp = "+" | "-". Term = [ "-" ] Factor | Term ProdOp [ "-" ] Factor. ProdOp = "*" | "/" | "%". Factor = ident | number | string | "false" | "true" | "[" [ Expressions ] "]" | "!" Factor | "head" "(" Expression ")" | "tail" "(" Expression ")" | "isEmpty" "(" Expression ")" | "(" ")" | "(" Expression ")" | "{" { Statement ";" } [ Expression ] "}" | Factor "(" [ Expressions ] ")". Expressions = Expression { "," Expression }. ###################################################################### $Id: concrete_syntax.txt,v 1.1 2004/02/24 16:11:58 schinz Exp $