Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ramscript
- import (
- "strconv"
- "errors"
- )
- /* SLICING */
- // Sliciing is the practice of cutting the code up into individual expressions.
- func slice(data string) ([]string, error) {
- sliced := make([]string,0,0)
- curSlice := ""
- inString := false
- for x := 0; x < len(data); x ++{
- if !inString{
- if (string(data[x]) == "\""){
- curSlice, sliced = clearSliced(curSlice, sliced)
- inString = true
- curSlice += string(data[x])
- } else if string(data[x]) == " " || string(data[x]) == "\n"{
- curSlice, sliced = clearSliced(curSlice, sliced)
- } else if checkForDoubleSymbols("=","=",data,x){
- sliced, curSlice, x = appendDoubleSymbols("=", "=", data, x, sliced, curSlice)
- } else if checkForDoubleSymbols("!","=",data,x){
- sliced, curSlice, x = appendDoubleSymbols("!", "=", data, x, sliced, curSlice)
- } else if checkForDoubleSymbols("<","=",data,x){
- sliced, curSlice, x = appendDoubleSymbols("<", "=", data, x, sliced, curSlice)
- } else if checkForDoubleSymbols(">","=",data,x){
- sliced, curSlice, x = appendDoubleSymbols(">", "=", data, x, sliced, curSlice)
- } else if checkForDoubleSymbols("&","&",data,x){
- sliced, curSlice, x = appendDoubleSymbols("&", "&", data, x, sliced, curSlice)
- } else if checkForDoubleSymbols("^","^",data,x){
- sliced, curSlice, x = appendDoubleSymbols("^", "^", data, x, sliced, curSlice)
- } else if checkForDoubleSymbols("|","|",data,x){
- sliced, curSlice, x = appendDoubleSymbols("|", "|", data, x, sliced, curSlice)
- } else if checkForDoubleSymbols("!","!",data,x){
- sliced, curSlice, x = appendDoubleSymbols("!", "!", data, x, sliced, curSlice)
- } else if checkForDoubleSymbols("+","=",data,x){
- sliced, curSlice, x = appendDoubleSymbols("+", "=", data, x, sliced, curSlice)
- } else if checkForDoubleSymbols("-","=",data,x){
- sliced, curSlice, x = appendDoubleSymbols("-", "=", data, x, sliced, curSlice)
- } else if checkForDoubleSymbols("*","=",data,x){
- sliced, curSlice, x = appendDoubleSymbols("*", "=", data, x, sliced, curSlice)
- } else if checkForDoubleSymbols("/","=",data,x){
- sliced, curSlice, x = appendDoubleSymbols("/", "=", data, x, sliced, curSlice)
- } else if checkForDoubleSymbols("%","=",data,x){
- sliced, curSlice, x = appendDoubleSymbols("%", "=", data, x, sliced, curSlice)
- } else if checkForDoubleSymbols("^","=",data,x){
- sliced, curSlice, x = appendDoubleSymbols("^", "=", data, x, sliced, curSlice)
- } else if checkForDoubleSymbols("@","=",data,x){
- sliced, curSlice, x = appendDoubleSymbols("@", "=", data, x, sliced, curSlice)
- } else if string(data[x]) == "(" || string(data[x]) == ")" || string(data[x]) == "," || string(data[x]) == "[" || string(data[x]) == "]" || string(data[x]) == "{" || string(data[x]) == "}" || string(data[x]) == ";" || string(data[x]) == ":" || string(data[x]) == "+" || string(data[x]) == "-" || string(data[x]) == "*" || string(data[x]) == "/" || string(data[x]) == "^" || string(data[x]) == "@" || string(data[x]) == "%" || string(data[x]) == "&" || (string(data[x]) == "." && x < len(string(data)) && !isNum(string(data[x+1]))){
- curSlice, sliced = clearSliced(curSlice, sliced)
- sliced = append(sliced, string(data[x]))
- } else {
- curSlice += string(data[x])
- }
- }else/*if inString*/ {
- curSlice += string(data[x])
- if string(data[x-1]) != "\\" && string(data[x]) == "\"" {
- curSlice, sliced = clearSliced(curSlice, sliced)
- inString = false
- }
- }
- }
- if !inString{
- return sliced, nil
- } else/*if inString*/{
- return sliced, errors.New("[SYNTAX] Your quote marks are invalid.")
- }
- }
- func checkForDoubleSymbols(symbol1 string, symbol2 string, data string, position int) bool {
- if position+1 <= len(string(data)) - 1 && string(data[position]) == symbol1 && string(data[position + 1]) == symbol2 {
- return true
- } else {
- return false
- }
- }
- func appendDoubleSymbols(symbol1 string, symbol2 string, data string, position int, sliced []string, curSlice string) ([]string, string, int) {
- curSlice, sliced = clearSliced(curSlice, sliced)
- sliced = append(sliced, "==")
- position ++;
- return sliced, curSlice, position
- }
- func clearSliced(curSlice string, sliced []string) (string, []string){
- if curSlice != "" {
- sliced = append(sliced, curSlice)
- }
- curSlice = ""
- return curSlice, sliced
- }
- func isNum(value string) bool {
- if _, err := strconv.Atoi(value); err == nil {
- return true
- }else{
- return false
- }
- }
- /* COMMON EXCEPTION CHECK*/
- // This is done to check the layout of the slices, and make sure they make sense.
- func commonExceptionCheck(data []string) error {
- //matching squiglys, squares, and parenthesis
- if true {
- var parenInset int = 0
- var squiglyInset int = 0
- var squareInset int = 0
- for x := 0; x < len(data); x ++ {
- if string(data[x]) == "["{
- squareInset++
- } else if string(data[x]) == "]"{
- squareInset--
- } else if string(data[x]) == "{" {
- squiglyInset++
- } else if string(data[x]) == "}" {
- squiglyInset--
- } else if string(data[x]) == "(" {
- parenInset++
- } else if string(data[x]) == ")" {
- parenInset--
- }
- }
- if parenInset != 0 {
- return errors.New("[SYNTAX] Your parenthesis don't match up.")
- } else if squiglyInset != 0 {
- return errors.New("[SYNTAX] Your squigly brackets don't match up.")
- } else if squareInset != 0 {
- return errors.New("[SYNTAX] Your square brackets don't match up.")
- }
- }
- //reasonable statement size
- if true {
- prevEndl := 0
- for x := 0; x < len(data); x ++ {
- if string(data[x]) == ";" {
- if x - prevEndl > 3 {
- prevEndl = x
- } else {
- return errors.New("[SYNTAX] One of your statements has an invalid length.")
- }
- }
- }
- }
- //reasonable operator placement
- for x := 0; x < len(data); x ++ {
- if x < len(data) - 1 && isOperator(string(data[x])) && isOperatorNotIncludingMinus(string(data[x+1])) {
- return errors.New("[SYNTAX] One of your operators is placed illegally.")
- }
- }
- //reasonable code ending
- if string(data[len(data) - 1]) != ";" && string(data[len(data) - 1] ) != "}" || isOperator(string(data[len(data) - 1])) {
- return errors.New("[SYNTAX] Your code doesn't end properly.")
- }
- return nil
- }
- func isOperator(potential string) bool {
- if potential == "+" || potential == "-" || potential == "*" || potential == "/" || potential == "^" || potential == "%" || potential == "==" || potential == "!=" || potential == "<=" || potential == ">=" || potential == ">" || potential == "<" || potential == "&&" || potential == "||" || potential == "^^" || potential == "!!" || potential == "!" || potential == "+=" || potential == "-=" || potential == "*=" || potential == "%=" || potential == "^=" || potential == "@=" || potential == "@" {
- return true
- } else {
- return false
- }
- }
- func isOperatorNotIncludingMinus(potential string) bool {
- if isOperator(potential) && potential != "-" {
- return true
- } else {
- return false
- }
- }
- /* LEXING */
- // This is done to catagorize each slice, and organize the slices into tree structures.
- func lex(sliced []string) ([]Statement, error) {
- statements := make([]Statement,0,0)
- for x := 0; x < len(sliced); x ++ {
- }
- return statements, nil
- }
- /* SECONDARY EXCEPTION CHECK*/
- // This is done to check for exceptions that are faster to find after lexing is finished.
- func secondaryExceptionCheck(statements []Statement) error {
- //variables are only in their scopes
- //operators are surrounded by usable datatypes
- //reasonable statement beginning
- return nil
- }
- /* EXECUTION */
- // This is done to acually execute the code, which should have been prepared in previous steps.
- func execute(statements []Statement, scoped bool) error {
- return nil
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement