mpw/debugger/parser.lemon

215 lines
4.0 KiB
Plaintext
Raw Normal View History

2013-07-03 21:05:00 +00:00
%extra_argument { struct Command *command }
%token_prefix tk
2013-07-03 22:03:46 +00:00
%token_type {uint32_t}
%include {
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include "commands.h"
2013-07-03 23:55:09 +00:00
#ifdef __cplusplus
extern "C" {
#endif
2013-07-03 22:03:46 +00:00
uint32_t cpuGetSR();
uint32_t cpuGetPC();
uint32_t cpuGetAReg(unsigned);
uint32_t cpuGetDReg(unsigned);
uint32_t debuggerReadLong(uint32_t);
2013-07-03 23:55:09 +00:00
#ifdef __cplusplus
}
#endif
#undef NDEBUG
2013-07-03 22:03:46 +00:00
}
2013-07-03 21:05:00 +00:00
%parse_failure {
2013-07-04 04:29:09 +00:00
//fprintf(stderr,"I don't understand.\n");
2013-07-03 21:05:00 +00:00
command->valid = false;
}
%parse_accept {
command->valid = true;
}
2013-07-03 22:03:46 +00:00
2013-07-03 21:05:00 +00:00
%left PIPEPIPE.
%left AMPAMP.
%left PIPE.
%left CARET.
%left AMP.
%left EQEQ BANGEQ.
%left LT LTEQ GT GTEQ.
%left LTLT GTGT.
%left PLUS MINUS.
%left STAR SLASH PERCENT.
%right BANG TILDE.
2013-07-03 23:55:09 +00:00
stmt ::= expr(a) EOL.
2013-07-03 21:05:00 +00:00
{
2013-07-03 23:55:09 +00:00
command->action = Print;
command->argc = 1;
command->argv[0] = a;
}
2013-07-03 21:05:00 +00:00
2013-07-04 04:29:09 +00:00
stmt ::= STAR EOL.
{
command->action = PrintRegisters;
command->argc = 0;
}
2013-07-03 23:55:09 +00:00
stmt ::= PRINT expr(a) EOL.
{
2013-07-03 22:03:46 +00:00
command->action = Print;
command->argc = 1;
command->argv[0] = a;
}
2013-07-03 21:05:00 +00:00
2013-07-03 23:55:09 +00:00
stmt ::= BREAK expr(a) EOL.
2013-07-03 22:03:46 +00:00
{
command->action = Break;
command->argc = 1;
command->argv[0] = a;
2013-07-03 21:05:00 +00:00
}
2013-07-03 23:55:09 +00:00
stmt ::= CONTINUE EOL.
2013-07-03 21:05:00 +00:00
{
2013-07-03 22:03:46 +00:00
command->action = Continue;
command->argc = 0;
2013-07-03 21:05:00 +00:00
}
2013-07-03 23:55:09 +00:00
stmt ::= TBREAK expr(a) EOL.
2013-07-03 21:05:00 +00:00
{
2013-07-03 22:03:46 +00:00
// negative number = remove it.
command->action = TBreak;
command->argc = 1;
command->argv[0] = a;
2013-07-03 21:05:00 +00:00
}
2013-07-03 23:55:09 +00:00
stmt ::= NEXT EOL.
2013-07-03 21:05:00 +00:00
{
2013-07-03 22:03:46 +00:00
command->action = Step;
command->argc = 0;
2013-07-03 21:05:00 +00:00
}
2013-07-03 23:55:09 +00:00
stmt ::= NEXT expr(a) EOL.
2013-07-03 21:05:00 +00:00
{
2013-07-03 22:03:46 +00:00
command->action = Step;
command->argc = 1;
command->argv[0] = a;
2013-07-03 21:05:00 +00:00
}
2013-07-03 23:55:09 +00:00
stmt ::= DUMP expr(a) EOL.
2013-07-03 21:05:00 +00:00
{
2013-07-03 22:03:46 +00:00
command->action = Dump;
command->argc = 1;
command->argv[0] = a;
2013-07-03 21:05:00 +00:00
}
2013-07-03 23:55:09 +00:00
stmt ::= LIST expr(a) EOL.
2013-07-03 21:05:00 +00:00
{
2013-07-03 22:03:46 +00:00
command->action = List;
command->argc = 1;
command->argv[0] = a;
2013-07-03 21:05:00 +00:00
}
2013-07-03 23:55:09 +00:00
stmt ::= expr(a) SEMIL EOL.
2013-07-03 21:05:00 +00:00
{
2013-07-03 22:03:46 +00:00
command->action = List;
command->argc = 1;
command->argv[0] = a;
2013-07-03 21:05:00 +00:00
}
2013-07-03 23:55:09 +00:00
stmt ::= expr(a) SEMIH EOL.
2013-07-03 22:03:46 +00:00
{
command->action = Dump;
command->argc = 1;
command->argv[0] = a;
}
2013-07-03 21:05:00 +00:00
2013-07-03 22:03:46 +00:00
2013-07-03 23:55:09 +00:00
stmt ::= DREGISTER(a) EQ expr(b) EOL.
2013-07-03 22:03:46 +00:00
{
command->action = SetDRegister;
command->argc = 2;
command->argv[0] = a;
command->argv[1] = b;
}
2013-07-03 23:55:09 +00:00
stmt ::= AREGISTER(a) EQ expr(b) EOL.
2013-07-03 22:03:46 +00:00
{
command->action = SetARegister;
command->argc = 2;
command->argv[0] = a;
command->argv[1] = b;
}
2013-07-03 23:55:09 +00:00
stmt ::= XREGISTER(a) EQ expr(b) EOL.
2013-07-03 22:03:46 +00:00
{
command->action = SetXRegister;
command->argc = 2;
command->argv[0] = a;
command->argv[1] = b;
}
2013-07-03 23:55:09 +00:00
stmt ::= HELP EOL.
2013-07-03 22:03:46 +00:00
{
command->action = Help;
command->argc = 0;
2013-07-03 21:05:00 +00:00
}
expr(rhs) ::= unary(a). { rhs = a; }
2013-07-03 23:55:09 +00:00
expr(rhs) ::= expr(a) PLUS expr(b). { rhs = a + b; }
expr(rhs) ::= expr(a) MINUS expr(b). { rhs = a - b; }
expr(rhs) ::= expr(a) STAR expr(b). { rhs = a * b; }
expr(rhs) ::= expr(a) SLASH expr(b). { rhs = a / b; }
expr(rhs) ::= expr(a) PERCENT expr(b). { rhs = a % b; }
expr(rhs) ::= expr(a) LTLT expr(b). { rhs = a << b; }
expr(rhs) ::= expr(a) GTGT expr(b). { rhs = a >> b; }
expr(rhs) ::= expr(a) LT expr(b). { rhs = a < b; }
expr(rhs) ::= expr(a) LTEQ expr(b). { rhs = a <= b; }
expr(rhs) ::= expr(a) GT expr(b). { rhs = a > b; }
expr(rhs) ::= expr(a) GTEQ expr(b). { rhs = a >= b; }
expr(rhs) ::= expr(a) EQEQ expr(b). { rhs = a == b; }
expr(rhs) ::= expr(a) BANGEQ expr(b). { rhs = a != b; }
expr(rhs) ::= expr(a) AMP expr(b). { rhs = a & b; }
expr(rhs) ::= expr(a) CARET expr(b). { rhs = a ^ b; }
expr(rhs) ::= expr(a) PIPE expr(b). { rhs = a | b; }
expr(rhs) ::= expr(a) AMPAMP expr(b). { rhs = a && b; }
expr(rhs) ::= expr(a) PIPEPIPE expr(b). { rhs = a || b; }
2013-07-03 21:05:00 +00:00
unary(rhs) ::= term(a). { rhs = a; }
unary(rhs) ::= PLUS unary(a). [BANG] { rhs = a; }
unary(rhs) ::= MINUS unary(a). [BANG] { rhs = -a; }
unary(rhs) ::= TILDE unary(a). { rhs = ~a; }
unary(rhs) ::= BANG unary(a). { rhs = !a; }
2013-07-03 22:03:46 +00:00
unary(rhs) ::= STAR unary(a). [BANG] { rhs = debuggerReadLong(a); }
2013-07-03 21:05:00 +00:00
term(rhs) ::= LPAREN expr(a) RPAREN. { rhs = a; }
term(rhs) ::= INTEGER(a). { rhs = a; }
term(rhs) ::= DREGISTER(a). { rhs = cpuGetDReg(a); }
term(rhs) ::= AREGISTER(a). { rhs = cpuGetAReg(a); }
term(rhs) ::= XREGISTER(a).
{
switch(a)
{
case 0:
rhs = cpuGetPC();
break;
case 1:
rhs = cpuGetSR();
break;
default:
rhs = 0;
}
}