-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
211 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
|
||
genericLexer someLexer; | ||
|
||
[Mode("EXT", "default")] | ||
@label("en","integer"); | ||
@label("fr","entier"); | ||
[Int] INT; | ||
|
||
@label("en","plus sign"); | ||
@label("fr","plus"); | ||
[Sugar] PLUS : "+"; | ||
|
||
@label("en","addition"); | ||
@label("fr","addition"); | ||
[KeyWord] ADD : "add"; | ||
|
||
@label("en","minus sign"); | ||
@label("fr","moins"); | ||
[Sugar] MINUS : "-"; | ||
|
||
@label("en","substraction"); | ||
@label("fr","soustraction"); | ||
[KeyWord] REMOVE : "remove"; | ||
|
||
@label("en","times sign"); | ||
@label("fr","fois"); | ||
[Sugar] TIMES : "*"; | ||
|
||
@label("en","multiplication"); | ||
@label("fr","multiplication"); | ||
[KeyWord] MUL : "mul"; | ||
|
||
@label("en","division sign"); | ||
@label("fr","diviser"); | ||
[Sugar] SLASH : "/"; | ||
|
||
@label("en","division"); | ||
@label("fr","division"); | ||
[KeyWord] DIV : "div"; | ||
|
||
[Mode("EXT", "default")] | ||
[Push("EXT")] | ||
[Sugar] OPEN : ">>>"; | ||
|
||
[Pop] | ||
[Sugar] CLOSE : "<<<"; | ||
|
||
|
||
|
||
parser someParser; | ||
|
||
-> root : someParser_expressions; | ||
[Right 10] PLUS; | ||
[Right 10] ADD; | ||
[Right 10] MINUS; | ||
[Right 10] REMOVE; | ||
[Right 50] TIMES; | ||
[Right 50] MUL; | ||
[Right 50] DIV; | ||
[Right 50] SLASH; | ||
[Prefix 100] PLUS; | ||
[Prefix 100] ADD; | ||
[Prefix 100] "#'"; | ||
[Prefix 100] MINUS; | ||
[Prefix 100] REMOVE; | ||
[Prefix 100] "~'"; | ||
[Operand] integer : INT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using sly.lexer; | ||
using sly.lexer.fsm; | ||
using sly.i18n; | ||
|
||
namespace ns | ||
{ | ||
public enum someLexer | ||
{ | ||
[LexemeLabel("en", "integer")] | ||
[LexemeLabel("fr", "entier")] | ||
[Mode("EXT", "default")] | ||
[Int] | ||
INT, | ||
[LexemeLabel("en", "plus sign")] | ||
[LexemeLabel("fr", "plus")] | ||
[Sugar("+")] | ||
PLUS, | ||
[LexemeLabel("en", "addition")] | ||
[LexemeLabel("fr", "addition")] | ||
[Keyword("add")] | ||
ADD, | ||
[LexemeLabel("en", "minus sign")] | ||
[LexemeLabel("fr", "moins")] | ||
[Sugar("-")] | ||
MINUS, | ||
[LexemeLabel("en", "substraction")] | ||
[LexemeLabel("fr", "soustraction")] | ||
[Keyword("remove")] | ||
REMOVE, | ||
[LexemeLabel("en", "times sign")] | ||
[LexemeLabel("fr", "fois")] | ||
[Sugar("*")] | ||
TIMES, | ||
[LexemeLabel("en", "multiplication")] | ||
[LexemeLabel("fr", "multiplication")] | ||
[Keyword("mul")] | ||
MUL, | ||
[LexemeLabel("en", "division sign")] | ||
[LexemeLabel("fr", "diviser")] | ||
[Sugar("/")] | ||
SLASH, | ||
[LexemeLabel("en", "division")] | ||
[LexemeLabel("fr", "division")] | ||
[Keyword("div")] | ||
DIV, | ||
[LexemeLabel("en", "test")] | ||
[LexemeLabel("fr", "test")] | ||
[Extension] | ||
TEST, | ||
[Push("EXT")] | ||
[Mode("EXT", "default")] | ||
[Sugar(">>>")] | ||
OPEN, | ||
[Pop] | ||
[Sugar("<<<")] | ||
CLOSE, | ||
} | ||
|
||
public class ExtendedsomeLexer | ||
{ | ||
public static void ExtendsomeLexer(someLexer token, LexemeAttribute lexem, GenericLexer<someLexer> lexer) | ||
{ | ||
if (token == someLexer.TEST) | ||
{ | ||
NodeCallback<GenericToken> callbackTEST = (FSMMatch<GenericToken> match) => | ||
{ | ||
// this store the token id the the FSMMatch object to be later returned by GenericLexer.Tokenize | ||
match.Properties[GenericLexer<someLexer>.DerivedToken] = someLexer.TEST; | ||
return match; | ||
}; | ||
var builder = lexer.FSMBuilder; | ||
builder.GoTo("start").Transition('#').MultiRangeTransition(('0', '9'), ('A', 'F')).MultiRangeTransition(('0', '9'), ('A', 'F')).MultiRangeTransition(('0', '9'), ('A', 'F')).MultiRangeTransition(('0', '9'), ('A', 'F')).MultiRangeTransition(('0', '9'), ('A', 'F')).MultiRangeTransition(('0', '9'), ('A', 'F')).End(GenericToken.Extension).CallBack(callbackTEST); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using sly.lexer; | ||
using sly.parser.generator; | ||
using System.Collections.Generic; | ||
using sly.parser.parser; | ||
|
||
namespace ns | ||
{ | ||
[ParserRoot("root")] | ||
public class someParser | ||
{ | ||
[Production("root : someParser_expressions")] | ||
public int root_someParserexpressions(int p0) | ||
{ | ||
return default(int); | ||
} | ||
|
||
[Infix("PLUS", Associativity.Right, 10)] | ||
[Infix("ADD", Associativity.Right, 10)] | ||
public int PLUS_ADD_(int left, Token<someLexer> oper, int right) | ||
{ | ||
return left; | ||
} | ||
|
||
[Infix("MINUS", Associativity.Right, 10)] | ||
[Infix("REMOVE", Associativity.Right, 10)] | ||
public int minus(int left, Token<someLexer> oper, int right) | ||
{ | ||
return left; | ||
} | ||
|
||
[Infix("TIMES", Associativity.Right, 50)] | ||
[Infix("MUL", Associativity.Right, 50)] | ||
public int TIMES_MUL_(int left, Token<someLexer> oper, int right) | ||
{ | ||
return left; | ||
} | ||
|
||
[Infix("DIV", Associativity.Right, 50)] | ||
[Infix("SLASH", Associativity.Right, 50)] | ||
public int div(int left, Token<someLexer> oper, int right) | ||
{ | ||
return left; | ||
} | ||
|
||
[Prefix("PLUS", Associativity.Left, 100)] | ||
[Prefix("ADD", Associativity.Left, 100)] | ||
[Prefix("'#'", Associativity.Left, 100)] | ||
public int PLUS_ADD_prefix0_(Token<someLexer> oper, int value) | ||
{ | ||
return value; | ||
} | ||
|
||
[Prefix("MINUS", Associativity.Left, 100)] | ||
[Prefix("REMOVE", Associativity.Left, 100)] | ||
[Prefix("'~'", Associativity.Left, 100)] | ||
public int MINUS_REMOVE_prefix1_(Token<someLexer> oper, int value) | ||
{ | ||
return value; | ||
} | ||
|
||
[Operand] | ||
[Production("integer : INT")] | ||
public int integer_INT(Token<someLexer> p0) | ||
{ | ||
return default(int); | ||
} | ||
} | ||
} |