示例#1
0
func getTransitionTableData(itemsets *items.ItemSets) []transitionTableRowData {
	data := make([]transitionTableRowData, itemsets.Size())
	for setNo, set := range itemsets.List() {
		if set.SymbolClasses.MatchAny {
			data[setNo].MatchAny = true
			data[setNo].MatchAnyState = set.DotTransition
		} else {
			data[setNo].MatchAnyState = -1
		}
		data[setNo].SymRange = make([]transitionTableSymRangeData, set.SymbolClasses.Size())
		for rngNo, rng := range set.SymbolClasses.List() {
			data[setNo].SymRange[rngNo].Range = rng.String()
			data[setNo].SymRange[rngNo].Test = rangeTest(rng)
			data[setNo].SymRange[rngNo].State = set.Transitions[rngNo]
		}
		data[setNo].Imports = make([]importTransitionData, len(set.Symbols.ImportIdList))
		for impI, imprt := range set.Symbols.ImportIdList {
			if nextSet := set.ImportTransitions[impI]; nextSet != -1 {
				data[setNo].Imports[impI].Import = imprt
				data[setNo].Imports[impI].ExtFunc = set.Symbols.ExternalFunction(imprt)
				data[setNo].Imports[impI].State = nextSet
			}
		}
	}
	return data
}
示例#2
0
文件: lexer.go 项目: seerdomin/gocc
func getLexerData(pkg, outDir string, itemsets *items.ItemSets, cfg config.Config) *lexerData {
	lexSymbols := itemsets.Symbols().List()
	return &lexerData{
		Debug:       cfg.DebugLexer(),
		TokenImport: path.Join(pkg, "token"),
		UtilImport:  path.Join(pkg, "util"),
		NumStates:   itemsets.Size(),
		NumSymbols:  len(lexSymbols),
		Symbols:     lexSymbols,
	}
}
示例#3
0
文件: acttab.go 项目: seerdomin/gocc
func getActTab(pkg string, itemsets *items.ItemSets, tokMap *token.TokenMap) *actTab {
	actab := &actTab{
		TokenImport: path.Join(pkg, "token"),
		Actions:     make([]action, itemsets.Size()),
	}
	for sno, set := range itemsets.List() {
		if act := set.Action(); act != nil {
			switch act1 := act.(type) {
			case items.Accept:
				actab.Actions[sno].Accept = tokMap.IdMap[string(act1)]
				actab.Actions[sno].Ignore = ""
			case items.Ignore:
				actab.Actions[sno].Accept = -1
				actab.Actions[sno].Ignore = string(act1)
			}
		}
	}
	return actab
}