mirror of
https://github.com/Ed94/LangStudies.git
synced 2025-01-22 04:23:45 -08:00
SRegEx works!!!!
Its not a full flegged transpiler but it works at least on RDP's lexer. I can expand on demand.
This commit is contained in:
parent
5ae405e284
commit
17c3b8fe36
@ -1,5 +1,7 @@
|
||||
extends Object
|
||||
|
||||
var SRegEx = preload("res://RegM/Scripts/SRegex.gd").new()
|
||||
|
||||
|
||||
class_name Lexer
|
||||
|
||||
@ -118,17 +120,17 @@ const Spec : Dictionary = \
|
||||
#Operators
|
||||
|
||||
# Logical
|
||||
TokenType.op_Relational : "^[>\\<]=?",
|
||||
TokenType.op_Relational : "^[><]=?",
|
||||
TokenType.op_Equality : "^[=!]=",
|
||||
TokenType.op_LAnd : "^&&",
|
||||
TokenType.op_LOr : "^\\|\\|",
|
||||
TokenType.op_LNot : "^!",
|
||||
|
||||
# Arithmetic
|
||||
TokenType.op_CAssign : "^[*\\/\\+\\-]=",
|
||||
TokenType.op_CAssign : "^[\\*\\/+-]=",
|
||||
TokenType.op_Assign : "^=",
|
||||
TokenType.op_Additive : "^[+\\-]",
|
||||
TokenType.op_Multiplicative : "^[*\\/]",
|
||||
TokenType.op_Additive : "^[+-]",
|
||||
TokenType.op_Multiplicative : "^[\\*\\/]",
|
||||
|
||||
# Literals
|
||||
TokenType.literal_BTrue : "^\\btrue\\b",
|
||||
@ -142,11 +144,11 @@ const Spec : Dictionary = \
|
||||
TokenType.sym_Identifier : "^\\w+"
|
||||
}
|
||||
|
||||
const SSpec : Dictonary =
|
||||
const SSpec : Dictionary = \
|
||||
{
|
||||
# Comments
|
||||
TokenType.cmt_SL : "start // inline.repeat()",
|
||||
TokenType.cmt_ML : "start /* set(whitespace !whitespace).repeat.lazy */",
|
||||
TokenType.cmt_SL : "start // inline.repeat(0-)",
|
||||
TokenType.cmt_ML : "start /* set(whitespace !whitespace).repeat(0-).lazy */",
|
||||
|
||||
# Formatting
|
||||
TokenType.fmt_S : "start whitespace.repeat(1-)",
|
||||
@ -154,7 +156,7 @@ const SSpec : Dictonary =
|
||||
# Delimiters
|
||||
TokenType.delim_Comma : "start ,",
|
||||
TokenType.delim_SMR : "start \\.",
|
||||
|
||||
|
||||
# Statements
|
||||
TokenType.def_End : "start ;",
|
||||
TokenType.def_BStart : "start {",
|
||||
@ -176,8 +178,8 @@ const SSpec : Dictonary =
|
||||
TokenType.def_Else : "start \"else\"",
|
||||
|
||||
# Expressions
|
||||
TokenType.expr_PStart : "start \(",
|
||||
TokenType.expr_PEnd : "start \)",
|
||||
TokenType.expr_PStart : "start \\(",
|
||||
TokenType.expr_PEnd : "start \\)",
|
||||
TokenType.expr_SBStart : "start [",
|
||||
TokenType.expr_SBEnd : "start ]",
|
||||
TokenType.expr_New : "start \"new\"",
|
||||
@ -190,20 +192,20 @@ const SSpec : Dictonary =
|
||||
TokenType.op_Relational : "start set(> <) =.repeat(0-1)",
|
||||
TokenType.op_Equality : "start set(= \\!) =",
|
||||
TokenType.op_LAnd : "start &&",
|
||||
TokenType.op_LOr : "start \\\| \\\|",
|
||||
TokenType.op_LNot : "start \\\!",
|
||||
TokenType.op_LOr : "start \\| \\|",
|
||||
TokenType.op_LNot : "start \\!",
|
||||
|
||||
# Arithmetic
|
||||
TokenType.op_CAssign : "start set(* / + -) =",
|
||||
TokenType.op_CAssign : "start set(* / + \\-) =",
|
||||
TokenType.op_Assign : "start =",
|
||||
TokenType.op_Additive : "start set(+ -)",
|
||||
TokenType.op_Additive : "start set(+ \\-)",
|
||||
TokenType.op_Multiplicative : "start set(* /)",
|
||||
|
||||
# Literals
|
||||
TokenType.literal_BTrue : "start \"true\"",
|
||||
TokenType.literal_BFalse : "start \"false\"",
|
||||
TokenType.literal_Number : "start digit.repeat(1-)",
|
||||
TokenType.literal_String : "start \\\" !set( \\\" ).repeat(1-) \\\" ",
|
||||
TokenType.literal_String : "start \\\" !set( \\\" ).repeat(0-) \\\"",
|
||||
TokenType.literal_Null : "start \"null\"",
|
||||
|
||||
# Symbols
|
||||
@ -227,10 +229,15 @@ func compile_regex():
|
||||
for type in TokenType.values() :
|
||||
var \
|
||||
regex = RegEx.new()
|
||||
regex.compile( Spec[type] )
|
||||
|
||||
var original = Spec[type]
|
||||
var transpiled = SRegEx.transpile(SSpec[type])
|
||||
|
||||
assert(transpiled == original, "transpiled did not match original")
|
||||
|
||||
regex.compile( transpiled )
|
||||
|
||||
SpecRegex[type] = regex
|
||||
# SpecRegex[type].compile( Spec[type] )
|
||||
|
||||
func init(programSrcText):
|
||||
SourceText = programSrcText
|
||||
|
@ -1,7 +1,7 @@
|
||||
## Concatenation
|
||||
|
||||
Regex : `/^AB$/`
|
||||
Psuedo: `start str(AB) end`
|
||||
Regex : `/^AB$/`
|
||||
Psuedo: `start AB end`
|
||||
|
||||
Machine:
|
||||
```
|
||||
@ -12,8 +12,8 @@ Submachine_A --epsilon--> Submachine_B
|
||||
|
||||
## Union
|
||||
|
||||
Regex : `/^A|B$/`
|
||||
Psuedo: `start glyph(A) | glyph(B) end`
|
||||
Regex : `/^A|B$/`
|
||||
Psuedo: `start A | B end`
|
||||
|
||||
Machine:
|
||||
```
|
||||
@ -26,8 +26,8 @@ Machine:
|
||||
|
||||
## Kleene Closure
|
||||
|
||||
Regex : `/^A*$/`
|
||||
Psuedo: `start glyph(A).repeating end`
|
||||
Regex : `/^A*$/`
|
||||
Psuedo: `start A.repeat(0-) end`
|
||||
|
||||
Machine:
|
||||
```
|
||||
|
30
App/RegM/Lectures/Lecture.8.Notes.md
Normal file
30
App/RegM/Lectures/Lecture.8.Notes.md
Normal file
@ -0,0 +1,30 @@
|
||||
# Complex Machines
|
||||
|
||||
Ex:
|
||||
|
||||
RegEx : `/xy*|z`
|
||||
SRegEx: `x y.repeat(0-) | z`
|
||||
|
||||
## Decomposition
|
||||
|
||||
### Stage 1: Union
|
||||
```
|
||||
->o.start (o)
|
||||
\epsilon-> o --xy*-> o -epsilon-->/
|
||||
\epsilon-> o --z---> o -epsilon->/
|
||||
```
|
||||
### Stage 2: Concatenation
|
||||
```
|
||||
->o.start (o)
|
||||
\epsilon -> o --x--> o -epsilon-> o --y* -epsilon->/
|
||||
\epsilon -> o --z--> o -epsilon------------------>/
|
||||
```
|
||||
### Stage 2: Kleene Closure
|
||||
```
|
||||
|<------------<|
|
||||
->epsi -> o -x-> o -epsi-> o -epsi-> o -y-> -epsi-> o ->epsi->|
|
||||
| |>---------------------->| /
|
||||
->o.start (o)
|
||||
\epsi -> o -z-> o -epsi------------------------------------>/
|
||||
```
|
||||
|
11
App/RegM/Lectures/Lecture.9.Notes.md
Normal file
11
App/RegM/Lectures/Lecture.9.Notes.md
Normal file
@ -0,0 +1,11 @@
|
||||
# Syntactic Sugar
|
||||
|
||||
Ex:
|
||||
|
||||
RegEx : `/a+|[0-3]/`
|
||||
SRegEx: `a.repeat(1-) | set(0-3)`
|
||||
|
||||
`A+` === `AA*` === `A.repeat(1-)` === `AA.repeat(0-)`
|
||||
`A?` === `A|ε` === `A.repeat(0-1)`
|
||||
|
||||
`[0-9]` === `0|1|2|3|4|5|6|7|8|9` === `set(0-9)`
|
@ -96,8 +96,6 @@ func union_pair(a : NFA, b : NFA):
|
||||
|
||||
return NFA.new(start, accepting)
|
||||
|
||||
|
||||
|
||||
func test():
|
||||
var state_1 = State.new(false)
|
||||
var state_2 = State.new(true)
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user