Analizador Usando PEG.js
-
Σ = { ADDOP, MULOP, '(', ')', NUM, ',', ID, '=', 'begin', 'end', 'if', 'then', ';', 'while', 'do', 'call', 'procedure', 'const', 'var', '.' },
-
V = { expression, term, factor, condition, statement, functions, declaration, block, program}
-
Productions:
- program → block '.'
- block → declaration functions statement
- declaration → (const' ID '=' NUM (',' ID '=' NUM) * ';')? ('var' ID (',' ID ) * ';')?
- functions → ('procedure' ID 'begin' block 'end')*
- statement → ID '=' expression | 'call' ID | 'if' condition 'then' statement | 'while' condition 'do' statement | 'begin' statement (';' statement) * 'end' | 'return' expression
- condition → expression COMPARISON expression
- expression → term ( ADDOP term) *
- term → factor (MULOP factor) *
- factor → '(' expression ')' | NUM | ID
const pi = 3.14;
var a;
begin
a = 4;
if a ==4 then a = 4 / 2
end.
const pi = 3.14;
var a;
a = pi.
procedure b
begin
var b;
b = b * 2
end
call b.
var x;
begin
a = 0;
while x <= 10 do
begin
x = x + 1
end;
while x != 0 do
x = x - 1
end.