grammar, allow multiple linebreaks between instructions + more work on stack.asm

This commit is contained in:
Sam Hadow 2024-04-08 22:15:46 +02:00
parent b179cdf7ec
commit ccee47ca5e
3 changed files with 29 additions and 9 deletions

View File

@ -17,6 +17,6 @@ JUMP|JE|JL { yylval = strdup(yytext); return OP_CTRL;}
[ ]*,[ ]* {return COMMA;}
\( {return PAR_O;}
\)[ ]*("//".*)? {return PAR_C;}
\n {return SEPARATION; }
\n+ {return SEPARATION; }
. {printf("token inconnu\n"); yyterminate();}
%%

View File

@ -1,21 +1,40 @@
(5,2,5,5,0)
ADD(0, 0, r0) // r0 current state in pushdown automaton
ADD(2, 0, r1) // r1 cursor position in input word, (i2 first symbol of input word, i1 length of input word)
ADD(9, 0, r8) // r8, address of stack top
ADD(2, 0, r9) // r9 bottom symbol
ADD(10, 0, r9) // r9 address of stack top
ADD(2, 0, r10) // r10 bottom symbol
SUB(i1, i2, r7)
SUB(r7, 2, r7) // r7 number of instructions
ADD(1, 0, r8) // reset loop counter
ADD(i1, 2, r2) // r2, address first automaton instruction begin state 'q', instruction: (q, a, A, w, q)
JUMP(3) // skip loop increment on 1st iteration
ADD(1, r8, r8) // increment loop counter
ADD(r6, 1, r2) // r2, address of next instruction to check
JL(r8, r7, ) // loop condition
ADD(r2, 1, r3) // r3, address instruction read symbol 'a'
ADD(r3, 1, r4) // r4, address instruction read stack symbol 'A'
ADD(r4, 1, r5) // r5, address, instruction word pushed on stack length
ADD(r5, i@r5, r6)
ADD(1, r6, r6) // r6, address, next state q'
JE(r0, i@r2, 2) // current state is the expected state in the instruction
JUMP(-9) // if not, next iteration
JE(r0, i@r2, ) // current state is the expected state in the instruction
JE(i@r1, 2, ) // read symbol is epsilon
JE(i@r1, 2, 3) // read symbol is epsilon
JE(i@r3, i@r1, ) // symbol in input == read symbol
JUMP()
JE(i@r4, 2, ) // read stack symbol is epsilon
JE(r@r6, i@r4, ) // stack top is the to expected symbol
JUMP(-12)
JE(i@r4, 2, ) // read stack symbol is epsilon (read symbol was epsilon)
JE(r@r6, i@r4, ) // stack top is the expected symbol
JUMP(-15)
JE(i@r4, 2, ) // read stack symbol is epsilon (read symbol was symbol in put)
JE(r@r6, i@r4, ) // stack top is the expected symbol
JUMP(-18)
JE(r0, 1, 3) // check if final state
ADD(0, 1, o1) // reject = 1
JUMP(2)
ADD(0, 0, o1) // accept = 0
ADD(0, 1 ,o0) // output size in o1

View File

@ -1,5 +1,6 @@
(10,5,1,2,4)
ADD(i0 ,1 ,r0)
SUB(i1,3,r1)
MULT(r1,r0,o1)
ADD(5, i@i2, o2)