changeset 3:9176d9aa3163

Ignore CR characters in the lexer for Windows files
author Mike Spivey <mike@cs.ox.ac.uk>
date Mon, 15 Oct 2018 16:23:49 +0100
parents c9123a24f544
children 9f5c8e19f204
files .gitignore lab0/lexer.mll lab1/lexer.mll lab2/lexer.mll lab3/lexer.mll lab4/lexer.mll ppc/lexer.mll
diffstat 7 files changed, 120 insertions(+), 113 deletions(-) [+]
line wrap: on
line diff
--- a/.gitignore	Mon Oct 15 16:23:30 2018 +0100
+++ b/.gitignore	Mon Oct 15 16:23:49 2018 +0100
@@ -4,12 +4,9 @@
 *.cmi
 *.cmo
 *~
-keiko/interp.c
-keiko/keiko.h
 keiko/obx-t.a
 keiko/pplink
 keiko/ppx
-keiko/template.c
 lab1/a.k
 lab1/a.test
 lab1/a.x
--- a/lab0/lexer.mll	Mon Oct 15 16:23:30 2018 +0100
+++ b/lab0/lexer.mll	Mon Oct 15 16:23:49 2018 +0100
@@ -20,6 +20,7 @@
     | "*"               { TIMES }
     | "/"               { DIVIDE }
     | [' ''\t']+        { token lexbuf }
+    | "\r"              { comment lexbuf }
     | "\n"              { token lexbuf }
     | _                 { BADTOK }
     | eof               { EOF }
--- a/lab1/lexer.mll	Mon Oct 15 16:23:30 2018 +0100
+++ b/lab1/lexer.mll	Mon Oct 15 16:23:49 2018 +0100
@@ -63,6 +63,7 @@
     | ":="              { ASSIGN }
     | [' ''\t']+        { token lexbuf }
     | "(*"              { comment lexbuf; token lexbuf }
+    | "\r"              { token lexbuf }
     | "\n"              { incr lineno; Source.note_line !lineno lexbuf;
                           token lexbuf }
     | _                 { BADTOK }
--- a/lab2/lexer.mll	Mon Oct 15 16:23:30 2018 +0100
+++ b/lab2/lexer.mll	Mon Oct 15 16:23:49 2018 +0100
@@ -54,6 +54,7 @@
     | ":="              { ASSIGN }
     | [' ''\t']+        { token lexbuf }
     | "(*"              { comment lexbuf; token lexbuf }
+    | "\r"              { token lexbuf }
     | "\n"              { incr lineno; Source.note_line !lineno lexbuf;
                           token lexbuf }
     | _                 { BADTOK }
--- a/lab3/lexer.mll	Mon Oct 15 16:23:30 2018 +0100
+++ b/lab3/lexer.mll	Mon Oct 15 16:23:49 2018 +0100
@@ -27,35 +27,38 @@
 let lineno = ref 1
 }
 
-rule token = parse
-  ['A'-'Z''a'-'z']['A'-'Z''a'-'z''0'-'9''_']* as s
+rule token =
+  parse
+     ['A'-'Z''a'-'z']['A'-'Z''a'-'z''0'-'9''_']* as s
                         { lookup s }
-| ['0'-'9']+ as s       { NUMBER (int_of_string s) }
-| "="                   { RELOP Eq }
-| "+"                   { ADDOP Plus }
-| "-"                   { MINUS }
-| "*"                   { MULOP Times }
-| "<"                   { RELOP Lt }
-| ">"                   { RELOP Gt }
-| "<>"                  { RELOP Neq }
-| "<="                  { RELOP Leq }
-| ">="                  { RELOP Geq }
-| "("                   { LPAR }
-| ")"                   { RPAR }
-| ","                   { COMMA }
-| ";"                   { SEMI }
-| "."                   { DOT }
-| ":="                  { ASSIGN }
-| [' ''\t']+            { token lexbuf }
-| "(*"                  { comment lexbuf; token lexbuf }
-| '\n'                  { incr lineno; Source.note_line !lineno lexbuf;
+    | ['0'-'9']+ as s   { NUMBER (int_of_string s) }
+    | "="               { RELOP Eq }
+    | "+"               { ADDOP Plus }
+    | "-"               { MINUS }
+    | "*"               { MULOP Times }
+    | "<"               { RELOP Lt }
+    | ">"               { RELOP Gt }
+    | "<>"              { RELOP Neq }
+    | "<="              { RELOP Leq }
+    | ">="              { RELOP Geq }
+    | "("               { LPAR }
+    | ")"               { RPAR }
+    | ","               { COMMA }
+    | ";"               { SEMI }
+    | "."               { DOT }
+    | ":="              { ASSIGN }
+    | [' ''\t']+        { token lexbuf }
+    | "(*"              { comment lexbuf; token lexbuf }
+    | "\r"              { token lexbuf }
+    | "\n"              { incr lineno; Source.note_line !lineno lexbuf;
                           token lexbuf }
-| _                     { BADTOK }
-| eof                   { EOF }
+    | _                 { BADTOK }
+    | eof               { EOF }
 
-and comment = parse
-  "*)"                  { () }
-| "\n"                  { incr lineno; Source.note_line !lineno lexbuf;
+and comment =
+  parse
+      "*)"              { () }
+    | "\n"              { incr lineno; Source.note_line !lineno lexbuf;
                           comment lexbuf }
-| _                     { comment lexbuf }
-| eof                   { () }
+    | _                 { comment lexbuf }
+    | eof               { () }
--- a/lab4/lexer.mll	Mon Oct 15 16:23:30 2018 +0100
+++ b/lab4/lexer.mll	Mon Oct 15 16:23:49 2018 +0100
@@ -68,46 +68,48 @@
 let notq = [^'\'']
 let notqq = [^'"']
 
-rule token = parse
-  letter (letter | digit | '_')* as s
-                                { lookup s }
-| digit+ as s                   { NUMBER (int_of_string s) }
-| q (notq as c) q               { CHAR c }
-| q q q q                       { CHAR '\'' }
-| qq ((notqq | qq qq)* as s) qq { get_string s }
-| ";"                           { SEMI }
-| "."                           { DOT }
-| "|"                           { VBAR }
-| ":"                           { COLON }
-| "^"                           { ARROW }
-| "("                           { LPAR }
-| ")"                           { RPAR }
-| ","                           { COMMA }
-| "["                           { SUB }
-| "]"                           { BUS }
-| "="                           { EQUAL }
-| "+"                           { ADDOP Plus }
-| "-"                           { MINUS }
-| "*"                           { MULOP Times }
-| "<"                           { RELOP Lt }
-| ">"                           { RELOP Gt }
-| "<>"                          { RELOP Neq }
-| "<="                          { RELOP Leq }
-| ">="                          { RELOP Geq }
-| ":="                          { ASSIGN }
-| [' ''\t']+                    { token lexbuf }
-| "(*"                          { comment lexbuf; token lexbuf }
-| "\n"                          { next_line lexbuf; token lexbuf }
-| _                             { BADTOK }
-| eof                           { err_message "unexpected end of file" 
-                                    [] !lineno; 
-                                  exit 1 }
+rule token = 
+  parse
+      letter (letter | digit | '_')* as s
+                        { lookup s }
+    | digit+ as s       { NUMBER (int_of_string s) }
+    | q (notq as c) q   { CHAR c }
+    | q q q q           { CHAR '\'' }
+    | qq ((notqq | qq qq)* as s) qq     
+                        { get_string s }
+    | ";"               { SEMI }
+    | "."               { DOT }
+    | "|"               { VBAR }
+    | ":"               { COLON }
+    | "^"               { ARROW }
+    | "("               { LPAR }
+    | ")"               { RPAR }
+    | ","               { COMMA }
+    | "["               { SUB }
+    | "]"               { BUS }
+    | "="               { EQUAL }
+    | "+"               { ADDOP Plus }
+    | "-"               { MINUS }
+    | "*"               { MULOP Times }
+    | "<"               { RELOP Lt }
+    | ">"               { RELOP Gt }
+    | "<>"              { RELOP Neq }
+    | "<="              { RELOP Leq }
+    | ">="              { RELOP Geq }
+    | ":="              { ASSIGN }
+    | [' ''\t']+        { token lexbuf }
+    | "(*"              { comment lexbuf; token lexbuf }
+    | "\r"              { token lexbuf }
+    | "\n"              { next_line lexbuf; token lexbuf }
+    | _                 { BADTOK }
+    | eof               { err_message "unexpected end of file" [] !lineno; 
+                          exit 1 }
 
-and comment = parse
-  "*)"                          { () }
-| "\n"                          { next_line lexbuf; comment lexbuf }
-| _                             { comment lexbuf }
-| eof                           { err_message "end of file in comment" 
-                                    [] !lineno; 
-                                  exit 1 }
+and comment = 
+  parse
+      "*)"              { () }
+    | "\n"              { next_line lexbuf; comment lexbuf }
+    | _                 { comment lexbuf }
+    | eof               { err_message "end of file in comment" [] !lineno; 
+                          exit 1 }
 
--- a/ppc/lexer.mll	Mon Oct 15 16:23:30 2018 +0100
+++ b/ppc/lexer.mll	Mon Oct 15 16:23:49 2018 +0100
@@ -68,46 +68,48 @@
 let notq = [^'\'']
 let notqq = [^'"']
 
-rule token = parse
-  letter (letter | digit | '_')* as s
-                                { lookup s }
-| digit+ as s                   { NUMBER (int_of_string s) }
-| q (notq as c) q               { CHAR c }
-| q q q q                       { CHAR '\'' }
-| qq ((notqq | qq qq)* as s) qq { get_string s }
-| ";"                           { SEMI }
-| "."                           { DOT }
-| "|"                           { VBAR }
-| ":"                           { COLON }
-| "^"                           { ARROW }
-| "("                           { LPAR }
-| ")"                           { RPAR }
-| ","                           { COMMA }
-| "["                           { SUB }
-| "]"                           { BUS }
-| "="                           { EQUAL }
-| "+"                           { ADDOP Plus }
-| "-"                           { MINUS }
-| "*"                           { MULOP Times }
-| "<"                           { RELOP Lt }
-| ">"                           { RELOP Gt }
-| "<>"                          { RELOP Neq }
-| "<="                          { RELOP Leq }
-| ">="                          { RELOP Geq }
-| ":="                          { ASSIGN }
-| [' ''\t']+                    { token lexbuf }
-| "(*"                          { comment lexbuf; token lexbuf }
-| "\n"                          { next_line lexbuf; token lexbuf }
-| _                             { BADTOK }
-| eof                           { err_message "unexpected end of file" 
-                                    [] !lineno; 
-                                  exit 1 }
+rule token = 
+  parse
+      letter (letter | digit | '_')* as s
+                        { lookup s }
+    | digit+ as s       { NUMBER (int_of_string s) }
+    | q (notq as c) q   { CHAR c }
+    | q q q q           { CHAR '\'' }
+    | qq ((notqq | qq qq)* as s) qq     
+                        { get_string s }
+    | ";"               { SEMI }
+    | "."               { DOT }
+    | "|"               { VBAR }
+    | ":"               { COLON }
+    | "^"               { ARROW }
+    | "("               { LPAR }
+    | ")"               { RPAR }
+    | ","               { COMMA }
+    | "["               { SUB }
+    | "]"               { BUS }
+    | "="               { EQUAL }
+    | "+"               { ADDOP Plus }
+    | "-"               { MINUS }
+    | "*"               { MULOP Times }
+    | "<"               { RELOP Lt }
+    | ">"               { RELOP Gt }
+    | "<>"              { RELOP Neq }
+    | "<="              { RELOP Leq }
+    | ">="              { RELOP Geq }
+    | ":="              { ASSIGN }
+    | [' ''\t']+        { token lexbuf }
+    | "(*"              { comment lexbuf; token lexbuf }
+    | "\r"              { comment lexbuf }
+    | "\n"              { next_line lexbuf; token lexbuf }
+    | _                 { BADTOK }
+    | eof               { err_message "unexpected end of file" [] !lineno; 
+                          exit 1 }
 
-and comment = parse
-  "*)"                          { () }
-| "\n"                          { next_line lexbuf; comment lexbuf }
-| _                             { comment lexbuf }
-| eof                           { err_message "end of file in comment" 
-                                    [] !lineno; 
-                                  exit 1 }
+and comment = 
+  parse
+      "*)"              { () }
+    | "\n"              { next_line lexbuf; comment lexbuf }
+    | _                 { comment lexbuf }
+    | eof               { err_message "end of file in comment" [] !lineno; 
+                          exit 1 }