diff options
| author | Kathy Gray | 2013-07-05 14:57:12 +0100 |
|---|---|---|
| committer | Kathy Gray | 2013-07-05 14:57:12 +0100 |
| commit | 08c4165f6a75952c7c96ed0c69530dcdb09a425f (patch) | |
| tree | 62d7ac1c848bd6f125e5d187343cecac38d920a5 | |
| parent | 6c4f5eb478c44b938fb782f867deae34b70fb480 (diff) | |
More token corrections and additions based on l2_design notes.
Lexer should now be complete
| -rw-r--r-- | src/lexer.mll | 122 | ||||
| -rw-r--r-- | src/parser.mly | 29 |
2 files changed, 117 insertions, 34 deletions
diff --git a/src/lexer.mll b/src/lexer.mll index 60accc9b..1ab7fa26 100644 --- a/src/lexer.mll +++ b/src/lexer.mll @@ -84,6 +84,14 @@ let kw_table = ("union", (fun x -> Union(x))) ("with", (fun x -> With(x))); ("val", (fun x -> Val(x))); + + ("AND", (fun x -> AND(x))); + ("div", (fun x -> Div_(x))); + ("EOR", (fun x -> EOR(x))); + ("mod", (fun x -> Mod(x))); + ("OR", (fun x -> OR(x))); + ("quot", (fun x -> Quot(x))); + ("rem", (fun x -> Rem(x))); ] } @@ -121,6 +129,7 @@ rule token skips = parse | "=" { (Eq(Some(skips),r"=")) } | "!" { (Excl(Some(skips),r"!")) } | ">" { (Gt(Some(skips),r">")) } + | "-" { (Minus(Some(skips))) } | "<" { (Lt(Some(skips),r"<")) } | "+" { (Plus(Some(skips),r"+")) } | ";" { (Semi(Some(skips))) } @@ -134,25 +143,56 @@ rule token skips = parse | "[" { (Lsquare(Some(skips))) } | "]" { (Rsquare(Some(skips))) } | "&&" as i { (AmpAmp(Some(skips),Ulib.Text.of_latin1 i)) } - | "->" { (Arrow(Some(skips))) } | "||" { (BarBar(Some(skips))) } | "|>" { (BarGt(Some(skips))) } | "|]" { (BarSquare(Some(skips))) } + | "^^" { (CarrotCarrot(Some(skips),r"^^")) } | "::" as i { (ColonColon(Some(skips),Ulib.Text.of_latin1 i)) } | ".." { (DotDot(Some(skips)) } + | "=/=" { (EqDivEq(Some(skips),r"=/=")) } | "==" { (EqEq(Some(skips),r"==")) } | "!=" { (ExclEq(Some(skips),r"!=")) } + | "!!" { (ExclExcl(Some(skips),r"!!")) } | ">=" { (GtEq(Some(skips),r">=")) } | ">=+" { (GtEqPlus(Some(skips),r">=+")) } | ">>" { (GtGt(Some(skips),r">>")) } | ">>>" { (GtGtGt(Some(skips),r">>")) } | ">+" { (GtPlus(Some(skips),r">+")) } + | "#>>" { (HashGtGt(Some(skips),r"#>>")) } + | "#<<" { (HashLtLt(Some(skips),r"#<<")) } + | "->" { (MinusGt(Some(skips))) } | "<=" { (LtEq(Some(skips),r"<=")) } | "<=+" { (LtEqPlus(Some(skips),r"<=+")) } + | "<>" { (LtGt(Some(skips),r"<>")) } | "<<" { (LtLt(Some(skips),r"<<")) } | "<<<" { (LtLtLt(Some(skips),r"<<<")) } | "<+" { (LtPlus(Some(skips),r"<+")) } | "**" { (StarStar(Some(skips),r"**")) } + | "~^" { (TildeCarrot(Some(skips),r"~^")) } + + | ">=_s" { (GtEqUnderS(Some(skips),r">=_s")) } + | ">=_si" { (GtEqUnderSi(Some(skips),r">=_si")) } + | ">=_u" { (GtEqUnderU(Some(skips),r">=_u")) } + | ">=_ui" { (GtEqUnderUi(Some(skips),r">=_ui")) } + | ">>_u" { (GtGtUnderU(Some(skips),r">>_u")) } + | ">_s" { (GtUnderS(Some(skips),r">_s")) } + | ">_si" { (GtUnderSi(Some(skips),r">_si")) } + | ">_u" { (GtUnderU(Some(skips),r">_u")) } + | ">_ui" { (GtUnderUi(Some(skips),r">_ui")) } + | "<=_s" { (LtEqUnderS(Some(skips),r"<=_s")) } + | "<=_si" { (LtEqUnderSi(Some(skips),r"<=_si")) } + | "<=_u" { (LtEqUnderU(Some(skips),r"<=_u")) } + | "<=_ui" { (LtEqUnderUi(Some(skips),r"<=_ui")) } + | "<_s" { (LtUnderS(Some(skips),r"<_s")) } + | "<_si" { (LtUnderSi(Some(skips),r"<_si")) } + | "<_u" { (LtUnderU(Some(skips),r"<_u")) } + | "<_ui" { (LtUnderUi(Some(skips),r"<_ui")) } + | "**_s" { (StarStarUnderS(Some(skips),r"**_s")) } + | "**_si" { (StarStarUnderSi(Some(skips),r"**_si")) } + | "*_u" { (StarUnderU(Some(skips),r"*_u")) } + | "*_ui" { (StarUnderUi(Some(skips),r"*_ui")) } + | "2^" { (TwoCarrot(Some(skips),r"2^")) } + | "--" { token (Ast.Com(Ast.Comment(comment lexbuf))::skips) lexbuf } @@ -161,31 +201,61 @@ rule token skips = parse (M.find i kw_table) (Some(skips)) else Id(Some(skips), Ulib.Text.of_latin1 i) } - | "&" oper_char* as i { (AmpI(Some(skips),Ulib.Text.of_latin1 i)) } - | "@" oper_char* as i { (AtI(Some(skips),Ulib.Text.of_latin1 i)) } - | "^" oper_char* as i { (CarrotI(Some(skips),Ulib.Text.of_latin1 i)) } - | "/" oper_char* as i { (DivI(Some(skips),Ulib.Text.of_latin1 i)) } - | "!" oper_char* as i { (ExclI(Some(skips),Ulib.Text.of_latin1 i)) } - | ">" oper_char* as i { (GtI(Some(skips),Ulib.Text.of_latin1 i)) } - | "<" oper_char* as i { (LtI(Some(skips),Ulib.Text.of_latin1 i)) } - | "+" oper_char* as i { (PlusI(Some(skips),Ulib.Text.of_latin1 i)) } - | "*" oper_char* as i { (StarI(Some(skips),Ulib.Text.of_latin1 i)) } - | "~" oper_char* as i { (TildeI(Some(skips),Ulib.Text.of_latin1 i)) } - | "&&" oper_char* as i { (AmpAmpI(Some(skips),Ulib.Text.of_latin1 i)) } - | "::" oper_char* as i { (ColonColonI(Some(skips),Ulib.Text.of_latin1 i)) } - | "==" oper_char* as i { (EqEqI(Some(skips),Ulib.Text.of_latin1 i)) } - | "!=" oper_char* as i { (ExclEqI(Some(skips),Ulib.Text.of_latin1 i)) } - | ">=" oper_char* as i { (GtEqI(Some(skips),Ulib.Text.of_latin1 i)) } - | ">=+" oper_char* as i { (GtEqPlusI(Some(skips),Ulib.Text.of_latin1 i)) } - | ">>" oper_char* as i { (GtGtI(Some(skips),Ulib.Text.of_latin1 i)) } - | ">>>" oper_char* as i { (GtGtGtI(Some(skips),Ulib.Text.of_latin1 i)) } - | ">+" oper_char* as i { (GtPlusI(Some(skips),Ulib.Text.of_latin1 i)) } - | "<=" oper_char* as i { (LtEqI(Some(skips),Ulib.Text.of_latin1 i)) } - | "<=+" oper_char* as i { (LtEqPlusI(Some(skips),Ulib.Text.of_latin1 i)) } - | "<<" oper_char* as i { (LtLtI(Some(skips),Ulib.Text.of_latin1 i)) } - | "<<<" oper_char* as i { (LtLtLtI(Some(skips),Ulib.Text.of_latin1 i)) } - | "<+" oper_char* as i { (LtPlusI(Some(skips),Ulib.Text.of_latin1 i)) } - | "**" oper_char* as i { (StarStarI(Some(skips),Ulib.Text.of_latin1 i)) } + | "&" oper_char+ as i { (AmpI(Some(skips),Ulib.Text.of_latin1 i)) } + | "@" oper_char+ as i { (AtI(Some(skips),Ulib.Text.of_latin1 i)) } + | "^" oper_char+ as i { (CarrotI(Some(skips),Ulib.Text.of_latin1 i)) } + | "/" oper_char+ as i { (DivI(Some(skips),Ulib.Text.of_latin1 i)) } + | "=" oper_char+ as i { (EqI(Some(skips),Ulib.Text.of_latin1 i)) } + | "!" oper_char+ as i { (ExclI(Some(skips),Ulib.Text.of_latin1 i)) } + | ">" oper_char+ as i { (GtI(Some(skips),Ulib.Text.of_latin1 i)) } + | "<" oper_char+ as i { (LtI(Some(skips),Ulib.Text.of_latin1 i)) } + | "+" oper_char+ as i { (PlusI(Some(skips),Ulib.Text.of_latin1 i)) } + | "*" oper_char+ as i { (StarI(Some(skips),Ulib.Text.of_latin1 i)) } + | "~" oper_char+ as i { (TildeI(Some(skips),Ulib.Text.of_latin1 i)) } + | "&&" oper_char+ as i { (AmpAmpI(Some(skips),Ulib.Text.of_latin1 i)) } + | "^^" oper_char+ as i { (CarrotCarrotI(Some(skips),Ulib.Text.of_latin1 i)) } + | "::" oper_char+ as i { (ColonColonI(Some(skips),Ulib.Text.of_latin1 i)) } + | "=/=" oper_char+ as i { (EqDivEqI(Some(skips),Ulib.Text.of_latin1 i)) } + | "==" oper_char+ as i { (EqEqI(Some(skips),Ulib.Text.of_latin1 i)) } + | "!=" oper_char+ as i { (ExclEqI(Some(skips),Ulib.Text.of_latin1 i)) } + | "!!" oper_char+ as i { (ExclExclI(Some(skips),Ulib.Text.of_latin1 i)) } + | ">=" oper_char+ as i { (GtEqI(Some(skips),Ulib.Text.of_latin1 i)) } + | ">=+" oper_char+ as i { (GtEqPlusI(Some(skips),Ulib.Text.of_latin1 i)) } + | ">>" oper_char+ as i { (GtGtI(Some(skips),Ulib.Text.of_latin1 i)) } + | ">>>" oper_char+ as i { (GtGtGtI(Some(skips),Ulib.Text.of_latin1 i)) } + | ">+" oper_char+ as i { (GtPlusI(Some(skips),Ulib.Text.of_latin1 i)) } + | "#>>" oper_char+ as i { (HashGtGt(Some(skips),Ulib.Text.of_latin1 i)) } + | "#<<" oper_char+ as i { (HashLtLt(Some(skips),Ulib.Text.of_latin1 i)) } + | "<=" oper_char+ as i { (LtEqI(Some(skips),Ulib.Text.of_latin1 i)) } + | "<=+" oper_char+ as i { (LtEqPlusI(Some(skips),Ulib.Text.of_latin1 i)) } + | "<<" oper_char+ as i { (LtLtI(Some(skips),Ulib.Text.of_latin1 i)) } + | "<<<" oper_char+ as i { (LtLtLtI(Some(skips),Ulib.Text.of_latin1 i)) } + | "<+" oper_char+ as i { (LtPlusI(Some(skips),Ulib.Text.of_latin1 i)) } + | "**" oper_char+ as i { (StarStarI(Some(skips),Ulib.Text.of_latin1 i)) } + | "~^" oper_char+ as i { (TildeCarrot(Some(skips),Ulib.Text.of_latin1 i)) } + + | ">=_s" oper_char+ as i { (GtEqUnderSI(Some(skips),Ulib.Text.of_latin1 i)) } + | ">=_si" oper_char+ as i { (GtEqUnderSiI(Some(skips),Ulib.Text.of_latin1 i)) } + | ">=_u" oper_char+ as i { (GtEqUnderUI(Some(skips),Ulib.Text.of_latin1 i)) } + | ">=_ui" oper_char+ as i { (GtEqUnderUiI(Some(skips),Ulib.Text.of_latin1 i)) } + | ">>_u" oper_char+ as i { (GtGtUnderUI(Some(skips),Ulib.Text.of_latin1 i)) } + | ">_s" oper_char+ as i { (GtUnderSI(Some(skips),Ulib.Text.of_latin1 i)) } + | ">_si" oper_char+ as i { (GtUnderSiI(Some(skips),Ulib.Text.of_latin1 i)) } + | ">_u" oper_char+ as i { (GtUnderUI(Some(skips),Ulib.Text.of_latin1 i)) } + | ">_ui" oper_char+ as i { (GtUnderUiI(Some(skips),Ulib.Text.of_latin1 i)) } + | "<=_s" oper_char+ as i { (LtEqUnderSI(Some(skips),Ulib.Text.of_latin1 i)) } + | "<=_si" oper_char+ as i { (LtEqUnderSiI(Some(skips),Ulib.Text.of_latin1 i)) } + | "<=_u" oper_char+ as i { (LtEqUnderUI(Some(skips),Ulib.Text.of_latin1 i)) } + | "<=_ui" oper_char+ as i { (LtEqUnderUiI(Some(skips),Ulib.Text.of_latin1 i)) } + | "<_s" oper_char+ as i { (LtUnderSI(Some(skips),Ulib.Text.of_latin1 i)) } + | "<_si" oper_char+ as i { (LtUnderSiI(Some(skips),Ulib.Text.of_latin1 i)) } + | "<_u" oper_char+ as i { (LtUnderUI(Some(skips),Ulib.Text.of_latin1 i)) } + | "<_ui" oper_char+ as i { (LtUnderUiI(Some(skips),Ulib.Text.of_latin1 i)) } + | "**_s" oper_char+ as i { (StarStarUnderSI(Some(skips),Ulib.Text.of_latin1 i)) } + | "**_si" oper_char+ as i { (StarStarUnderSiI(Some(skips),Ulib.Text.of_latin1 i)) } + | "*_u" oper_char+ as i { (StarUnderUI(Some(skips),Ulib.Text.of_latin1 i)) } + | "*_ui" oper_char+ as i { (StarUnderUiI(Some(skips),Ulib.Text.of_latin1 i)) } + | "2^" oper_char+ as i { (TwoCarrotI(Some(skips),Ulib.Text.of_latin1 i)) } | digit+ as i { (Num(Some(skips),int_of_string i)) } | "0b" (binarydigit+ as i) { (Bin(Some(skips), i)) } diff --git a/src/parser.mly b/src/parser.mly index a680b8dd..4dc413ba 100644 --- a/src/parser.mly +++ b/src/parser.mly @@ -130,10 +130,11 @@ let mk_pre_x_l sk1 (sk2,id) sk3 l = %token <Ast.terminal> If_ In IN Let_ Rec Register Struct Switch Then True %token <Ast.terminal> Type Typedef Union With Val -%token <Ast.terminal> Arrow Bar Colon Comma Dot Eof Semi Under -%token <Ast.terminal> Lcurly Rcurly Lparen Rparen Lsquare Rsquare -%token <Ast.terminal> BarBar BarGt BarSquare DotDot LtBar SquareBar +%token <Ast.terminal> AND Div_ EOR Mod OR Quot Rem +%token <Ast.terminal> Bar Colon Comma Dot Eof Minus Semi Under +%token <Ast.terminal> Lcurly Rcurly Lparen Rparen Lsquare Rsquare +%token <Ast.terminal> BarBar BarGt BarSquare DotDot MinusGt LtBar SquareBar %{ (*Terminals with content*) @@ -143,13 +144,25 @@ let mk_pre_x_l sk1 (sk2,id) sk3 l = %token <Ast.terminal * int> Num %token <Ast.terminal * string> String Bin Hex -%token <Ast.terminal * Ulib.Text.t> Amp At Carrot Div Eq Excl Gt Lt Plus Star Tilde -%token <Ast.terminal * Ulib.Text.t> AmpAmp ColonColon EqEq ExclEq GtEq GtEqPlus GtGt -%token <Ast.terminal * Ulib.Text.t> GtGtGt GtPlus LtEq LtEqPlus LtLt LtLtLt LtPlus StarStar +%token <Ast.terminal * Ulib.Text.t> Amp At Carrot Div Eq Excl Gt Lt Plus Star Tilde +%token <Ast.terminal * Ulib.Text.t> AmpAmp CarrotCarrot ColonColon EqDivEq EqEq ExclEq ExclExcl +%token <Ast.terminal * Ulib.Text.t> GtEq GtEqPlus GtGt GtGtGt GtPlus HashGtGt HashLtLt +%token <Ast.terminal * Ulib.Text.t> LtEq LtEqPlus LtGt LtLt LtLtLt LtPlus StarStar TildeCarrot + +%token <Ast.terminal * Ulib.Text.t> GtEqUnderS GtEqUnderSi GtEqUnderU GtEqUnderUi GtGtUnderU GtUnderS +%token <Ast.terminal * Ulib.Text.t> GtUnderSi GtUnderU GtUnderUi LtEqUnderS LtEqUnderSi LtEqUnderU +%token <Ast.terminal * Ulib.Text.t> LtEqUnderUi LtUnderS LtUnderSi LtUnderU LtUnderUi StarUnderS +%token <Ast.terminal * Ulib.Text.t> StarUnderSi StarUnderU StarUnderUi TwoCarrot %token <Ast.terminal * Ulib.Text.t> AmpI AtI CarrotI DivI EqI ExclI GtI LtI PlusI StarI TildeI -%token <Ast.terminal * Ulib.Text.t> AmpAmpI ColonColonI EqEqI ExclEqI GtEqI GtEqPlusI GtGtI -%token <Ast.terminal * Ulib.Text.t> GtGtGtI GtPlusI LtEqI LtEqPlusI LtLtI LtLtLtI LtPlusI StarStarI +%token <Ast.terminal * Ulib.Text.t> AmpAmpI CarrotCarrotI ColonColonI EqDivEqI EqEqI ExclEqI ExclExclI +%token <Ast.terminal * Ulib.Text.t> GtEqI GtEqPlusI GtGtI GtGtGtI GtPlusI HashGtGtI HashLtLtI +%token <Ast.terminal * Ulib.Text.t> LtEqI LtEqPlusI LtGtI LtLtI LtLtLtI LtPlusI StarStarI TildeCarrotI + +%token <Ast.terminal * Ulib.Text.t> GtEqUnderSI GtEqUnderSiI GtEqUnderUI GtEqUnderUiI GtGtUnderUI GtUnderSI +%token <Ast.terminal * Ulib.Text.t> GtUnderSiI GtUnderUI GtUnderUiI LtEqUnderSI LtEqUnderSiI LtEqUnderUI +%token <Ast.terminal * Ulib.Text.t> LtEqUnderUiI LtUnderSI LtUnderSiI LtUnderUI LtUnderUiI StarUnderSI +%token <Ast.terminal * Ulib.Text.t> StarUnderSiI StarUnderUI StarUnderUiI TwoCarrotI %start file %type <Ast.defs> defs |
