diff --git a/flap/src/hopix/hopixLexer.mll b/flap/src/hopix/hopixLexer.mll index 980c832..5e6312e 100644 --- a/flap/src/hopix/hopixLexer.mll +++ b/flap/src/hopix/hopixLexer.mll @@ -15,18 +15,35 @@ } let newline = ('\010' | '\013' | "\013\010") - let blank = [' ' '\009' '\012'] let digit = ['0'-'9'] +let hexa = "0x" ['0'-'9' 'a'-'f' 'A'-'F'] +let bina = "0b" ['0'-'1'] +let octa = "0o" ['0'-'7'] +let integers = '-'? (digit+ + | hexa+ + | bina+ + | octa+) + +let ident = ['a'-'z']['A'-'Z' 'a'-'z' '0'-'9' '_']* rule token = parse (** Layout *) | newline { next_line_and token lexbuf } | blank+ { token lexbuf } - | eof { EOF } + | eof { EOF } - (** Lexing error. *) + (** Keywords *) + | "let" { LET } + + (** Operators *) + | '=' { EQUAL } + + (** Values *) + | integers as i { INT (Mint.of_string i) } + | ident as s { ID s } + + (** Lexing error *) | _ { error lexbuf "unexpected character." } - diff --git a/flap/src/hopix/hopixParser.mly b/flap/src/hopix/hopixParser.mly index 9d94e29..14a8a6e 100644 --- a/flap/src/hopix/hopixParser.mly +++ b/flap/src/hopix/hopixParser.mly @@ -3,20 +3,46 @@ open HopixAST open Position - %} -%token EOF +%token EOF LET EQUAL +%token INT +%token ID %start program %% -program: EOF -{ - [] -} +program: +| definition=located(definition)* EOF { + definition + } + +definition: +| v=vdefinition { + DefineValue v + } + +vdefinition: // manque le type ici, on met None en attendant +| LET i=located(identifier) EQUAL e=located(expression) { + SimpleValue(i, None, e) + } + +expression: +| l=located(literal) { + Literal l + } + +literal: +| i=INT { + LInt i + } + +identifier: +| i=ID { + Id i + } %inline located(X): x=X { Position.with_poss $startpos $endpos x