Started working on '+' operator

This commit is contained in:
2024-10-24 14:39:28 -04:00
parent c894ee4c0d
commit 139c88dd58
2 changed files with 9 additions and 4 deletions

View File

@@ -11,7 +11,7 @@ import (
const CONCAT rune = '~'
func isOperator(c rune) bool {
if c == '*' || c == '|' || c == CONCAT {
if c == '+' || c == '*' || c == '|' || c == CONCAT {
return true
}
return false
@@ -19,7 +19,7 @@ func isOperator(c rune) bool {
/* priority returns the priority of the given operator */
func priority(op rune) int {
precedence := []rune{'|', CONCAT, '*'}
precedence := []rune{'|', CONCAT, '+', '*'}
return slices.Index(precedence, op)
}
@@ -138,6 +138,8 @@ func thompson(re string) *State {
}
stateToAdd.transitions[s1.content] = append(stateToAdd.transitions[s1.content], s1)
nfa = append(nfa, stateToAdd)
case '+':
case '|':
s1 := pop(&nfa)
s2 := pop(&nfa)