0% found this document useful (0 votes)
47 views5 pages

Gramática (Semántico) : 1 Terminales Del Lenguaje

The document defines the grammar for a programming language. It lists the terminal symbols of the language including variables, numbers, operators, and keywords. It then defines the starting symbol and provides rewrite rules to describe expressions, variable declarations, functions, conditionals, loops, and other elements of the language syntax.

Uploaded by

lastname name
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views5 pages

Gramática (Semántico) : 1 Terminales Del Lenguaje

The document defines the grammar for a programming language. It lists the terminal symbols of the language including variables, numbers, operators, and keywords. It then defines the starting symbol and provides rewrite rules to describe expressions, variable declarations, functions, conditionals, loops, and other elements of the language syntax.

Uploaded by

lastname name
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Gramática (semántico)

1 Terminales del Lenguaje


• VAR
• NUM
• FLOAT
• CHAR
• STR
• BREAK: break
• TYPE: int | oat | string | char | bool | void
• ASIG: =
• IF: if
• ELSEIF: else if
• ELSE: else
• WHILE: while
• FOR: for
• TO: to
• NEXT: next
• OP_PR: + | -
• OP_SE: * | /
• OP_LO: AND | OR | NOT
• CONDICIONALES: < | == | <= | >= | > | !=
• INCLUDE: include
• RETURN: return

2 Gramática
Símbolo inicial
START := INCLUDE STR (R1)START | DE (R2)START | 

1. if(doesExists(INCLUDE.path)) (R1)
START.val = INCLUDE + START.val
else ERROR

1
2. START := DE START (R2)
R2 :=
START.val = DE.val + START.val
1. IM := INCLUDE STR (R3)
R3 :=
if(path_exists(STR.str))
include(STR.str);
else ERROR
Declaración y Denición de Variable y funciones (DE)
DE := TYPE VAR LF
1. DE := TYPE VAR (R4) (R5) LF)
R4 :=
type = TYPE.str
name = getName(VAR)
setType(name, type)
LF.type = type
LF.name = name

R5 :=
name = getName(VAR)
if(LF.array){
setArray(name, LF.array)
setSize(name, LF.size)
}
else{
setValue(name, LF.value)
}

LF := L(R6) | (R7)VF(R8) | 

1. LF := L (R6) LF.array = L.array (R6)


L.size = L.size

2. VF.type = LF.type (R7)


3. LF.val = VF.val (R8)
L := [ NUM ]

1. L := [ NUM ] (R7)
R7 :=
L.array = True
L.size = NUM.str

VF := (R9)AV(R10) | AF | 

1. AV.type = VF.type (R9)

2. VF.val = AV.val (R10)

2
AF := ( PARAMETRO ) { CODE }

PARAMETRO := TYPE VAR LV | 

LV := , PARAMETRO | 

AV := ASIG(R11)MV

if(MV.type == AV.type) (R11)


MV.val = AV.val
else ERROR
MV := [ EX PL ] | OP

1. MV := [ EX PL ] (R12)

2. MV := OP R13)

PL := , EX PL| 

OP := BO(R14) | DP(R15) | TV(R16)

1. OP.val := BO.val (R14)

2. OP.val := DP.val (R15)

3. OP.val := TV.val (R16)

BO := OP_PR (R17)(R18)BOO

1. if(OP_PR.type == '+') (R17)


BOO.op = +
else if(OP_PR.type == '-')
BOO.op = -
else ERROR
2. BO.val = BOO.val (R18)
BOO := DP(R19) | TV(R20)

1. BOO.type = DP.type, BOO.name = DP.name, BOO.val = DP.val (R19)


2. BOO.type = TV.type, BOO.val = TV.val (R20)
DP := ( DPP(R29) )

1. DP.type = (DPP.type), DP.name_param = (DPP.name) (R29)

DPP := BO(R30) | TV(R31)

1. if(DPP.type == BO.type) (R30)


DPP.val = BO.val

3
2. if(DPP.type == TV.type) (R31)
DPP.val = TV.val
TV := PS (R26) TVV

1. TVV.type = PS.type, TVV.value = PS.value (R26)


TVV := BO(R27) | OP_SE (R28)TV | FF(R29) | 

1. if(BO.type == TVV.type) (R27)


BO.val = TVV.val
else ERROR
2. if(TVV.type == TV.type) (R28)
if(OP_SE == '*')
if(TVV.type == int)
if(TVV.type == oat)
TV.val * TVV.val
else ERROR
if(OP_SE == '/')
if(TVV.type == int)
if(TVV.type == oat)
TV.val / TVV.val
else ERROR else ERROR else ERROR else ERROR
3. No hay reglas (R29)

EX := NUM(R32) | FLOAT(R33) | CHAR(R34) | STR(R35)

1. EX.type = NUM.type, EX.val = NUM.val (R32)


2. EX.type = FLOAT.type, EX.val = FLOAT.val (R33)
3. EX.type = CHAR.type, EX.val = CHAR.val (R34)
4. EX.type = STR.type, EX.val = STR.val (R35)
BODY
BODY := VAR (R36)BODY | IFS (R37)BODY | WH (R38)BODY | FR (R39)BODY | B
(R40)BODY | R(R41) | 

1. VAR.type = BODY.type, VAR.val = C.val (R36)


2. IFS.code = BODY.code (R37)
3. WH.code = BODY.code (R38)
4. FR.code = BODY.code (R39)
5. B.val = BODY.val (R40)
6. R = BODY.return (R41)
R:= RETURN (R42)PS

1. PS.val = R.val (R42)


B := BREAK(R43)

4
1. if(isWhile()) (R43)
BREAK = TRUE
else FALSE
VAR := TYPE VAR AS | VAR LAV

LAV := L AV | AV | FF

FF := ( PS MPS )

MPS := , PS MPS | 

AS := AV | 

IFS := IF EI EL

IF := IF ( CON ) { CODE }

EI := ELSEIF ( CON ) { CODE } EI | 

EL := ELSE { CODE } | 

CON := ( PS ZZ ) MO

MO := OP_LO CON| 

PS := VAR(R21) | NUM(R22) | FLOAT(R23) | CHAR(R24) | STR(R25)

1. PS.type = getType(VAR), if(doesExists(VAR)){ PS.val = VAR.str} (R21)


2. PS.type = NUM.type, PS.val = NUM.str (R22)
3. PS.type = getType(FLOAT.str), PS.val = FLOAT.str (R23)
4. PS.type = getType(CHAR.str), PS.val = CHAR.str (R24)
5. PS.type = getType(STR.str), PS.val = STR.str (R25)
WH := WHILE ( CON ) { CODE }

FR := FOR ( FV ) TO ( VL ) NEXT ( VL ) { CODE }

FV := VAR AV | FA

FA := TYPE VAR ASIG VL

VL := NUM | FLOAT

ZZ := CONDICIONALES PS | 

You might also like