new Gcode interpreter

More
29 Mar 2023 00:07 #267742 by fsabbatini
 
Hi again everyone,
Along with the rewrite of the cnc parts to make it industrial, i went ahead and rewrote the complete GCode parser, making it 90% $iemens compatible. Its not finished yet but almost there. 
I had to rewrite the whole parser, changing it from a simple "character eater" parser to a full blown lexer/sintatic/semantic parser. For this purpose i used ANTLR4 for cpp. Now you can throw weird stuff at it like:

N10 
DEF INT INT_VAR='HA5B8', pepe
def string[5] franco
N20 DEF STRING[80] RESULT
N30 RESULT=SPRINT("INTEGER %.'h34's","FRANCO")
int_var = 2 pepe=3 pepe=4

pepe2:
pepe = 1000

int_Var=0
n10 pepe1: int_Var=int_var+1
pepe = pepe + 500

gotob "pepe"<<1
 


YES! goto/gotob/gotof/gotos/gotoc, all are implemented! with the IF (expression) goto ... way of writing things...
Variables declarations, arrays up to three dimensions, of char/int/bool/string types

Weird stuff like this also are just fine

def string[50] franco[3,2], koko
def int francooooo[1,2,3], junco, pepe[2,3,4]
def real jamon[10,15]
def int prueba
def char koka[2]
def int letra

pepe[1,1,1] = 1
pepe[1,1,2] = 2
pepe[0,2,3] = 3
pepe[pepe[1,1,1],1,3] = 8
jamon[pepe[1,1,1], pepe[0,2,3]] = 123.543
jamon[pepe[1,1,1], pepe[1,1,1] + pepe[1,1,2] + pepe[0,2,3]] = (pepe[1,1,3] + jamon[pepe[1,1,1], pepe[0,2,3]])/2

franco[2,1] = "HOLA"
franco[1,1] = "MARISA"
franco[0,0] = "COMO ESTAS"
prueba = 1;
franco[prueba+1, prueba-prueba] = "PEPITO"
prueba = 3;
franco[prueba-1, prueba-2] = franco[2,1] << " " << franco[1,1] << " " << franco[0,0]
koko = "joya"
franco[prueba-1, prueba-2] = franco[prueba-1, prueba-2] << " " << koko << " FACUNDO"
koko = franco[0,0,8] << franco[0,0,9] << franco[0,0,10]

koko[0] = "A"   
koko[1] = "B"
koko[2] = "C"
koko[3] = koko[4]
koko[4] = "E"
koko[5] = "F"
koko[6] = koko[6]
koka[1] = koko[4]

franco[prueba-1, prueba-2] = franco[prueba-1, prueba-2] << koka[1]

koka[0] = franco[prueba-1, prueba-2,2]
koka[0] = "1" * 2
letra = koka[0] + 1
letra = "E" * 2 + 1 - "E"
koka[1] = letra + 1 
koka[1] = "A"
letra = koka[1] + 1
 


Also maths functions with type conversion are allowed!

;def int pepe[5,6]
def int indice=2,indice1=2
def bool pruebaBool
;pruebaBool = isVar("pepe["<<indice<<","<<indice1<<"]")

def real resultado[30]
def int indexs = 0

def real valor

valor = 61.1

resultado[indexs]= cos(valor)
indexs = indexs + 1
resultado[indexs]= sin(valor)
indexs = indexs + 1
resultado[indexs]= tan(89.99999999)
indexs = indexs + 1
resultado[indexs]= asin(1)
indexs = indexs + 1
resultado[indexs]= acos(-1)
indexs = indexs + 1
resultado[indexs]= atan2(12,14.5)
indexs = indexs + 1
resultado[indexs] = sqrt(abs(-3))
indexs = indexs + 1
resultado[indexs] = pot(4)
indexs = indexs + 1
resultado[indexs] = round(4.2)
indexs = indexs + 1
resultado[indexs] = round(4.5)
indexs = indexs + 1
resultado[indexs] = trunc(6.2)
indexs = indexs + 1
resultado[indexs] = trunc(6.8)
indexs = indexs + 1
resultado[indexs] = ln(0.0001)
indexs = indexs + 1
resultado[indexs] = exp(12)
indexs = indexs + 1
resultado[indexs] = minval(10,2)
indexs = indexs + 1
resultado[indexs] = maxval(2.4,1.23)
indexs = indexs + 1
resultado[indexs] = minval(10.4, maxval(1.4,15.23))
indexs = indexs + 'H1'
resultado[indexs] = bound(-.4, 10.4, -10.23)
indexs = indexs + 'b1'
resultado[indexs]= ('HFFA' + 'B011011101') * 1.23ex-3
indexs = indexs + 1
resultado[indexs]= nuMbeR("   -0.1EX2   ") + NumbeR("   +.5ex3 ") - numbeR("   +123.1 ") - number("'h33'")
indexs = indexs + 1 
resultado[indexs]= 5
 


and finally really wierd (maybe not usefull at all haha) but totally fine and working stuff like this

def string[30] pruebaString[2,3] = ("franco","mauro","jose","cordoba","rosario","buenos aires")
def real pruebareal[2,3,4] = set(4,4,,,,2.234)
DEF int FELD1[10,3]=SET(1.2,0,0,10,11,12,20,20,20,30,30,30,40,40,40,)
def int pepe[2,2] = (1)
def int pepe[2,2]   ;


> arreglar
def string[10] franco[20] = rep("FRANCO",3)
DEF int FELD[2,3,4] = REP("S",24)
def int valor = 876
def int repite = 5
def int inicio = 2
def string[30] valorString = "yonoseyono"

pruebareal[0,1,2] = pruebareal[0,1,1] + 1.2


franco[4,0] = "T"
franco[4,1] = "R"
franco[4,2] = franco[4,3]  
franco[4,3] = "S"
franco[4,4] = "a"

feld[1,1,0] = set(12,"A",12,,14,15,,17)


pepe[1,0]=set(4)

pruebaString[1,0] = set("franco1",,"jose3")

FELD1[5,0]=set(1,valor+1)
feld1[5,0]=feld1[5,0]+1
FELD1[5,0]=set(1,feld1[5,0]+1)   ;-> revisar

feld[1,1,1]=rep(valor+1,repite)
franco[inicio] = "REPITEEE"
franco[inicio] = rep(franco[inicio],repite)
franco[inicio+13] = rep(franco[inicio-1],repite)
franco[inicio+15] = set(franco[inicio],"yo!")

pruebareal[0,inicio,inicio] = 12.1122
pruebareal[0,inicio,inicio]=rep(pruebareal[0,inicio,inicio]+pruebareal[0,inicio,inicio]*2,inicio*2)
 


Also, while/loop/repeat/if  do not need to use the "o<>" thing in front of it.. its has some nasty bugs.
Also i removed the python remaps (for now, maybe if needed i will add them in the future)

As soon as it finished i will publish a compiled version of the interpreter so you can check it out (it has several dependencies and not easy to compile)

Best regards
Franco
 
The following user(s) said Thank You: gilmarbr, tommylight, 0x2102, Grotius, spumco, MennilTossFlykune, DSS, ch4

Please Log in or Create an account to join the conversation.

More
29 Mar 2023 16:49 #267826 by HansU
Replied by HansU on topic new Gcode interpreter
I guess your interpreter is open source as well, because it is built on the Linuxcnc interpreter? In that case - are the sources somewhere available?

Please Log in or Create an account to join the conversation.

More
18 Apr 2023 15:49 #269374 by gilmarbr
Replied by gilmarbr on topic new Gcode interpreter
Cool! Very interesting stuff. 

Please Log in or Create an account to join the conversation.

Time to create page: 0.072 seconds
Powered by Kunena Forum