Commit db07539a authored by Nicaudie Charlotte's avatar Nicaudie Charlotte

Added debug print tokens, parser is now working

parent f5268155
......@@ -35,8 +35,8 @@
let h = Hashtbl.create 17 in
List.iter (fun (s,t) -> Hashtbl.add h s t) keyword_table;
fun s ->
let s = String.lowercase s in (* not sensitive to casing *)
try List.assoc s keyword_table with _ -> IDENT s
let s = String.lowercase_ascii s in (* not sensitive to casing *)
try List.assoc s keyword_table with _ -> IDENT s (* rend Ident qd il trouve pas dans la table d'assoc*)
let newline lexbuf =
let pos = lexbuf.lex_curr_p in
......@@ -53,8 +53,8 @@ let space = [' ' '\t']
rule get_token = parse
| "#" [^ '\n']* '\n'
| '\n' { newline lexbuf; token lexbuf }
| space+ { token lexbuf }
| '\n' { newline lexbuf; get_token lexbuf }
| space+ { get_token lexbuf }
| ident as id { id_or_kwd id }
(* | '+' { PLUS }
| '-' { MINUS }
......@@ -75,6 +75,6 @@ rule get_token = parse
(* Note : comments cannot be interlocked in Turtle *)
and comment = parse
| "*)" { token lexbuf }
| "*)" { get_token lexbuf }
| _ { comment lexbuf }
| eof { raise (Lexing_error ("unterminated comment")) }
\ No newline at end of file
......@@ -33,8 +33,8 @@ let () =
if !ifile="" then begin eprintf "Aucun fichier a compiler\n@?"; exit 1 end;
(* Ce fichier doit avoir l'extension .logo *)
if not (Filename.check_suffix !ifile ".logo") then begin
eprintf "Le fichier d'entree doit avoir l'extension .logo\n@?";
if not (Filename.check_suffix !ifile ".tjs") then begin
eprintf "Le fichier d'entree doit avoir l'extension .tjs\n@?";
Arg.usage options usage;
exit 1
end;
......@@ -54,7 +54,7 @@ let () =
(*let p = Parser.prog Lexer.token buf in*)
Print_tokens.print stdout buf false;
Print_tokens.print stdout buf;
close_in f;
exit 0;
......
%{ open Ast %}
/*
Tokens declarations
*/
%token <int> INT
%token <float> FLOAT
%token <string> IDENT
%token INIT ITER
%token TRANSLATION ROTATION
%token COMMA SEMICOLON
......
......@@ -7,9 +7,8 @@ let rquote = "\xe2\x80\x98"
let rtriangle = "\xe2\x96\xb8"
let ltriangle = "\xe2\x97\x82"
(** [print_token show_loc out token] prints [token] on the out channel [out].
If [show_loc] is true, prints position informations for the identifiers. *)
let print_token show_loc out = function
(** [print_token out token] prints [token] on the out channel [out]. *)
let print_token out = function
| INIT ->
fprintf out "INIT"
| ITER ->
......@@ -20,19 +19,12 @@ let print_token show_loc out = function
fprintf out "ROTATION"
| OR ->
fprintf out "OR"
| INTEGER ->
fprintf out "INTEGER"
| FLOAT ->
fprintf out "FLOAT"
| INT i ->
fprintf out "INTEGER %d" i
| FLOAT f ->
fprintf out "FLOAT %f" f
| IDENT id ->
if show_loc then
let pos = Location.startpos id in
let l = pos.pos_lnum in
let c = pos.pos_cnum - pos.pos_bol + 1 in
fprintf out "IDENT %s%s%s %s line %d, char %d %s" lquote (Location.content id) rquote rtriangle l c ltriangle
else
fprintf out "IDENT %s%s%s" lquote (Location.content id) rquote
fprintf out "IDENT %s%s%s" lquote id rquote
| COMMA ->
fprintf out "COMMA"
| SEMICOLON ->
......@@ -48,10 +40,10 @@ let print_token show_loc out = function
| EOF ->
fprintf out "EOF"
let print out lexbuf show_loc =
let print out lexbuf =
let token = ref (Lexer.get_token lexbuf) in
fprintf out "%a\n" (print_token show_loc) !token;
fprintf out "%a\n" (print_token) !token;
while !token <> EOF do
token := Lexer.get_token lexbuf;
fprintf out "%a\n" (print_token show_loc) !token
fprintf out "%a\n" (print_token) !token
done
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment